mirror of https://github.com/zulip/zulip.git
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.
This commit is contained in:
parent
fb63c47ea6
commit
5c790aac72
|
@ -36,6 +36,8 @@ format used by the Zulip server that they are interacting with.
|
||||||
[client capability](/api/register-queue#parameter-client_capabilities)
|
[client capability](/api/register-queue#parameter-client_capabilities)
|
||||||
do not receive `update` event when name of a deactivated user group
|
do not receive `update` event when name of a deactivated user group
|
||||||
is updated.
|
is updated.
|
||||||
|
* [`GET /user_groups`](/api/get-user-groups): Renamed `allow_deactivated`
|
||||||
|
parameter to `include_deactivated_groups`.
|
||||||
|
|
||||||
**Feature level 293**
|
**Feature level 293**
|
||||||
|
|
||||||
|
|
|
@ -509,7 +509,7 @@ def fetch_initial_state_data(
|
||||||
|
|
||||||
if want("realm_user_groups"):
|
if want("realm_user_groups"):
|
||||||
state["realm_user_groups"] = user_groups_in_realm_serialized(
|
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:
|
if user_profile is not None:
|
||||||
|
|
|
@ -480,7 +480,7 @@ def get_setting_value_for_user_group_object(
|
||||||
|
|
||||||
|
|
||||||
def user_groups_in_realm_serialized(
|
def user_groups_in_realm_serialized(
|
||||||
realm: Realm, *, allow_deactivated: bool
|
realm: Realm, *, include_deactivated_groups: bool
|
||||||
) -> list[UserGroupDict]:
|
) -> list[UserGroupDict]:
|
||||||
"""This function is used in do_events_register code path so this code
|
"""This function is used in do_events_register code path so this code
|
||||||
should be performant. We need to do 2 database queries because
|
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",
|
"can_mention_group__named_user_group",
|
||||||
).filter(realm=realm)
|
).filter(realm=realm)
|
||||||
|
|
||||||
if not allow_deactivated:
|
if not include_deactivated_groups:
|
||||||
realm_groups = realm_groups.filter(deactivated=False)
|
realm_groups = realm_groups.filter(deactivated=False)
|
||||||
|
|
||||||
membership = UserGroupMembership.objects.filter(user_group__realm=realm).values_list(
|
membership = UserGroupMembership.objects.filter(user_group__realm=realm).values_list(
|
||||||
|
|
|
@ -20043,13 +20043,16 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
allow_deactivated:
|
include_deactivated_groups:
|
||||||
description: |
|
description: |
|
||||||
Whether to include deactivated user groups in the response.
|
Whether to include deactivated user groups in the response.
|
||||||
|
|
||||||
**Changes**: New in Zulip 10.0 (feature level 290). Previously,
|
**Changes**: In Zulip 10.0 (feature level 294), renamed
|
||||||
deactivated user groups did not exist and thus would never be
|
`allow_deactivated` to `include_deactivated_groups`.
|
||||||
included in the response.
|
|
||||||
|
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
|
type: boolean
|
||||||
example: true
|
example: true
|
||||||
default: false
|
default: false
|
||||||
|
|
|
@ -89,7 +89,7 @@ class UserGroupTestCase(ZulipTestCase):
|
||||||
assert user_group is not None
|
assert user_group is not None
|
||||||
empty_user_group = check_add_user_group(realm, "newgroup", [], acting_user=user)
|
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.assert_length(user_groups, 10)
|
||||||
self.assertEqual(user_groups[0]["id"], user_group.id)
|
self.assertEqual(user_groups[0]["id"], user_group.id)
|
||||||
self.assertEqual(user_groups[0]["creator_id"], user_group.creator_id)
|
self.assertEqual(user_groups[0]["creator_id"], user_group.creator_id)
|
||||||
|
@ -161,7 +161,7 @@ class UserGroupTestCase(ZulipTestCase):
|
||||||
},
|
},
|
||||||
acting_user=None,
|
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]["id"], new_user_group.id)
|
||||||
self.assertEqual(user_groups[10]["creator_id"], new_user_group.creator_id)
|
self.assertEqual(user_groups[10]["creator_id"], new_user_group.creator_id)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -194,7 +194,7 @@ class UserGroupTestCase(ZulipTestCase):
|
||||||
new_user_group, [another_new_group, owners_system_group], acting_user=None
|
new_user_group, [another_new_group, owners_system_group], acting_user=None
|
||||||
)
|
)
|
||||||
do_deactivate_user_group(another_new_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.assert_length(user_groups, 12)
|
||||||
self.assertEqual(user_groups[10]["id"], new_user_group.id)
|
self.assertEqual(user_groups[10]["id"], new_user_group.id)
|
||||||
self.assertEqual(user_groups[10]["name"], "newgroup2")
|
self.assertEqual(user_groups[10]["name"], "newgroup2")
|
||||||
|
@ -206,7 +206,7 @@ class UserGroupTestCase(ZulipTestCase):
|
||||||
self.assertEqual(user_groups[11]["name"], "newgroup3")
|
self.assertEqual(user_groups[11]["name"], "newgroup3")
|
||||||
self.assertTrue(user_groups[11]["deactivated"])
|
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.assert_length(user_groups, 11)
|
||||||
self.assertEqual(user_groups[10]["id"], new_user_group.id)
|
self.assertEqual(user_groups[10]["id"], new_user_group.id)
|
||||||
self.assertEqual(user_groups[10]["name"], "newgroup2")
|
self.assertEqual(user_groups[10]["name"], "newgroup2")
|
||||||
|
|
|
@ -98,10 +98,10 @@ def get_user_groups(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
user_profile: UserProfile,
|
user_profile: UserProfile,
|
||||||
*,
|
*,
|
||||||
allow_deactivated: Json[bool] = False,
|
include_deactivated_groups: Json[bool] = False,
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
user_groups = user_groups_in_realm_serialized(
|
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})
|
return json_success(request, data={"user_groups": user_groups})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue