logout_all_users: Add option to logout deactivated users.

This commit is contained in:
Tim Abbott 2016-05-09 14:01:49 -07:00
parent 393159bbd8
commit 9b65464b6b
2 changed files with 17 additions and 1 deletions

View File

@ -305,6 +305,16 @@ def delete_all_user_sessions():
for session in Session.objects.all():
delete_session(session)
def delete_all_deactivated_user_sessions():
for session in Session.objects.all():
user_profile_id = get_session_user(session)
if user_profile_id is None:
continue
user_profile = get_user_profile_by_id(user_profile_id)
if not user_profile.is_active or user_profile.realm.deactivated:
logging.info("Deactivating session for deactivated user %s" % (user_profile.email,))
delete_session(session)
def active_humans_in_realm(realm):
return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False)

View File

@ -5,7 +5,7 @@ from optparse import make_option
from django.core.management.base import BaseCommand
from zerver.lib.actions import delete_all_user_sessions, \
delete_realm_user_sessions
delete_realm_user_sessions, delete_all_deactivated_user_sessions
from zerver.models import get_realm
class Command(BaseCommand):
@ -17,11 +17,17 @@ class Command(BaseCommand):
action='store',
default=None,
help="Only logout all users in a particular realm"),
make_option('--deactivated-only',
action='store_true',
default=False,
help="Only logout all users who are deactivated"),
)
def handle(self, *args, **options):
if options["realm"]:
realm = get_realm(options["realm"])
delete_realm_user_sessions(realm)
elif options["deactivated_only"]:
delete_all_deactivated_user_sessions()
else:
delete_all_user_sessions()