2021-05-10 19:49:55 +02:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
from typing import Any
|
|
|
|
|
2022-04-14 23:58:15 +02:00
|
|
|
from zerver.actions.create_realm import do_change_realm_subdomain
|
2021-05-10 19:49:55 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
|
|
|
|
|
|
|
|
|
|
|
class Command(ZulipBaseCommand):
|
|
|
|
help = """Change realm's subdomain."""
|
|
|
|
|
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
|
|
self.add_realm_args(parser, required=True)
|
|
|
|
parser.add_argument("new_subdomain", metavar="<new subdomain>", help="realm new subdomain")
|
2022-06-23 23:57:39 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--skip-redirect",
|
|
|
|
action="store_true",
|
|
|
|
help="Do not redirect the old name to the new one",
|
|
|
|
)
|
2021-05-10 19:49:55 +02:00
|
|
|
|
2022-06-23 23:57:39 +02:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2021-05-10 19:49:55 +02:00
|
|
|
realm = self.get_realm(options)
|
|
|
|
assert realm is not None # Should be ensured by parser
|
|
|
|
|
|
|
|
new_subdomain = options["new_subdomain"]
|
2022-06-23 23:57:39 +02:00
|
|
|
do_change_realm_subdomain(
|
|
|
|
realm,
|
|
|
|
new_subdomain,
|
|
|
|
acting_user=None,
|
|
|
|
add_deactivated_redirect=not options["skip_redirect"],
|
|
|
|
)
|
2021-05-10 19:49:55 +02:00
|
|
|
print("Done!")
|