Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
registration: Fix "Resend" link not working for realm creation.
Sahil Batraafc5066e36b5
diff --git a/templates/zerver/accounts_send_confirm.html b/templates/zerver/accounts_send_confirm.htmlindex 780f0f2254d..5ae43509071 100644--- a/templates/zerver/accounts_send_confirm.html+++ b/templates/zerver/accounts_send_confirm.html@@ -28,6 +28,9 @@ page can be easily identified in it's respective JavaScript file --><form class="resend_confirm" action="/new/" method="post" style="position: absolute;">{{ csrf_input }}<input type="hidden" class="email" id="email" value="{{ email }}" name="email"/> + <input type="hidden" class="realm_name" value="{{ new_realm_name }}" name="realm_name"/> + <input type="hidden" class="realm_type" value="{{ realm_type }}" name="realm_type"/> + <input type="hidden" class="realm_subdomain" value="{{ realm_subdomain }}" name="realm_subdomain"/> </form>{% else %}<form class="resend_confirm" action="/accounts/home/" method="post" style="position: absolute;">diff --git a/zerver/tests/test_management_commands.py b/zerver/tests/test_management_commands.pyindex abfa251e84a..772580a53b2 100644--- a/zerver/tests/test_management_commands.py+++ b/zerver/tests/test_management_commands.py@@ -338,7 +338,8 @@ class TestGenerateRealmCreationLink(ZulipTestCase):)self.assertEqual(result.status_code, 302)self.assertEqual(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}", result["Location"]+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}",+ result["Location"],)result = self.client_get(result["Location"])self.assert_in_response("Check your email", result)diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 2b5abb28dd5..0122d98df5e 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -758,7 +758,9 @@ class PasswordResetTest(ZulipTestCase):result = self.client_get("/accounts/send_confirm/[email protected]")self.assert_in_success_response(["/accounts/home/"], result)- result = self.client_get("/accounts/new/send_confirm/[email protected]")+ result = self.client_get(+ "/accounts/new/send_confirm/[email protected]&realm_name=Zulip+test&realm_type=10&realm_subdomain=zuliptest"+ )self.assert_in_success_response(["/new/"], result)def test_password_reset_for_soft_deactivated_user(self) -> None:@@ -1266,7 +1268,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(org_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1401,7 +1403,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1447,7 +1449,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1496,7 +1498,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1556,7 +1558,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1601,7 +1603,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1642,7 +1644,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1687,7 +1689,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(realm_name)}&realm_type=10&realm_subdomain={string_id}"))result = self.client_get(result["Location"])@@ -1741,7 +1743,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(first_realm_name)}&realm_type=10&realm_subdomain={first_string_id}"))result = self.client_get(result["Location"])@@ -1755,7 +1757,7 @@ class RealmCreationTest(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertTrue(result["Location"].endswith(- f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}"+ f"/accounts/new/send_confirm/?email={urllib.parse.quote(email)}&realm_name={urllib.parse.quote_plus(second_realm_name)}&realm_type=10&realm_subdomain={second_string_id}"))result = self.client_get(result["Location"])diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex a51ca7a358a..44bc75674fb 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -58,7 +58,13 @@ from zerver.lib.sessions import get_expirable_session_varfrom zerver.lib.subdomains import get_subdomainfrom zerver.lib.url_encoding import append_url_query_stringfrom zerver.lib.users import get_accounts_for_email-from zerver.lib.validator import to_converted_or_fallback, to_non_negative_int, to_timezone_or_empty+from zerver.lib.validator import (+ check_capped_string,+ check_int_in,+ to_converted_or_fallback,+ to_non_negative_int,+ to_timezone_or_empty,+)from zerver.lib.zephyr import compute_mit_user_fullnamefrom zerver.models import (DisposableEmailError,@@ -756,7 +762,14 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Htif key_record is not None:key_record.delete()new_realm_send_confirm_url = reverse("new_realm_send_confirm")- query = urlencode({"email": email})+ query = urlencode(+ {+ "email": email,+ "realm_name": realm_name,+ "realm_type": realm_type,+ "realm_subdomain": realm_subdomain,+ }+ )url = append_url_query_string(new_realm_send_confirm_url, query)return HttpResponseRedirect(url)else:@@ -787,11 +800,26 @@ def signup_send_confirm(request: HttpRequest, email: str = REQ("email")) -> Http@add_google_analytics@has_request_variables-def new_realm_send_confirm(request: HttpRequest, email: str = REQ("email")) -> HttpResponse:+def new_realm_send_confirm(+ request: HttpRequest,+ email: str = REQ("email"),+ realm_name: str = REQ(str_validator=check_capped_string(Realm.MAX_REALM_NAME_LENGTH)),+ realm_type: int = REQ(json_validator=check_int_in(Realm.ORG_TYPE_IDS)),+ realm_subdomain: str = REQ(str_validator=check_capped_string(Realm.MAX_REALM_SUBDOMAIN_LENGTH)),+) -> HttpResponse:return TemplateResponse(request,"zerver/accounts_send_confirm.html",- context={"email": email, "realm_creation": True},+ context={+ "email": email,+ # Using "new_realm_name" key here since "realm_name" key is already present in+ # the context provided by zulip_default_context and it is "None" during realm+ # creation.+ "new_realm_name": realm_name,+ "realm_type": realm_type,+ "realm_subdomain": realm_subdomain,+ "realm_creation": True,+ },)