mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
Add a management command to deactivate a user.
(imported from commit 14ef58bdd2cd20c05c68cd53cf911711d3bdb5fd)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.sessions.models import Session
|
||||
from zephyr.lib.context_managers import lockfile
|
||||
from zephyr.models import Realm, Stream, UserProfile, UserActivity, \
|
||||
Subscription, Recipient, Message, UserMessage, \
|
||||
@@ -51,6 +52,22 @@ def do_create_user(email, password, realm, full_name, short_name,
|
||||
'domain': realm.domain})
|
||||
return create_user(email, password, realm, full_name, short_name, active)
|
||||
|
||||
def user_sessions(user):
|
||||
return [s for s in Session.objects.all() if s.get_decoded().get('_auth_user_id') == user.id]
|
||||
|
||||
def do_deactivate(user_profile):
|
||||
user_profile.user.set_unusable_password()
|
||||
user_profile.user.is_active = False
|
||||
user_profile.user.save()
|
||||
|
||||
for session in user_sessions(user_profile.user):
|
||||
session.delete()
|
||||
|
||||
log_event({'type': 'user_deactivated',
|
||||
'timestamp': time.time(),
|
||||
'user': user_profile.user.email,
|
||||
'domain': user_profile.realm.domain})
|
||||
|
||||
def do_change_user_email(user, new_email):
|
||||
old_email = user.email
|
||||
user.email = new_email
|
||||
|
||||
Reference in New Issue
Block a user