From fbcc3b5c84544b460b3b76a1f4523352db0d9590 Mon Sep 17 00:00:00 2001 From: Ujjawal Modi Date: Fri, 14 Jul 2023 10:20:33 +0530 Subject: [PATCH] user_groups: Rename `can_mention_group_id` parameter. Earlier the API endpoints related to user_group accepts and returns a field `can_mention_group_id` which represents the ID of user_group whose members can mention the group. This commit renames this field to `can_mention_group`. --- api_docs/changelog.md | 8 +++++ version.py | 2 +- web/src/user_groups.ts | 6 ++-- web/tests/composebox_typeahead.test.js | 6 ++-- web/tests/lib/events.js | 2 +- web/tests/user_groups.test.js | 6 ++-- zerver/actions/user_groups.py | 5 ++- zerver/lib/event_schema.py | 4 +-- zerver/lib/user_groups.py | 4 +-- zerver/openapi/zulip.yaml | 44 ++++++++++++++++++-------- zerver/tests/test_events.py | 2 +- zerver/tests/test_user_groups.py | 24 +++++++------- zerver/views/user_groups.py | 8 +++-- 13 files changed, 74 insertions(+), 47 deletions(-) diff --git a/api_docs/changelog.md b/api_docs/changelog.md index 1e7086a447..4110c05ae6 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -20,6 +20,14 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 8.0 +**Feature level 198** + +* [`GET /events`](/api/get-events), [`POST /register`](/api/register-queue), + [`GET /user_groups`](/api/get-user-groups), + [`POST /user_groups/create`](/api/create-user-group), + [`PATCH /user_groups/{user_group_id}`](/api/update-user-group):Renamed + group setting `can_mention_group_id` to `can_mention_group`. + **Feature level 197** * [`POST /users/me/subscriptions`](/api/subscribe), diff --git a/version.py b/version.py index 09f0cd958b..763d2e39b9 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.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 = 197 +API_FEATURE_LEVEL = 198 # 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/web/src/user_groups.ts b/web/src/user_groups.ts index 3795d0ec29..0cc5d58675 100644 --- a/web/src/user_groups.ts +++ b/web/src/user_groups.ts @@ -12,7 +12,7 @@ export type UserGroup = { members: Set; is_system_group: boolean; direct_subgroup_ids: Set; - can_mention_group_id: number; + can_mention_group: number; }; // The members field is a number array which we convert @@ -46,7 +46,7 @@ export function add(user_group_raw: UserGroupRaw): void { members: new Set(user_group_raw.members), is_system_group: user_group_raw.is_system_group, direct_subgroup_ids: new Set(user_group_raw.direct_subgroup_ids), - can_mention_group_id: user_group_raw.can_mention_group_id, + can_mention_group: user_group_raw.can_mention_group, }; user_group_name_dict.set(user_group.name, user_group); @@ -96,7 +96,7 @@ export function get_user_groups_allowed_to_mention(): UserGroup[] { const user_groups = get_realm_user_groups(); return user_groups.filter((group) => { - const can_mention_group_id = group.can_mention_group_id; + const can_mention_group_id = group.can_mention_group; return ( page_params.user_id !== undefined && is_user_in_group(can_mention_group_id, page_params.user_id) diff --git a/web/tests/composebox_typeahead.test.js b/web/tests/composebox_typeahead.test.js index b3f46a542f..ce00a8d41f 100644 --- a/web/tests/composebox_typeahead.test.js +++ b/web/tests/composebox_typeahead.test.js @@ -331,7 +331,7 @@ const hamletcharacters = { members: new Set([100, 104]), is_system_group: false, direct_subgroup_ids: new Set([]), - can_mention_group_id: 2, + can_mention_group: 2, }; const backend = { @@ -341,7 +341,7 @@ const backend = { members: new Set([101]), is_system_group: false, direct_subgroup_ids: new Set([1]), - can_mention_group_id: 1, + can_mention_group: 1, }; const call_center = { @@ -351,7 +351,7 @@ const call_center = { members: new Set([102]), is_system_group: false, direct_subgroup_ids: new Set([]), - can_mention_group_id: 2, + can_mention_group: 2, }; const make_emoji = (emoji_dict) => ({ diff --git a/web/tests/lib/events.js b/web/tests/lib/events.js index 7d45c4f193..7c6db15e4b 100644 --- a/web/tests/lib/events.js +++ b/web/tests/lib/events.js @@ -795,7 +795,7 @@ exports.fixtures = { members: [1], is_system_group: false, direct_subgroup_ids: [2], - can_mention_group_id: 11, + can_mention_group: 11, }, }, diff --git a/web/tests/user_groups.test.js b/web/tests/user_groups.test.js index 9ba8977ae8..658a912aa1 100644 --- a/web/tests/user_groups.test.js +++ b/web/tests/user_groups.test.js @@ -16,7 +16,7 @@ run_test("user_groups", () => { members: new Set([1, 2]), is_system_group: false, direct_subgroup_ids: new Set([4, 5]), - can_mention_group_id: 2, + can_mention_group: 2, }; const params = {}; @@ -34,7 +34,7 @@ run_test("user_groups", () => { members: new Set([3]), is_system_group: false, direct_subgroup_ids: new Set([]), - can_mention_group_id: 2, + can_mention_group: 2, }; const all = { name: "Everyone", @@ -42,7 +42,7 @@ run_test("user_groups", () => { members: new Set([1, 2, 3]), is_system_group: false, direct_subgroup_ids: new Set([4, 5, 6]), - can_mention_group_id: 1, + can_mention_group: 1, }; user_groups.add(admins); diff --git a/zerver/actions/user_groups.py b/zerver/actions/user_groups.py index 9ce26165d1..25abefc245 100644 --- a/zerver/actions/user_groups.py +++ b/zerver/actions/user_groups.py @@ -183,7 +183,7 @@ def do_send_create_user_group_event( id=user_group.id, is_system_group=user_group.is_system_group, direct_subgroup_ids=[direct_subgroup.id for direct_subgroup in direct_subgroups], - can_mention_group_id=user_group.can_mention_group_id, + can_mention_group=user_group.can_mention_group_id, ), ) send_event(user_group.realm, event, active_user_ids(user_group.realm_id)) @@ -443,6 +443,5 @@ def do_change_user_group_permission_setting( ).decode(), ) - setting_id_name = setting_name + "_id" - event_data_dict: Dict[str, Union[str, int]] = {setting_id_name: setting_value_group.id} + event_data_dict: Dict[str, Union[str, int]] = {setting_name: setting_value_group.id} do_send_user_group_update_event(user_group, event_data_dict) diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py index 701055d32c..ef4f3d2cc7 100644 --- a/zerver/lib/event_schema.py +++ b/zerver/lib/event_schema.py @@ -1689,7 +1689,7 @@ group_type = DictType( ("direct_subgroup_ids", ListType(int)), ("description", str), ("is_system_group", bool), - ("can_mention_group_id", int), + ("can_mention_group", int), ] ) @@ -1737,7 +1737,7 @@ user_group_data_type = DictType( # force vertical ("name", str), ("description", str), - ("can_mention_group_id", int), + ("can_mention_group", int), ], ) diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.py index 699cbefac2..dfd8569546 100644 --- a/zerver/lib/user_groups.py +++ b/zerver/lib/user_groups.py @@ -26,7 +26,7 @@ class UserGroupDict(TypedDict): members: List[int] direct_subgroup_ids: List[int] is_system_group: bool - can_mention_group_id: int + can_mention_group: int def access_user_group_by_id( @@ -144,7 +144,7 @@ def user_groups_in_realm_serialized(realm: Realm) -> List[UserGroupDict]: members=[], direct_subgroup_ids=[], is_system_group=user_group.is_system_group, - can_mention_group_id=user_group.can_mention_group_id, + can_mention_group=user_group.can_mention_group_id, ) membership = UserGroupMembership.objects.filter(user_group__realm=realm).values_list( diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 4f920a4f07..183adec277 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -2915,7 +2915,7 @@ paths: "description": "Backend team", "id": 2, "is_system_group": false, - "can_mention_group_id": 11, + "can_mention_group": 11, }, "id": 0, } @@ -2955,13 +2955,17 @@ paths: description: | The new description of the group. Only present if the description changed. - can_mention_group_id: + can_mention_group: type: integer description: | ID of the new user group whose members are allowed to mention the group. - **Changes**: New in Zulip 8.0 (feature level 191). Previously, groups + **Changes**: Before Zulip 8.0 (feature level 198), + the `can_mention_group` setting + was named `can_mention_group_id`. + + New in Zulip 8.0 (feature level 191). Previously, groups could be mentioned if and only if they were not system groups. example: { @@ -16230,7 +16234,7 @@ paths: type: integer example: [1, 2, 3, 4] required: true - - name: can_mention_group_id + - name: can_mention_group in: query description: | ID of the user group whose members are allowed to mention the new @@ -16239,7 +16243,10 @@ paths: This setting cannot be set to `"role:internet"` and `"role:owners"` system groups. - **Changes**: New in Zulip 8.0 (feature level 191). Previously, groups + **Changes**: Before Zulip 8.0 (feature level 198), + the `can_mention_group` setting was named `can_mention_group_id`. + + New in Zulip 8.0 (feature level 191). Previously, groups could be mentioned if and only if they were not system groups. schema: type: integer @@ -16367,7 +16374,7 @@ paths: schema: type: string example: The marketing team. - - name: can_mention_group_id + - name: can_mention_group in: query description: | ID of the new user group whose members are allowed to mention the @@ -16376,7 +16383,10 @@ paths: This setting cannot be set to `"role:internet"` and `"role:owners"` system groups. - **Changes**: New in Zulip 8.0 (feature level 191). Previously, groups + **Changes**: Before Zulip 8.0 (feature level 198), + the `can_mention_group` setting was named `can_mention_group_id`. + + New in Zulip 8.0 (feature level 191). Previously, groups could be mentioned if and only if they were not system groups. schema: type: integer @@ -16498,12 +16508,15 @@ paths: modified by users. **Changes**: New in Zulip 5.0 (feature level 93). - can_mention_group_id: + can_mention_group: type: integer description: | ID of the user group whose members are allowed to mention the group. - **Changes**: New in Zulip 8.0 (feature level 191). Previously, groups + **Changes**: Before Zulip 8.0 (feature level 198), + the `can_mention_group` setting was named `can_mention_group_id`. + + New in Zulip 8.0 (feature level 191). Previously, groups could be mentioned if and only if they were not system groups. description: | A list of `user_group` objects. @@ -16520,7 +16533,7 @@ paths: "members": [1], "direct_subgroup_ids": [], "is_system_group": true, - "can_mention_group_id": 11, + "can_mention_group": 11, }, { "description": "Administrators of this organization, including owners", @@ -16529,7 +16542,7 @@ paths: "members": [2], "direct_subgroup_ids": [1], "is_system_group": true, - "can_mention_group_id": 12, + "can_mention_group": 12, }, { "description": "Characters of Hamlet", @@ -16538,7 +16551,7 @@ paths: "members": [3, 4], "direct_subgroup_ids": [], "is_system_group": false, - "can_mention_group_id": 13, + "can_mention_group": 13, }, ], } @@ -17517,12 +17530,15 @@ components: directly modified by users. **Changes**: New in Zulip 5.0 (feature level 93). - can_mention_group_id: + can_mention_group: type: integer description: | ID of the user group whose members are allowed to mention the group. - **Changes**: New in Zulip 8.0 (feature level 191). Previously, groups + **Changes**: Before Zulip 8.0 (feature level 198), + the `can_mention_group` setting was named `can_mention_group_id`. + + New in Zulip 8.0 (feature level 191). Previously, groups could be mentioned if and only if they were not system groups. Subscriptions: type: object diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 95815cbd11..5b70302c4e 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -1414,7 +1414,7 @@ class NormalActionsTest(BaseAction): backend, "can_mention_group", moderators_group, acting_user=None ) ) - check_user_group_update("events[0]", events[0], "can_mention_group_id") + check_user_group_update("events[0]", events[0], "can_mention_group") # Test add members hamlet = self.example_user("hamlet") diff --git a/zerver/tests/test_user_groups.py b/zerver/tests/test_user_groups.py index b357df9239..93f25ab7fc 100644 --- a/zerver/tests/test_user_groups.py +++ b/zerver/tests/test_user_groups.py @@ -320,7 +320,7 @@ class UserGroupAPITestCase(UserGroupTestCase): "name": "support", "members": orjson.dumps([hamlet.id]).decode(), "description": "Support team", - "can_mention_group_id": orjson.dumps(moderators_group.id).decode(), + "can_mention_group": orjson.dumps(moderators_group.id).decode(), } result = self.client_post("/json/user_groups/create", info=params) self.assert_json_success(result) @@ -331,7 +331,7 @@ class UserGroupAPITestCase(UserGroupTestCase): "name": "test", "members": orjson.dumps([hamlet.id]).decode(), "description": "Test group", - "can_mention_group_id": orjson.dumps(leadership_group.id).decode(), + "can_mention_group": orjson.dumps(leadership_group.id).decode(), } result = self.client_post("/json/user_groups/create", info=params) self.assert_json_success(result) @@ -345,7 +345,7 @@ class UserGroupAPITestCase(UserGroupTestCase): "name": "marketing", "members": orjson.dumps([hamlet.id]).decode(), "description": "Marketing team", - "can_mention_group_id": orjson.dumps(nobody_group.id).decode(), + "can_mention_group": orjson.dumps(nobody_group.id).decode(), } result = self.client_post("/json/user_groups/create", info=params) self.assert_json_success(result) @@ -359,7 +359,7 @@ class UserGroupAPITestCase(UserGroupTestCase): "name": "frontend", "members": orjson.dumps([hamlet.id]).decode(), "description": "Frontend team", - "can_mention_group_id": orjson.dumps(internet_group.id).decode(), + "can_mention_group": orjson.dumps(internet_group.id).decode(), } result = self.client_post("/json/user_groups/create", info=params) self.assert_json_error( @@ -373,7 +373,7 @@ class UserGroupAPITestCase(UserGroupTestCase): "name": "frontend", "members": orjson.dumps([hamlet.id]).decode(), "description": "Frontend team", - "can_mention_group_id": orjson.dumps(owners_group.id).decode(), + "can_mention_group": orjson.dumps(owners_group.id).decode(), } result = self.client_post("/json/user_groups/create", info=params) self.assert_json_error( @@ -384,7 +384,7 @@ class UserGroupAPITestCase(UserGroupTestCase): "name": "frontend", "members": orjson.dumps([hamlet.id]).decode(), "description": "Frontend team", - "can_mention_group_id": orjson.dumps(1111).decode(), + "can_mention_group": orjson.dumps(1111).decode(), } result = self.client_post("/json/user_groups/create", info=params) self.assert_json_error(result, "Invalid user group") @@ -489,7 +489,7 @@ class UserGroupAPITestCase(UserGroupTestCase): self.login("hamlet") params = { - "can_mention_group_id": orjson.dumps(moderators_group.id).decode(), + "can_mention_group": orjson.dumps(moderators_group.id).decode(), } result = self.client_patch(f"/json/user_groups/{support_group.id}", info=params) self.assert_json_success(result) @@ -497,7 +497,7 @@ class UserGroupAPITestCase(UserGroupTestCase): self.assertEqual(support_group.can_mention_group, moderators_group) params = { - "can_mention_group_id": orjson.dumps(marketing_group.id).decode(), + "can_mention_group": orjson.dumps(marketing_group.id).decode(), } result = self.client_patch(f"/json/user_groups/{support_group.id}", info=params) self.assert_json_success(result) @@ -508,7 +508,7 @@ class UserGroupAPITestCase(UserGroupTestCase): name="role:nobody", realm=hamlet.realm, is_system_group=True ) params = { - "can_mention_group_id": orjson.dumps(nobody_group.id).decode(), + "can_mention_group": orjson.dumps(nobody_group.id).decode(), } result = self.client_patch(f"/json/user_groups/{support_group.id}", info=params) self.assert_json_success(result) @@ -519,7 +519,7 @@ class UserGroupAPITestCase(UserGroupTestCase): name="role:owners", realm=hamlet.realm, is_system_group=True ) params = { - "can_mention_group_id": orjson.dumps(owners_group.id).decode(), + "can_mention_group": orjson.dumps(owners_group.id).decode(), } result = self.client_patch(f"/json/user_groups/{support_group.id}", info=params) self.assert_json_error( @@ -530,7 +530,7 @@ class UserGroupAPITestCase(UserGroupTestCase): name="role:internet", realm=hamlet.realm, is_system_group=True ) params = { - "can_mention_group_id": orjson.dumps(internet_group.id).decode(), + "can_mention_group": orjson.dumps(internet_group.id).decode(), } result = self.client_patch(f"/json/user_groups/{support_group.id}", info=params) self.assert_json_error( @@ -538,7 +538,7 @@ class UserGroupAPITestCase(UserGroupTestCase): ) params = { - "can_mention_group_id": orjson.dumps(1111).decode(), + "can_mention_group": orjson.dumps(1111).decode(), } result = self.client_patch(f"/json/user_groups/{support_group.id}", info=params) self.assert_json_error(result, "Invalid user group") diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index 0b1d103aad..055211bf7b 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -49,7 +49,9 @@ def add_user_group( name: str = REQ(), members: Sequence[int] = REQ(json_validator=check_list(check_int), default=[]), description: str = REQ(), - can_mention_group_id: Optional[int] = REQ(json_validator=check_int, default=None), + can_mention_group_id: Optional[int] = REQ( + "can_mention_group", json_validator=check_int, default=None + ), ) -> HttpResponse: user_profiles = user_ids_to_users(members, user_profile.realm) name = check_user_group_name(name) @@ -101,7 +103,9 @@ def edit_user_group( user_group_id: int = REQ(json_validator=check_int, path_only=True), name: Optional[str] = REQ(default=None), description: Optional[str] = REQ(default=None), - can_mention_group_id: Optional[int] = REQ(json_validator=check_int, default=None), + can_mention_group_id: Optional[int] = REQ( + "can_mention_group", json_validator=check_int, default=None + ), ) -> HttpResponse: if name is None and description is None and can_mention_group_id is None: raise JsonableError(_("No new data supplied"))