Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
auth: Fix 500 error on accessing selfhosting subdomain user login page.
Aman Agrawala2dd84541d61
diff --git a/templates/zerver/invalid_realm.html b/templates/zerver/invalid_realm.htmlindex a885cac7c4c..ea72694e72c 100644--- a/templates/zerver/invalid_realm.html+++ b/templates/zerver/invalid_realm.html@@ -23,6 +23,11 @@{% trans %}Please try a different URL, <a href="{{ root_domain_url }}/accounts/find/">get a list of your accounts</a> on this server, or <a href="mailto:{{ support_email }}">contact this Zulip server's administrators</a>.{% endtrans %}{% endif %}</p>+ {% if is_selfhosting_management_error_page %}+ <p>+ {% trans %}<a href="{{ current_url }}/serverlogin/">Click here</a> to access plan management for your Zulip server.{% endtrans %}+ </p>+ {% endif %}</div></div></div>diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex a40d3b8df71..ccfc9c0889a 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -418,6 +418,11 @@ class AuthBackendTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertEqual(result["Location"], "http://zulip.testserver/")+ def test_invalid_login_on_self_hosting_management_subdomain(self) -> None:+ result = self.client_get("/login/", subdomain="selfhosting")+ self.assertEqual(result.status_code, 404)+ self.assert_in_response("No organization found", result)+@override_settings(AUTHENTICATION_BACKENDS=("zproject.backends.ZulipDummyBackend",))def test_no_backend_enabled(self) -> None:result = self.client_get("/login/")diff --git a/zerver/views/auth.py b/zerver/views/auth.pyindex 27cc02dd827..817e60ce9e6 100644--- a/zerver/views/auth.py+++ b/zerver/views/auth.py@@ -889,9 +889,17 @@ def login_page(next: str = "/",**kwargs: Any,) -> HttpResponse:- if get_subdomain(request) == settings.SOCIAL_AUTH_SUBDOMAIN:+ subdomain = get_subdomain(request)+ if subdomain == settings.SOCIAL_AUTH_SUBDOMAIN:return social_auth_subdomain_login_page(request)+ if subdomain == settings.SELF_HOSTING_MANAGEMENT_SUBDOMAIN:+ context = {+ "current_url": request.get_host(),+ "is_selfhosting_management_error_page": True,+ }+ return render(request, "zerver/invalid_realm.html", status=404, context=context)+# To support previewing the Zulip login pages, we have a special option# that disables the default behavior of redirecting logged-in users to the# logged-in app.