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.

do_delete_user: Clean up acting_user logic.

Tim Abbottf446560607d5
diff --git a/zerver/actions/users.py b/zerver/actions/users.py
index 703a84f2bab..da3b06ed061 100644
--- a/zerver/actions/users.py
+++ b/zerver/actions/users.py
@@ -42,11 +42,11 @@ if settings.BILLING_ENABLED:
from corporate.lib.stripe import update_license_ledger_if_needed
-def do_delete_user(user_profile: UserProfile) -> None:
+def do_delete_user(user_profile: UserProfile, *, acting_user: Optional[UserProfile]) -> None:
if user_profile.realm.is_zephyr_mirror_realm:
raise AssertionError("Deleting zephyr mirror users is not supported")
- do_deactivate_user(user_profile, acting_user=None)
+ do_deactivate_user(user_profile, acting_user=acting_user)
subscribed_huddle_recipient_ids = set(
Subscription.objects.filter(
@@ -88,7 +88,7 @@ def do_delete_user(user_profile: UserProfile) -> None:
RealmAuditLog.objects.create(
realm=replacement_user.realm,
modified_user=replacement_user,
- acting_user=None,
+ acting_user=acting_user,
event_type=RealmAuditLog.USER_DELETED,
event_time=timezone_now(),
)
diff --git a/zerver/management/commands/delete_user.py b/zerver/management/commands/delete_user.py
index e2c4a779bc5..35533e5d962 100644
--- a/zerver/management/commands/delete_user.py
+++ b/zerver/management/commands/delete_user.py
@@ -64,5 +64,5 @@ This will:
raise CommandError("This was a dry run. Pass -f to actually delete.")
for user_profile in user_profiles:
- do_delete_user(user_profile)
+ do_delete_user(user_profile, acting_user=None)
print(f"Successfully deleted user {user_profile.delivery_email}.")
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index 52ca5b0b39f..79a838d737e 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -2218,7 +2218,7 @@ class DeleteUserTest(ZulipTestCase):
)
self.assertGreater(len(huddle_with_hamlet_recipient_ids), 0)
- do_delete_user(hamlet)
+ do_delete_user(hamlet, acting_user=None)
replacement_dummy_user = UserProfile.objects.get(id=hamlet_user_id, realm=realm)