do_deactivate_user: Add acting user to RealmAuditLog.

This commit is contained in:
Tim Abbott 2017-08-16 16:20:23 -07:00
parent 98aae162dc
commit 7cfb4e195f
2 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -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):