diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 59b5469b03..bbdbaabaa4 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -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: diff --git a/zerver/tests/test_channel_folders.py b/zerver/tests/test_channel_folders.py index 335f8418bc..17b2185b63 100644 --- a/zerver/tests/test_channel_folders.py +++ b/zerver/tests/test_channel_folders.py @@ -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") diff --git a/zerver/views/channel_folders.py b/zerver/views/channel_folders.py index f25ea664f3..decde3d6dc 100644 --- a/zerver/views/channel_folders.py +++ b/zerver/views/channel_folders.py @@ -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)