From ab4e6a94c5f6fb53aeb4c6a312fe28f78a9995f8 Mon Sep 17 00:00:00 2001 From: m-e-l-u-h-a-n Date: Sun, 26 Feb 2023 21:17:58 +0530 Subject: [PATCH] user groups: Make name and description optional in group update. View that handled `PATCH user_groups/` required both name and description parameters to be passed. Due to this clients had to pass values for both these parameters even if one of them was changed. To resolve this name description parameters to `PATCH user_groups/` are made optional. --- api_docs/changelog.md | 4 ++++ version.py | 2 +- zerver/openapi/zulip.yaml | 8 ++++++-- zerver/tests/test_user_groups.py | 5 +++++ zerver/views/user_groups.py | 12 ++++++------ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/api_docs/changelog.md b/api_docs/changelog.md index e992ca1286..3c56b2b801 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -20,6 +20,10 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 7.0 +**Feature level 165** +* [`PATCH /user_groups/{user_group_id}`](/api/update-user-group): The + `name` and `description` parameters are now optional. + **Feature level 164** * [`POST /register`](/api/register-queue): Added the diff --git a/version.py b/version.py index 822d0ac35b..b1e57cac2c 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 164 +API_FEATURE_LEVEL = 165 # Bump the minor PROVISION_VERSION to indicate that folks should provision # only when going from an old version of the code to a newer version. Bump diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 3afd363a04..f71507efcc 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -15061,18 +15061,22 @@ paths: in: query description: | The new name of the group. + + **Changes**: Before Zulip 7.0 (feature level 165), this was + a required field. schema: type: string example: marketing team - required: true - name: description in: query description: | The new description of the group. + + **Changes**: Before Zulip 7.0 (feature level 165), this was + a required field. schema: type: string example: The marketing team. - required: true responses: "200": $ref: "#/components/responses/SimpleSuccess" diff --git a/zerver/tests/test_user_groups.py b/zerver/tests/test_user_groups.py index 8499d86536..ae72234d0b 100644 --- a/zerver/tests/test_user_groups.py +++ b/zerver/tests/test_user_groups.py @@ -283,6 +283,11 @@ class UserGroupAPITestCase(UserGroupTestCase): result = self.client_patch(f"/json/user_groups/{user_group.id}", info={}) self.assert_json_error(result, "No new data supplied") + # Test when only one of name or description is supplied. + params = {"name": "help team"} + result = self.client_patch(f"/json/user_groups/{user_group.id}", info=params) + self.assert_json_success(result) + # Test when invalid user group is supplied params = {"name": "help"} result = self.client_patch("/json/user_groups/1111", info=params) diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index fb4d567101..3d76efce5f 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -1,4 +1,4 @@ -from typing import Sequence +from typing import Optional, Sequence from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ @@ -62,18 +62,18 @@ def edit_user_group( request: HttpRequest, user_profile: UserProfile, user_group_id: int = REQ(json_validator=check_int, path_only=True), - name: str = REQ(default=""), - description: str = REQ(default=""), + name: Optional[str] = REQ(default=None), + description: Optional[str] = REQ(default=None), ) -> HttpResponse: - if not (name or description): + if name is None and description is None: raise JsonableError(_("No new data supplied")) user_group = access_user_group_by_id(user_group_id, user_profile) - if name != user_group.name: + if name is not None and name != user_group.name: do_update_user_group_name(user_group, name, acting_user=user_profile) - if description != user_group.description: + if description is not None and description != user_group.description: do_update_user_group_description(user_group, description, acting_user=user_profile) return json_success(request)