2016-06-04 16:52:18 +02:00
|
|
|
from argparse import ArgumentParser
|
2024-05-19 01:30:36 +02:00
|
|
|
from typing import Any, cast
|
2016-04-21 18:01:44 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
|
|
|
|
2022-04-14 23:57:15 +02:00
|
|
|
from zerver.actions.realm_settings 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
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"--redirect_url", metavar="<redirect_url>", help="URL to which the realm has moved"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2024-05-19 01:30:36 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--deactivation_reason",
|
|
|
|
metavar="<deactivation_reason>",
|
|
|
|
help="Reason for deactivation",
|
|
|
|
required=True,
|
|
|
|
)
|
2023-09-25 22:59:44 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--email_owners",
|
|
|
|
action="store_true",
|
|
|
|
help="Whether to email organization owners about realm deactivation",
|
|
|
|
)
|
2021-05-10 21:29:25 +02:00
|
|
|
self.add_realm_args(parser, required=True)
|
2015-09-20 04:10:27 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2023-09-25 22:59:44 +02:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2017-08-07 17:24:52 +02:00
|
|
|
realm = self.get_realm(options)
|
2024-05-19 01:30:36 +02:00
|
|
|
deactivation_reason = options["deactivation_reason"]
|
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
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
if options["redirect_url"]:
|
|
|
|
print("Setting the redirect URL to", options["redirect_url"])
|
|
|
|
do_add_deactivated_redirect(realm, options["redirect_url"])
|
2020-10-28 08:44:10 +01:00
|
|
|
|
2017-08-07 17:24:52 +02:00
|
|
|
if realm.deactivated:
|
2021-02-12 08:20:45 +01:00
|
|
|
print("The realm", options["realm_id"], "is already deactivated.")
|
2022-12-04 08:47:12 +01:00
|
|
|
return
|
2020-10-28 08:44:10 +01:00
|
|
|
|
2023-09-25 22:59:44 +02:00
|
|
|
send_realm_deactivation_email = options["email_owners"]
|
2017-08-07 17:24:52 +02:00
|
|
|
print("Deactivating", options["realm_id"])
|
2024-05-19 01:30:36 +02:00
|
|
|
do_deactivate_realm(
|
2023-09-25 22:59:44 +02:00
|
|
|
realm,
|
|
|
|
acting_user=None,
|
|
|
|
deactivation_reason=cast(Any, deactivation_reason),
|
|
|
|
email_owners=send_realm_deactivation_email,
|
2024-05-19 01:30:36 +02:00
|
|
|
)
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Done!")
|