Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

audit_log: Correctly add acting_user in bulk_remove_subscriptions.

arpit5518807cddc905d
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 08cd3f67179..5a65e9f5862 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -3043,6 +3043,7 @@ def bulk_remove_subscriptions(users: Iterable[UserProfile],
all_subscription_logs: (List[RealmAuditLog]) = []
for (sub, stream) in subs_to_deactivate:
all_subscription_logs.append(RealmAuditLog(realm=sub.user_profile.realm,
+ acting_user=acting_user,
modified_user=sub.user_profile,
modified_stream=stream,
event_last_message_id=event_last_message_id,
diff --git a/zerver/management/commands/merge_streams.py b/zerver/management/commands/merge_streams.py
index 5d56f9e5a17..93bce61760d 100644
--- a/zerver/management/commands/merge_streams.py
+++ b/zerver/management/commands/merge_streams.py
@@ -68,7 +68,7 @@ class Command(ZulipBaseCommand):
print(f"Deactivating {len(subs_to_deactivate)} subscriptions")
bulk_remove_subscriptions([sub.user_profile for sub in subs_to_deactivate],
[stream_to_destroy],
- self.get_client())
+ self.get_client(), acting_user=None)
do_deactivate_stream(stream_to_destroy)
if len(users_to_activate) > 0:
print(f"Adding {len(users_to_activate)} subscriptions")
diff --git a/zerver/management/commands/remove_users_from_stream.py b/zerver/management/commands/remove_users_from_stream.py
index a646b250c36..19915a72a60 100644
--- a/zerver/management/commands/remove_users_from_stream.py
+++ b/zerver/management/commands/remove_users_from_stream.py
@@ -27,7 +27,7 @@ class Command(ZulipBaseCommand):
stream_name = options["stream"].strip()
stream = get_stream(stream_name, realm)
- result = bulk_remove_subscriptions(user_profiles, [stream], self.get_client())
+ result = bulk_remove_subscriptions(user_profiles, [stream], self.get_client(), acting_user=None)
not_subscribed = result[1]
not_subscribed_users = {tup[0] for tup in not_subscribed}
diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py
index 47d240cb86c..22335a9bcf6 100644
--- a/zerver/tests/test_audit_log.py
+++ b/zerver/tests/test_audit_log.py
@@ -184,17 +184,19 @@ class TestRealmAuditLog(ZulipTestCase):
now = timezone_now()
user = [self.example_user('hamlet')]
stream = [self.make_stream('test_stream')]
-
- bulk_add_subscriptions(stream, user)
+ acting_user = self.example_user('iago')
+ bulk_add_subscriptions(stream, user, acting_user=acting_user)
subscription_creation_logs = RealmAuditLog.objects.filter(event_type=RealmAuditLog.SUBSCRIPTION_CREATED,
- event_time__gte=now)
+ event_time__gte=now, acting_user=acting_user, modified_user=user[0],
+ modified_stream=stream[0])
self.assertEqual(subscription_creation_logs.count(), 1)
self.assertEqual(subscription_creation_logs[0].modified_stream.id, stream[0].id)
self.assertEqual(subscription_creation_logs[0].modified_user, user[0])
- bulk_remove_subscriptions(user, stream, get_client("website"))
+ bulk_remove_subscriptions(user, stream, get_client("website"), acting_user=acting_user)
subscription_deactivation_logs = RealmAuditLog.objects.filter(event_type=RealmAuditLog.SUBSCRIPTION_DEACTIVATED,
- event_time__gte=now)
+ event_time__gte=now, acting_user=acting_user, modified_user=user[0],
+ modified_stream=stream[0])
self.assertEqual(subscription_deactivation_logs.count(), 1)
self.assertEqual(subscription_deactivation_logs[0].modified_stream.id, stream[0].id)
self.assertEqual(subscription_deactivation_logs[0].modified_user, user[0])