Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
change_realm_subdomain: Support skipping the redirect.
Alex Vandiver5529639b84af
diff --git a/zerver/actions/create_realm.py b/zerver/actions/create_realm.pyindex fc0235a5790..48afc3e5134 100644--- a/zerver/actions/create_realm.py+++ b/zerver/actions/create_realm.py@@ -30,7 +30,11 @@ from zerver.models import (def do_change_realm_subdomain(- realm: Realm, new_subdomain: str, *, acting_user: Optional[UserProfile]+ realm: Realm,+ new_subdomain: str,+ *,+ acting_user: Optional[UserProfile],+ add_deactivated_redirect: bool = True,) -> None:"""Changing a realm's subdomain is a highly disruptive operation,because all existing clients will need to be updated to point to@@ -69,9 +73,10 @@ def do_change_realm_subdomain(# deactivated. We are creating a deactivated realm using old subdomain and setting# it's deactivated redirect to new_subdomain so that we can tell the users that# the realm has been moved to a new subdomain.- placeholder_realm = do_create_realm(old_subdomain, realm.name)- do_deactivate_realm(placeholder_realm, acting_user=None)- do_add_deactivated_redirect(placeholder_realm, realm.uri)+ if add_deactivated_redirect:+ placeholder_realm = do_create_realm(old_subdomain, realm.name)+ do_deactivate_realm(placeholder_realm, acting_user=None)+ do_add_deactivated_redirect(placeholder_realm, realm.uri)def set_realm_permissions_based_on_org_type(realm: Realm) -> None:diff --git a/zerver/management/commands/change_realm_subdomain.py b/zerver/management/commands/change_realm_subdomain.pyindex 0b982456999..fc3dd9a0596 100644--- a/zerver/management/commands/change_realm_subdomain.py+++ b/zerver/management/commands/change_realm_subdomain.py@@ -11,11 +11,21 @@ class Command(ZulipBaseCommand):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")+ parser.add_argument(+ "--skip-redirect",+ action="store_true",+ help="Do not redirect the old name to the new one",+ )- def handle(self, *args: Any, **options: str) -> None:+ def handle(self, *args: Any, **options: Any) -> None:realm = self.get_realm(options)assert realm is not None # Should be ensured by parsernew_subdomain = options["new_subdomain"]- do_change_realm_subdomain(realm, new_subdomain, acting_user=None)+ do_change_realm_subdomain(+ realm,+ new_subdomain,+ acting_user=None,+ add_deactivated_redirect=not options["skip_redirect"],+ )print("Done!")diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 28d14561ae7..c7e00ffe146 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -221,6 +221,19 @@ class DeactivationNoticeTestCase(ZulipTestCase):result.content.decode(),)+ def test_no_deactivation_notice_with_no_rediect(self) -> None:+ realm = get_realm("zulip")+ do_change_realm_subdomain(+ realm, "new-subdomain-name", acting_user=None, add_deactivated_redirect=False+ )++ result = self.client_get("/login/", follow=True)+ self.assertEqual(result.status_code, 404)+ self.assertNotIn(+ "new-subdomain-name",+ result.content.decode(),+ )+def test_deactivated_redirect_field_of_placeholder_realms_are_modified_on_changing_subdomain_multiple_times(self,) -> None: