From 27b61815970300a2a56636914e33e96e4cd8e1dc Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Sat, 1 Feb 2025 01:14:26 +0800 Subject: [PATCH] register_server: Add docs_url to HostnameAlreadyInUseBouncerError. This means that the URL is only hard-coded on the bouncer side. That's useful, because now we'll be able to change the URL and only need a bouncer deployment for users to get the new URL when they encounter HostnameAlreadyInUseBouncerError. As opposed to self-hosted servers being stuck with an outdated docs link hardcoded in their register_server.py. --- zerver/lib/push_notifications.py | 3 ++- zerver/management/commands/register_server.py | 3 ++- zerver/tests/test_push_notifications.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index 95795efcc1..3d3648547f 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -1532,8 +1532,9 @@ class PushNotificationsDisallowedByBouncerError(Exception): class HostnameAlreadyInUseBouncerError(JsonableError): code = ErrorCode.HOSTNAME_ALREADY_IN_USE_BOUNCER_ERROR + docs_url = "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#moving-your-registration-to-a-new-server" - data_fields = ["hostname"] + data_fields = ["hostname", "docs_url"] def __init__(self, hostname: str) -> None: self.hostname: str = hostname diff --git a/zerver/management/commands/register_server.py b/zerver/management/commands/register_server.py index f553ddc9c2..5f6d672eef 100644 --- a/zerver/management/commands/register_server.py +++ b/zerver/management/commands/register_server.py @@ -237,6 +237,7 @@ that registration and saving the updated secret in "code" in content_dict and content_dict["code"] == "HOSTNAME_ALREADY_IN_USE_BOUNCER_ERROR" ): + docs_url = content_dict["docs_url"] print( "--------------------------------\n" "The hostname is already in use by another server. If you control the hostname \n" @@ -246,7 +247,7 @@ that registration and saving the updated secret in "\n" "For more information, see: \n" "\n" - "https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#moving-your-registration-to-a-new-server" + f"{docs_url}" ) raise CommandError diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 5b21b98a53..377468770d 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -48,6 +48,7 @@ from zerver.lib.exceptions import JsonableError from zerver.lib.push_notifications import ( APNsContext, DeviceToken, + HostnameAlreadyInUseBouncerError, InvalidRemotePushDeviceTokenError, UserPushIdentityCompat, b64_to_hex, @@ -5361,6 +5362,7 @@ class PushBouncerSignupTest(ZulipTestCase): result = self.client_post("/api/v1/remotes/server/register", request) self.assert_json_error(result, "A server with hostname example.com already exists") self.assertEqual(result.json()["code"], "HOSTNAME_ALREADY_IN_USE_BOUNCER_ERROR") + self.assertEqual(result.json()["docs_url"], HostnameAlreadyInUseBouncerError.docs_url) def test_register_contact_email_validation_rules(self) -> None: zulip_org_id = str(uuid.uuid4())