mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	channel_folders: Check max length restrictions while updating.
This commit updates code to make sure we check maximum allowed length for name and description for channel folders when updating them.
This commit is contained in:
		@@ -24465,11 +24465,19 @@ paths:
 | 
			
		||||
                name:
 | 
			
		||||
                  description: |
 | 
			
		||||
                    The new name of the channel folder.
 | 
			
		||||
 | 
			
		||||
                    Clients should use the `max_channel_folder_name_length` returned
 | 
			
		||||
                    by the [`POST /register`](/api/register-queue) endpoint to determine
 | 
			
		||||
                    the maximum channel folder name length.
 | 
			
		||||
                  type: string
 | 
			
		||||
                  example: backend
 | 
			
		||||
                description:
 | 
			
		||||
                  description: |
 | 
			
		||||
                    The new description of the channel folder.
 | 
			
		||||
 | 
			
		||||
                    Clients should use the `max_channel_folder_description_length`
 | 
			
		||||
                    returned by the [`POST /register`](/api/register-queue) endpoint
 | 
			
		||||
                    to determine the maximum channel folder description length.
 | 
			
		||||
                  type: string
 | 
			
		||||
                  example: Backend channels.
 | 
			
		||||
                is_archived:
 | 
			
		||||
 
 | 
			
		||||
@@ -238,6 +238,13 @@ class UpdateChannelFoldersTest(ZulipTestCase):
 | 
			
		||||
        result = self.client_patch(f"/json/channel_folders/{channel_folder_id}", params)
 | 
			
		||||
        self.assert_json_error(result, "Invalid character in channel folder name, at position 4.")
 | 
			
		||||
 | 
			
		||||
        long_name = "a" * (ChannelFolder.MAX_NAME_LENGTH + 1)
 | 
			
		||||
        params = {"name": long_name}
 | 
			
		||||
        result = self.client_patch(f"/json/channel_folders/{channel_folder_id}", params)
 | 
			
		||||
        self.assert_json_error(
 | 
			
		||||
            result, f"name is too long (limit: {ChannelFolder.MAX_NAME_LENGTH} characters)"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_updating_channel_folder_description(self) -> None:
 | 
			
		||||
        channel_folder = check_add_channel_folder(
 | 
			
		||||
            get_realm("zulip"),
 | 
			
		||||
@@ -276,6 +283,13 @@ class UpdateChannelFoldersTest(ZulipTestCase):
 | 
			
		||||
        self.assertEqual(channel_folder.description, "")
 | 
			
		||||
        self.assertEqual(channel_folder.rendered_description, "")
 | 
			
		||||
 | 
			
		||||
        params = {"description": "a" * (ChannelFolder.MAX_DESCRIPTION_LENGTH + 1)}
 | 
			
		||||
        result = self.client_patch(f"/json/channel_folders/{channel_folder_id}", params)
 | 
			
		||||
        self.assert_json_error(
 | 
			
		||||
            result,
 | 
			
		||||
            f"description is too long (limit: {ChannelFolder.MAX_DESCRIPTION_LENGTH} characters)",
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def test_archiving_and_unarchiving_channel_folder(self) -> None:
 | 
			
		||||
        desdemona = self.example_user("desdemona")
 | 
			
		||||
        realm = get_realm("zulip")
 | 
			
		||||
 
 | 
			
		||||
@@ -59,9 +59,11 @@ def update_channel_folder(
 | 
			
		||||
    user_profile: UserProfile,
 | 
			
		||||
    *,
 | 
			
		||||
    channel_folder_id: PathOnly[int],
 | 
			
		||||
    description: str | None = None,
 | 
			
		||||
    description: Annotated[
 | 
			
		||||
        str | None, StringConstraints(max_length=ChannelFolder.MAX_DESCRIPTION_LENGTH)
 | 
			
		||||
    ] = None,
 | 
			
		||||
    is_archived: Json[bool] | None = None,
 | 
			
		||||
    name: str | None = None,
 | 
			
		||||
    name: Annotated[str | None, StringConstraints(max_length=ChannelFolder.MAX_NAME_LENGTH)] = None,
 | 
			
		||||
) -> HttpResponse:
 | 
			
		||||
    channel_folder = get_channel_folder_by_id(channel_folder_id, user_profile.realm)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user