2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
2016-10-16 00:29:57 +02:00
|
|
|
from argparse import ArgumentParser
|
2013-04-02 18:00:12 +02:00
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
2013-07-29 23:03:31 +02:00
|
|
|
from zerver.lib.actions import delete_all_user_sessions, \
|
2016-05-09 23:01:49 +02:00
|
|
|
delete_realm_user_sessions, delete_all_deactivated_user_sessions
|
2016-11-16 21:16:02 +01:00
|
|
|
from zerver.models import get_realm_by_string_id
|
2013-04-02 18:00:12 +02:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Log out all users."
|
|
|
|
|
2016-10-17 05:31:47 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-10-16 00:29:57 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
|
|
|
parser.add_argument('--realm',
|
|
|
|
dest='realm',
|
|
|
|
action='store',
|
|
|
|
default=None,
|
|
|
|
help="Only logout all users in a particular realm")
|
|
|
|
parser.add_argument('--deactivated-only',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Only logout all users who are deactivated")
|
|
|
|
|
2013-04-02 18:00:12 +02:00
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **Any) -> None
|
2013-04-02 18:00:12 +02:00
|
|
|
if options["realm"]:
|
2016-11-16 21:16:02 +01:00
|
|
|
realm = get_realm_by_string_id(options["realm"])
|
2013-04-02 18:00:12 +02:00
|
|
|
delete_realm_user_sessions(realm)
|
2016-05-09 23:01:49 +02:00
|
|
|
elif options["deactivated_only"]:
|
|
|
|
delete_all_deactivated_user_sessions()
|
2013-04-02 18:00:12 +02:00
|
|
|
else:
|
|
|
|
delete_all_user_sessions()
|