diff --git a/zerver/actions/user_groups.py b/zerver/actions/user_groups.py index c4988f66f3..bfbdf49e71 100644 --- a/zerver/actions/user_groups.py +++ b/zerver/actions/user_groups.py @@ -83,7 +83,9 @@ def update_users_in_full_members_system_group( new_full_member_ids = [user["id"] for user in new_full_members] if len(old_full_members) > 0: - remove_members_from_user_group(full_members_system_group, old_full_member_ids) + remove_members_from_user_group( + full_members_system_group, old_full_member_ids, acting_user=acting_user + ) if len(new_full_members) > 0: bulk_add_members_to_user_group( @@ -178,7 +180,9 @@ def bulk_add_members_to_user_group( @transaction.atomic(savepoint=False) -def remove_members_from_user_group(user_group: UserGroup, user_profile_ids: List[int]) -> None: +def remove_members_from_user_group( + user_group: UserGroup, user_profile_ids: List[int], *, acting_user: Optional[UserProfile] +) -> None: UserGroupMembership.objects.filter( user_group_id=user_group.id, user_profile_id__in=user_profile_ids ).delete() diff --git a/zerver/tests/test_event_queue.py b/zerver/tests/test_event_queue.py index 5dc37605b7..6b01300997 100644 --- a/zerver/tests/test_event_queue.py +++ b/zerver/tests/test_event_queue.py @@ -452,7 +452,9 @@ class MissedMessageNotificationsTest(ZulipTestCase): already_notified={"email_notified": True, "push_notified": True}, ) destroy_event_queue(user_profile, client_descriptor.event_queue.id) - remove_members_from_user_group(hamlet_and_cordelia, [user_profile.id, cordelia.id]) + remove_members_from_user_group( + hamlet_and_cordelia, [user_profile.id, cordelia.id], acting_user=None + ) # Test the hook with a stream message with stream_push_notify change_subscription_properties(user_profile, stream, sub, {"push_notifications": True}) diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 62c456e9ce..1ef72ebfec 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -1307,7 +1307,10 @@ class NormalActionsTest(BaseAction): # Test remove members hamlet = self.example_user("hamlet") - events = self.verify_action(lambda: remove_members_from_user_group(backend, [hamlet.id])) + events = self.verify_action( + lambda: remove_members_from_user_group(backend, [hamlet.id], acting_user=None) + ) + check_user_group_remove_members("events[0]", events[0]) api_design = create_user_group( diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index 85ec58f088..dde6ac6f74 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -153,7 +153,7 @@ def remove_members_from_group_backend( raise JsonableError(_("There is no member '{}' in this user group").format(member)) user_profile_ids = [user.id for user in user_profiles] - remove_members_from_user_group(user_group, user_profile_ids) + remove_members_from_user_group(user_group, user_profile_ids, acting_user=user_profile) return json_success(request)