registration: Fix "Resend" link not working for realm creation.

The "Resend" link for realm creation was not working correctly
because it is implemented by basically submiting the registration
form again which results in resending the email but all the
required parameters were not passed to the form after recent
changes in the realm creation flow.

This commit fixes it by passing all the required parameters -
email, realm name, realm type and realm subdomain, when submitting
form again by clicking on the "resend" link.

Fixes #25249.
This commit is contained in:
Sahil Batra 2023-04-26 15:57:30 +05:30 committed by Tim Abbott
parent f8f4fa4c5e
commit afc5066e36
4 changed files with 50 additions and 16 deletions

View File

@ -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"/>&nbsp;
<input type="hidden" class="realm_name" value="{{ new_realm_name }}" name="realm_name"/>&nbsp;
<input type="hidden" class="realm_type" value="{{ realm_type }}" name="realm_type"/>&nbsp;
<input type="hidden" class="realm_subdomain" value="{{ realm_subdomain }}" name="realm_subdomain"/>&nbsp;
</form>
{% else %}
<form class="resend_confirm" action="/accounts/home/" method="post" style="position: absolute;">

View File

@ -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)

View File

@ -758,7 +758,9 @@ class PasswordResetTest(ZulipTestCase):
result = self.client_get("/accounts/send_confirm/?email=alice@example.com")
self.assert_in_success_response(["/accounts/home/"], result)
result = self.client_get("/accounts/new/send_confirm/?email=alice@example.com")
result = self.client_get(
"/accounts/new/send_confirm/?email=alice@example.com&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"])

View File

@ -58,7 +58,13 @@ from zerver.lib.sessions import get_expirable_session_var
from zerver.lib.subdomains import get_subdomain
from zerver.lib.url_encoding import append_url_query_string
from 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_fullname
from zerver.models import (
DisposableEmailError,
@ -756,7 +762,14 @@ def create_realm(request: HttpRequest, creation_key: Optional[str] = None) -> Ht
if 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,
},
)