diff --git a/zephyr/lib/actions.py b/zephyr/lib/actions.py index 71066c55f1..82a5a23254 100644 --- a/zephyr/lib/actions.py +++ b/zephyr/lib/actions.py @@ -116,17 +116,18 @@ def delete_all_user_sessions(): for session in Session.objects.all(): delete_session(session) -def do_deactivate(user_profile): +def do_deactivate(user_profile, log=True): user_profile.is_active = False; user_profile.set_unusable_password() user_profile.save(update_fields=["is_active", "password"]) delete_user_sessions(user_profile) - log_event({'type': 'user_deactivated', - 'timestamp': time.time(), - 'user': user_profile.email, - 'domain': user_profile.realm.domain}) + if log: + log_event({'type': 'user_deactivated', + 'timestamp': time.time(), + 'user': user_profile.email, + 'domain': user_profile.realm.domain}) notice = dict(event=dict(type="realm_user", op="remove", person=dict(email=user_profile.email, diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index 25042a8ab6..21e37b3822 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -8,7 +8,7 @@ from zephyr.models import Message, UserProfile, Stream, Recipient, Client, \ Subscription, Huddle, get_huddle, Realm, UserMessage, \ get_huddle_hash, clear_database, get_client, get_user_profile_by_id from zephyr.lib.actions import do_send_message, set_default_streams, \ - do_activate_user, do_change_password + do_activate_user, do_deactivate, do_change_password from zephyr.lib.parallel import run_parallel from django.db import transaction, connection from django.conf import settings @@ -538,6 +538,10 @@ def restore_saved_messages(): users_by_id[user_profile.id] = user_profile users[old_message["user"]] = user_profile continue + elif message_type == "user_deactivated": + user_profile = users[old_message["user"]] + do_deactivate(user_profile, log=False) + continue elif message_type == "user_change_password": # Just handle these the slow way user_profile = users[old_message["user"]]