2016-06-04 16:52:18 +02:00
|
|
|
from argparse import ArgumentParser
|
2017-11-16 00:43:27 +01:00
|
|
|
from typing import Any
|
2016-04-21 18:01:44 +02:00
|
|
|
|
2020-10-28 08:44:10 +01:00
|
|
|
from zerver.lib.actions import do_add_deactivated_redirect, do_deactivate_realm
|
2017-08-07 17:24:52 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2014-01-07 18:04:26 +01:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-08-07 17:24:52 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2016-04-21 17:58:48 +02:00
|
|
|
help = """Script to deactivate a realm."""
|
2014-01-07 18:04:26 +01:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2020-10-28 08:44:10 +01:00
|
|
|
parser.add_argument('--redirect_url', metavar='<redirect_url>',
|
|
|
|
help="URL to which the realm has moved")
|
2017-08-07 17:24:52 +02:00
|
|
|
self.add_realm_args(parser, True)
|
2015-09-20 04:10:27 +02:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
2017-08-07 17:24:52 +02:00
|
|
|
realm = self.get_realm(options)
|
2020-10-28 08:44:10 +01:00
|
|
|
|
2017-09-26 01:25:39 +02:00
|
|
|
assert realm is not None # Should be ensured by parser
|
|
|
|
|
2020-10-28 08:44:10 +01:00
|
|
|
if options['redirect_url']:
|
|
|
|
print("Setting the redirect URL to", options['redirect_url'])
|
|
|
|
do_add_deactivated_redirect(realm, options['redirect_url'])
|
|
|
|
|
2017-08-07 17:24:52 +02:00
|
|
|
if realm.deactivated:
|
2020-10-28 08:44:10 +01:00
|
|
|
print("The realm", options['realm_id'], "is already deactivated.")
|
2017-08-07 17:24:52 +02:00
|
|
|
exit(0)
|
2020-10-28 08:44:10 +01:00
|
|
|
|
2017-08-07 17:24:52 +02:00
|
|
|
print("Deactivating", options["realm_id"])
|
2016-04-21 18:01:44 +02:00
|
|
|
do_deactivate_realm(realm)
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Done!")
|