mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
user_groups: Send metadata access related events on remove subgroups.
Fixes #33420.
(cherry picked from commit 6833ad8a21)
This commit is contained in:
committed by
Tim Abbott
parent
003ea23eb3
commit
06172ea126
@@ -526,6 +526,16 @@ def remove_subgroups_from_user_group(
|
||||
*,
|
||||
acting_user: UserProfile | None,
|
||||
) -> None:
|
||||
if len(subgroups) == 0:
|
||||
return
|
||||
|
||||
realm = user_group.realm
|
||||
supergroups = get_recursive_supergroups_union_for_groups([user_group.id])
|
||||
streams = list(
|
||||
get_metadata_access_streams_via_group_ids([group.id for group in supergroups], realm)
|
||||
)
|
||||
old_stream_metadata_user_ids = bulk_can_access_stream_metadata_user_ids(streams)
|
||||
|
||||
GroupGroupMembership.objects.filter(supergroup=user_group, subgroup__in=subgroups).delete()
|
||||
|
||||
subgroup_ids = [subgroup.id for subgroup in subgroups]
|
||||
@@ -555,6 +565,17 @@ def remove_subgroups_from_user_group(
|
||||
|
||||
do_send_subgroups_update_event("remove_subgroups", user_group, subgroup_ids)
|
||||
|
||||
new_stream_metadata_user_ids = bulk_can_access_stream_metadata_user_ids(streams)
|
||||
for stream in streams:
|
||||
user_ids_losing_metadata_access = (
|
||||
old_stream_metadata_user_ids[stream.id] - new_stream_metadata_user_ids[stream.id]
|
||||
)
|
||||
send_stream_deletion_event(
|
||||
realm,
|
||||
list(user_ids_losing_metadata_access),
|
||||
[stream],
|
||||
)
|
||||
|
||||
|
||||
@transaction.atomic(savepoint=False)
|
||||
def do_deactivate_user_group(
|
||||
|
||||
@@ -2260,8 +2260,10 @@ class NormalActionsTest(BaseAction):
|
||||
check_stream_create("events[1]", events[1])
|
||||
check_subscription_peer_add("events[2]", events[2])
|
||||
|
||||
# Remove subgroup for next test.
|
||||
with self.verify_action(num_events=2) as events:
|
||||
remove_subgroups_from_user_group(user_group, [hamlet_group], acting_user=None)
|
||||
check_user_group_remove_subgroups("events[0]", events[0])
|
||||
check_stream_delete("events[1]", events[1])
|
||||
else:
|
||||
with self.verify_action() as events:
|
||||
bulk_add_members_to_user_groups([user_group], [hamlet.id], acting_user=None)
|
||||
@@ -2275,8 +2277,9 @@ class NormalActionsTest(BaseAction):
|
||||
add_subgroups_to_user_group(user_group, [hamlet_group], acting_user=None)
|
||||
check_user_group_add_subgroups("events[0]", events[0])
|
||||
|
||||
# Remove subgroup for next test.
|
||||
with self.verify_action() as events:
|
||||
remove_subgroups_from_user_group(user_group, [hamlet_group], acting_user=None)
|
||||
check_user_group_remove_subgroups("events[0]", events[0])
|
||||
|
||||
nobody_group = NamedUserGroup.objects.get(
|
||||
name=SystemGroups.NOBODY, realm=othello.realm, is_system_group=True
|
||||
|
||||
@@ -572,6 +572,7 @@ class UserGroupTestCase(ZulipTestCase):
|
||||
bulk_remove_members_from_user_groups([], [hamlet.id], acting_user=None)
|
||||
bulk_remove_members_from_user_groups([test_group], [], acting_user=None)
|
||||
add_subgroups_to_user_group(test_group, [], acting_user=None)
|
||||
remove_subgroups_from_user_group(test_group, [], acting_user=None)
|
||||
|
||||
|
||||
class UserGroupAPITestCase(UserGroupTestCase):
|
||||
|
||||
Reference in New Issue
Block a user