diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 33f05a27ee..3ba13f1619 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -531,8 +531,8 @@ def do_reactivate_realm(realm): realm.deactivated = False realm.save(update_fields=["deactivated"]) -def do_deactivate_user(user_profile, _cascade=True): - # type: (UserProfile, bool) -> None +def do_deactivate_user(user_profile, acting_user=None, _cascade=True): + # type: (UserProfile, Optional[UserProfile], bool) -> None if not user_profile.is_active: return @@ -544,6 +544,7 @@ def do_deactivate_user(user_profile, _cascade=True): event_time = timezone_now() RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile, + acting_user=acting_user, event_type='user_deactivated', event_time=event_time) do_increment_logging_stat(user_profile.realm, COUNT_STATS['active_users_log:is_bot:day'], user_profile.is_bot, event_time, increment=-1) @@ -565,7 +566,7 @@ def do_deactivate_user(user_profile, _cascade=True): bot_profiles = UserProfile.objects.filter(is_bot=True, is_active=True, bot_owner=user_profile) for profile in bot_profiles: - do_deactivate_user(profile, _cascade=False) + do_deactivate_user(profile, acting_user=acting_user, _cascade=False) def do_deactivate_stream(stream, log=True): # type: (Stream, bool) -> None diff --git a/zerver/views/users.py b/zerver/views/users.py index acc3a6641f..3548839fe7 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -48,7 +48,7 @@ def deactivate_user_own_backend(request, user_profile): if user_profile.is_realm_admin and check_last_admin(user_profile): return json_error(_('Cannot deactivate the only organization administrator')) - do_deactivate_user(user_profile) + do_deactivate_user(user_profile, acting_user=user_profile) return json_success() def check_last_admin(user_profile): @@ -71,7 +71,7 @@ def _deactivate_user_profile_backend(request, user_profile, target): if not user_profile.can_admin_user(target): return json_error(_('Insufficient permission')) - do_deactivate_user(target) + do_deactivate_user(target, acting_user=user_profile) return json_success() def reactivate_user_backend(request, user_profile, email):