Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
realm_creation: Rework error pages.
Mateusz Mandera582d5b0aa31a
diff --git a/templates/zerver/realm_creation_disabled.html b/templates/zerver/realm_creation_disabled.htmlnew file mode 100644index 00000000000..f407222a3b6--- /dev/null+++ b/templates/zerver/realm_creation_disabled.html@@ -0,0 +1,24 @@+{% extends "zerver/portico.html" %}++{% block title %}+<title>{{ _("Organization creation link required") }} | Zulip</title>+{% endblock %}++{% block portico_content %}+<div class="error_page">+ <div class="container row-fluid">+ <img src="/static/images/errors/500art.svg" alt=""/>+ <div class="errorbox">+ <div class="errorcontent">+ <h1 class="lead">{{ _("Organization creation link required") }}</h1>+ <p>+ {% trans %}+ Creating a new organization on this server requires a valid organization creation link.+ Please see <a href="https://zulip.readthedocs.io/en/stable/production/multiple-organizations.html">documentation</a> on creating a new organization for more information.+ {% endtrans %}+ </p>+ </div>+ </div>+ </div>+</div>+{% endblock %}diff --git a/templates/zerver/realm_creation_failed.html b/templates/zerver/realm_creation_failed.htmldeleted file mode 100644index d46b2c0b597..00000000000--- a/templates/zerver/realm_creation_failed.html+++ /dev/null@@ -1,35 +0,0 @@-{% extends "zerver/portico.html" %}-{% set entrypoint = "landing-page" %}--{% block title %}-<title>{{ _("Error creating new organization") }} | Zulip</title>-{% endblock %}--{% block customhead %}-<meta name="viewport" content="width=device-width, initial-scale=1.0" />-{% endblock %}--{% block portico_content %}--{% include 'zerver/landing_nav.html' %}--<div class="portico-landing why-page">- <div class="hero small-hero">- <h1 class="center">{{ message }}</h1>- </div>- <div class="main">- <div class="padded-content">- <div class="inner-content">- <p>{{ _('This server does not allow members of the public to create new organizations.') }}</p>- <p>- {% trans zulip_cloud_link="https://zulip.com",production_install_url="https://zulip.readthedocs.io/en/stable/production/install.html" %}- Zulip is open source, so you can <a href="{{ production_install_url}}">install your own Zulip server</a> or create a new organization on- <a href="{{ zulip_cloud_link }}">Zulip Cloud</a>- {% endtrans %}- </p>- </div>- </div>- </div>-</div>--{% endblock %}diff --git a/templates/zerver/realm_creation_link_invalid.html b/templates/zerver/realm_creation_link_invalid.htmlnew file mode 100644index 00000000000..8eb09c68a79--- /dev/null+++ b/templates/zerver/realm_creation_link_invalid.html@@ -0,0 +1,25 @@+{% extends "zerver/portico.html" %}++{% block title %}+<title>{{ _("Organization creation link expired or invalid") }} | Zulip</title>+{% endblock %}++{% block portico_content %}+<div class="error_page">+ <div class="container">+ <div class="row-fluid">+ <img class="hourglass-img" src="/static/images/errors/timeout_hourglass.png" alt=""/>+ <div class="errorbox">+ <div class="errorcontent">+ <h1 class="lead">{{ _("Organization creation link expired or invalid") }}</h1>+ <p>+ {% trans %}+ Unfortunately, this is not a valid link for creating an organization. Please <a href="/new/">obtain a new link</a> and try again.+ {% endtrans %}+ </p>+ </div>+ </div>+ </div>+ </div>+</div>+{% endblock %}diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.pyindex a4b14a8abc1..c6de1b10561 100644--- a/zerver/tests/test_management_commands.py+++ b/zerver/tests/test_management_commands.py@@ -309,9 +309,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase):# Original link is now deadresult = self.client_get(generated_link)- self.assert_in_success_response(- ["The organization creation link has expired or is not valid."], result- )+ self.assert_in_success_response(["Organization creation link expired or invalid"], result)@override_settings(OPEN_REALM_CREATION=False)def test_generate_link_confirm_email(self) -> None:@@ -326,18 +324,14 @@ class TestGenerateRealmCreationLink(ZulipTestCase):# Original link is now deadresult = self.client_get(generated_link)- self.assert_in_success_response(- ["The organization creation link has expired or is not valid."], result- )+ self.assert_in_success_response(["Organization creation link expired or invalid"], result)@override_settings(OPEN_REALM_CREATION=False)def test_realm_creation_with_random_link(self) -> None:# Realm creation attempt with an invalid link should failrandom_link = "/new/5e89081eb13984e0f3b130bf7a4121d153f1614b"result = self.client_get(random_link)- self.assert_in_success_response(- ["The organization creation link has expired or is not valid."], result- )+ self.assert_in_success_response(["Organization creation link expired or invalid"], result)@override_settings(OPEN_REALM_CREATION=False)def test_realm_creation_with_expired_link(self) -> None:@@ -351,9 +345,7 @@ class TestGenerateRealmCreationLink(ZulipTestCase):obj.save()result = self.client_get(generated_link)- self.assert_in_success_response(- ["The organization creation link has expired or is not valid."], result- )+ self.assert_in_success_response(["Organization creation link expired or invalid"], result)@skipUnless(settings.ZILENCER_ENABLED, "requires zilencer")diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 233decdb002..97002d29a38 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -3456,7 +3456,7 @@ class RealmCreationTest(ZulipTestCase):# Create new realm with the email, but no creation key.result = self.client_post("/new/", {"email": email})self.assertEqual(result.status_code, 200)- self.assert_in_response("New organization creation disabled", result)+ self.assert_in_response("Organization creation link required", result)@override_settings(OPEN_REALM_CREATION=True)def test_create_realm_with_subdomain(self) -> None:diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 96f274d365a..5ff05bf4203 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -13,7 +13,6 @@ from django.http import HttpRequest, HttpResponse, HttpResponseRedirectfrom django.shortcuts import redirect, renderfrom django.urls import reversefrom django.utils.translation import get_language-from django.utils.translation import gettext as _from django_auth_ldap.backend import LDAPBackend, _LDAPUserfrom confirmation.models import (@@ -611,17 +610,13 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Htexcept RealmCreationKey.Invalid:return render(request,- "zerver/realm_creation_failed.html",- context={- "message": _("The organization creation link has expired" " or is not valid.")- },+ "zerver/realm_creation_link_invalid.html",)if not settings.OPEN_REALM_CREATION:if key_record is None:return render(request,- "zerver/realm_creation_failed.html",- context={"message": _("New organization creation disabled")},+ "zerver/realm_creation_disabled.html",)# When settings.OPEN_REALM_CREATION is enabled, anyone can create a new realm,