user_groups: Include "can_join_group" field in user group objects.

Fixes part of #25938.
This commit is contained in:
Sahil Batra 2024-09-19 19:09:08 +05:30 committed by Tim Abbott
parent e1d7f57da7
commit 1033230b52
8 changed files with 70 additions and 2 deletions

View File

@ -28,6 +28,9 @@ format used by the Zulip server that they are interacting with.
* [`PATCH /user_groups/{user_group_id}`](/api/update-user-group): Added
`can_join_group` parameter to support changing the user group whose
members can join the specified user group.
* [`GET /events`](/api/get-events), [`POST /register`](/api/register-queue),
[`GET /user_groups`](/api/get-user-groups): Add `can_manage_group` to
user group objects.
**Feature level 300**

View File

@ -34,7 +34,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
API_FEATURE_LEVEL = 300 # Last bumped for GET /messages API changes
API_FEATURE_LEVEL = 301 # Last bumped for can_join_group setting.
# 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

View File

@ -834,6 +834,7 @@ exports.fixtures = {
members: [1],
is_system_group: false,
direct_subgroup_ids: [2],
can_join_group: 16,
can_manage_group: 16,
can_mention_group: 11,
deactivated: false,

View File

@ -188,6 +188,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_join_group=get_group_setting_value_for_api(user_group.can_join_group),
can_manage_group=get_group_setting_value_for_api(user_group.can_manage_group),
can_mention_group=get_group_setting_value_for_api(user_group.can_mention_group),
deactivated=False,

View File

@ -1847,6 +1847,7 @@ group_type = DictType(
("direct_subgroup_ids", ListType(int)),
("description", str),
("is_system_group", bool),
("can_join_group", group_setting_type),
("can_manage_group", group_setting_type),
("can_mention_group", group_setting_type),
("deactivated", bool),
@ -1896,6 +1897,7 @@ user_group_data_type = DictType(
optional_keys=[
("name", str),
("description", str),
("can_join_group", group_setting_type),
("can_manage_group", group_setting_type),
("can_mention_group", group_setting_type),
("deactivated", bool),

View File

@ -55,6 +55,7 @@ class UserGroupDict(TypedDict):
creator_id: int | None
date_created: int | None
is_system_group: bool
can_join_group: int | AnonymousSettingGroupDict
can_manage_group: int | AnonymousSettingGroupDict
can_mention_group: int | AnonymousSettingGroupDict
deactivated: bool
@ -551,6 +552,8 @@ def user_groups_in_realm_serialized(
UserGroup and UserGroupMembership that we need.
"""
realm_groups = NamedUserGroup.objects.select_related(
"can_join_group",
"can_join_group__named_user_group",
"can_manage_group",
"can_manage_group__named_user_group",
"can_mention_group",
@ -603,6 +606,9 @@ def user_groups_in_realm_serialized(
members=direct_member_ids,
direct_subgroup_ids=direct_subgroup_ids,
is_system_group=user_group.is_system_group,
can_join_group=get_setting_value_for_user_group_object(
user_group.can_join_group, group_members, group_subgroups
),
can_manage_group=get_setting_value_for_user_group_object(
user_group.can_manage_group, group_members, group_subgroups
),

View File

@ -3161,6 +3161,7 @@ paths:
"description": "Backend team",
"id": 2,
"is_system_group": false,
"can_join_group": 16,
"can_manage_group": 16,
"can_mention_group": 11,
},
@ -3210,6 +3211,19 @@ paths:
description: |
The new description of the group. Only present if the description
changed.
can_join_group:
allOf:
- $ref: "#/components/schemas/GroupSettingValue"
- description: |
A [group-setting value][setting-values] defining the set of users who
have permission to join this group. Only present if this user group
permissiod setting changed.
**Changes**: New in Zulip 10.0 (feature level 301).
Will be one of the following:
[setting-values]: /api/group-setting-values
can_manage_group:
allOf:
- $ref: "#/components/schemas/GroupSettingValue"
@ -20530,6 +20544,18 @@ paths:
modified by users.
**Changes**: New in Zulip 5.0 (feature level 93).
can_join_group:
allOf:
- $ref: "#/components/schemas/GroupSettingValue"
- description: |
A [group-setting value][setting-values] defining the set of users who
have permission to join this user group.
**Changes**: New in Zulip 10.0 (feature level 301).
Will be one of the following:
[setting-values]: /api/group-setting-values
can_manage_group:
allOf:
- $ref: "#/components/schemas/GroupSettingValue"
@ -20589,6 +20615,7 @@ paths:
"members": [1],
"direct_subgroup_ids": [],
"is_system_group": true,
"can_join_group": 16,
"can_manage_group": 16,
"can_mention_group": 11,
},
@ -20601,6 +20628,7 @@ paths:
"members": [2],
"direct_subgroup_ids": [1],
"is_system_group": true,
"can_join_group": 17,
"can_manage_group": 17,
"can_mention_group": 12,
},
@ -20613,6 +20641,7 @@ paths:
"members": [3, 4],
"direct_subgroup_ids": [],
"is_system_group": false,
"can_join_group": 20,
"can_manage_group": 20,
"can_mention_group": 13,
},
@ -21858,6 +21887,18 @@ components:
directly modified by users.
**Changes**: New in Zulip 5.0 (feature level 93).
can_join_group:
allOf:
- $ref: "#/components/schemas/GroupSettingValue"
- description: |
A [group-setting value][setting-values] defining the set of users who
have permission to join this user group.
**Changes**: New in Zulip 10.0 (feature level 301).
Will be one of the following:
[setting-values]: /api/group-setting-values
can_manage_group:
allOf:
- $ref: "#/components/schemas/GroupSettingValue"

View File

@ -1836,6 +1836,10 @@ class NormalActionsTest(BaseAction):
self.user_profile.realm, "backend", [othello], "Backend team", acting_user=othello
)
check_user_group_add("events[0]", events[0])
nobody_group = NamedUserGroup.objects.get(
name=SystemGroups.NOBODY, realm=self.user_profile.realm, is_system_group=True
)
self.assertEqual(events[0]["group"]["can_join_group"], nobody_group.id)
self.assertEqual(
events[0]["group"]["can_manage_group"],
AnonymousSettingGroupDict(direct_members=[12], direct_subgroups=[]),
@ -1857,10 +1861,20 @@ class NormalActionsTest(BaseAction):
"frontend",
[othello],
"",
{"can_manage_group": user_group, "can_mention_group": user_group},
{
"can_join_group": user_group,
"can_manage_group": user_group,
"can_mention_group": user_group,
},
acting_user=othello,
)
check_user_group_add("events[0]", events[0])
self.assertEqual(
events[0]["group"]["can_join_group"],
AnonymousSettingGroupDict(
direct_members=[othello.id], direct_subgroups=[moderators_group.id]
),
)
self.assertEqual(
events[0]["group"]["can_manage_group"],
AnonymousSettingGroupDict(