mirror of https://github.com/zulip/zulip.git
user_groups: Track acting user for remove_members_from_user_group.
This is a prep-commit for populating RealmAuditLogs for changes made to UserGroup. Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
parent
7ae4549b3f
commit
e4cf3611cf
|
@ -83,7 +83,9 @@ def update_users_in_full_members_system_group(
|
||||||
new_full_member_ids = [user["id"] for user in new_full_members]
|
new_full_member_ids = [user["id"] for user in new_full_members]
|
||||||
|
|
||||||
if len(old_full_members) > 0:
|
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:
|
if len(new_full_members) > 0:
|
||||||
bulk_add_members_to_user_group(
|
bulk_add_members_to_user_group(
|
||||||
|
@ -178,7 +180,9 @@ def bulk_add_members_to_user_group(
|
||||||
|
|
||||||
|
|
||||||
@transaction.atomic(savepoint=False)
|
@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(
|
UserGroupMembership.objects.filter(
|
||||||
user_group_id=user_group.id, user_profile_id__in=user_profile_ids
|
user_group_id=user_group.id, user_profile_id__in=user_profile_ids
|
||||||
).delete()
|
).delete()
|
||||||
|
|
|
@ -452,7 +452,9 @@ class MissedMessageNotificationsTest(ZulipTestCase):
|
||||||
already_notified={"email_notified": True, "push_notified": True},
|
already_notified={"email_notified": True, "push_notified": True},
|
||||||
)
|
)
|
||||||
destroy_event_queue(user_profile, client_descriptor.event_queue.id)
|
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
|
# Test the hook with a stream message with stream_push_notify
|
||||||
change_subscription_properties(user_profile, stream, sub, {"push_notifications": True})
|
change_subscription_properties(user_profile, stream, sub, {"push_notifications": True})
|
||||||
|
|
|
@ -1307,7 +1307,10 @@ class NormalActionsTest(BaseAction):
|
||||||
|
|
||||||
# Test remove members
|
# Test remove members
|
||||||
hamlet = self.example_user("hamlet")
|
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])
|
check_user_group_remove_members("events[0]", events[0])
|
||||||
|
|
||||||
api_design = create_user_group(
|
api_design = create_user_group(
|
||||||
|
|
|
@ -153,7 +153,7 @@ def remove_members_from_group_backend(
|
||||||
raise JsonableError(_("There is no member '{}' in this user group").format(member))
|
raise JsonableError(_("There is no member '{}' in this user group").format(member))
|
||||||
|
|
||||||
user_profile_ids = [user.id for user in user_profiles]
|
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)
|
return json_success(request)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue