From 5c790aac725602b3c2393dc94ca3cd053f3fcb45 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 18 Sep 2024 19:12:57 +0530 Subject: [PATCH] user_groups: Rename allow_deactivated in 'GET /user_groups'. This commit renames "allow_deactivated" parameter in "GET /user_groups" endpoint to "include_deactivated_groups", so that we can have consistent naming here and for client capability used for deciding whether to send deactivated groups in register response and how to handle the related events. --- api_docs/changelog.md | 2 ++ zerver/lib/events.py | 2 +- zerver/lib/user_groups.py | 4 ++-- zerver/openapi/zulip.yaml | 11 +++++++---- zerver/tests/test_user_groups.py | 8 ++++---- zerver/views/user_groups.py | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/api_docs/changelog.md b/api_docs/changelog.md index 8af8dba39d..cd95f8d569 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -36,6 +36,8 @@ format used by the Zulip server that they are interacting with. [client capability](/api/register-queue#parameter-client_capabilities) do not receive `update` event when name of a deactivated user group is updated. +* [`GET /user_groups`](/api/get-user-groups): Renamed `allow_deactivated` + parameter to `include_deactivated_groups`. **Feature level 293** diff --git a/zerver/lib/events.py b/zerver/lib/events.py index ab9232af13..cef6528e38 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -509,7 +509,7 @@ def fetch_initial_state_data( if want("realm_user_groups"): state["realm_user_groups"] = user_groups_in_realm_serialized( - realm, allow_deactivated=include_deactivated_groups + realm, include_deactivated_groups=include_deactivated_groups ) if user_profile is not None: diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.py index c37359d075..45327a74b1 100644 --- a/zerver/lib/user_groups.py +++ b/zerver/lib/user_groups.py @@ -480,7 +480,7 @@ def get_setting_value_for_user_group_object( def user_groups_in_realm_serialized( - realm: Realm, *, allow_deactivated: bool + realm: Realm, *, include_deactivated_groups: bool ) -> list[UserGroupDict]: """This function is used in do_events_register code path so this code should be performant. We need to do 2 database queries because @@ -494,7 +494,7 @@ def user_groups_in_realm_serialized( "can_mention_group__named_user_group", ).filter(realm=realm) - if not allow_deactivated: + if not include_deactivated_groups: realm_groups = realm_groups.filter(deactivated=False) membership = UserGroupMembership.objects.filter(user_group__realm=realm).values_list( diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 22f440bbe4..b728d8829e 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -20043,13 +20043,16 @@ paths: schema: type: object properties: - allow_deactivated: + include_deactivated_groups: description: | Whether to include deactivated user groups in the response. - **Changes**: New in Zulip 10.0 (feature level 290). Previously, - deactivated user groups did not exist and thus would never be - included in the response. + **Changes**: In Zulip 10.0 (feature level 294), renamed + `allow_deactivated` to `include_deactivated_groups`. + + New in Zulip 10.0 (feature level 290). Previously, deactivated + user groups did not exist and thus would never be included in + the response. type: boolean example: true default: false diff --git a/zerver/tests/test_user_groups.py b/zerver/tests/test_user_groups.py index 11168cc994..57217b1c54 100644 --- a/zerver/tests/test_user_groups.py +++ b/zerver/tests/test_user_groups.py @@ -89,7 +89,7 @@ class UserGroupTestCase(ZulipTestCase): assert user_group is not None empty_user_group = check_add_user_group(realm, "newgroup", [], acting_user=user) - user_groups = user_groups_in_realm_serialized(realm, allow_deactivated=False) + user_groups = user_groups_in_realm_serialized(realm, include_deactivated_groups=False) self.assert_length(user_groups, 10) self.assertEqual(user_groups[0]["id"], user_group.id) self.assertEqual(user_groups[0]["creator_id"], user_group.creator_id) @@ -161,7 +161,7 @@ class UserGroupTestCase(ZulipTestCase): }, acting_user=None, ) - user_groups = user_groups_in_realm_serialized(realm, allow_deactivated=False) + user_groups = user_groups_in_realm_serialized(realm, include_deactivated_groups=False) self.assertEqual(user_groups[10]["id"], new_user_group.id) self.assertEqual(user_groups[10]["creator_id"], new_user_group.creator_id) self.assertEqual( @@ -194,7 +194,7 @@ class UserGroupTestCase(ZulipTestCase): new_user_group, [another_new_group, owners_system_group], acting_user=None ) do_deactivate_user_group(another_new_group, acting_user=None) - user_groups = user_groups_in_realm_serialized(realm, allow_deactivated=True) + user_groups = user_groups_in_realm_serialized(realm, include_deactivated_groups=True) self.assert_length(user_groups, 12) self.assertEqual(user_groups[10]["id"], new_user_group.id) self.assertEqual(user_groups[10]["name"], "newgroup2") @@ -206,7 +206,7 @@ class UserGroupTestCase(ZulipTestCase): self.assertEqual(user_groups[11]["name"], "newgroup3") self.assertTrue(user_groups[11]["deactivated"]) - user_groups = user_groups_in_realm_serialized(realm, allow_deactivated=False) + user_groups = user_groups_in_realm_serialized(realm, include_deactivated_groups=False) self.assert_length(user_groups, 11) self.assertEqual(user_groups[10]["id"], new_user_group.id) self.assertEqual(user_groups[10]["name"], "newgroup2") diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index 5e11d211ee..1f15b41d59 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -98,10 +98,10 @@ def get_user_groups( request: HttpRequest, user_profile: UserProfile, *, - allow_deactivated: Json[bool] = False, + include_deactivated_groups: Json[bool] = False, ) -> HttpResponse: user_groups = user_groups_in_realm_serialized( - user_profile.realm, allow_deactivated=allow_deactivated + user_profile.realm, include_deactivated_groups=include_deactivated_groups ) return json_success(request, data={"user_groups": user_groups})