signup: Stop prompting self-hosted customers for marketing emails.

Fixes #20595.
This commit is contained in:
Eeshan Garg 2022-01-05 17:53:40 -05:00 committed by Tim Abbott
parent 9aa5082d63
commit 1b303e7b2f
4 changed files with 60 additions and 2 deletions

View File

@ -249,6 +249,7 @@ Form is validated both client-side using jquery-validate (see signup.js) and ser
{% endif %}
</div>
{% endif %}
{% if corporate_enabled %}
<div class="input-group">
<label for="id_enable_marketing_emails" class="inline-block checkbox marketing_emails_checkbox">
<input id="id_enable_marketing_emails" type="checkbox" name="enable_marketing_emails"
@ -257,6 +258,7 @@ Form is validated both client-side using jquery-validate (see signup.js) and ser
{% trans %}Subscribe me to Zulip's low-traffic newsletter (a few emails a year).{% endtrans %}
</label>
</div>
{% endif %}
<div class="register-button-box">
<button class="register-button" type="submit">
<span>{{ _('Sign up') }}</span>

View File

@ -653,7 +653,7 @@ Output:
source_realm_id: str = "",
key: Optional[str] = None,
realm_type: int = Realm.ORG_TYPES["business"]["id"],
enable_marketing_emails: bool = True,
enable_marketing_emails: Optional[bool] = None,
is_demo_organization: bool = False,
**kwargs: ClientArg,
) -> HttpResponse:
@ -678,9 +678,10 @@ Output:
"from_confirmation": from_confirmation,
"default_stream_group": default_stream_groups,
"source_realm_id": source_realm_id,
"enable_marketing_emails": enable_marketing_emails,
"is_demo_organization": is_demo_organization,
}
if enable_marketing_emails is not None:
payload["enable_marketing_emails"] = enable_marketing_emails
if password is not None:
payload["password"] = password
if realm_in_root_domain is not None:

View File

@ -3232,6 +3232,60 @@ class RealmCreationTest(ZulipTestCase):
self.assertEqual(user.realm, realm)
self.assertTrue(user.enable_marketing_emails)
@override_settings(OPEN_REALM_CREATION=True, CORPORATE_ENABLED=False)
def test_create_realm_without_prompting_for_marketing_emails(self) -> None:
password = "test"
string_id = "zuliptest"
email = "user1@test.com"
realm_name = "Test"
# Make sure the realm does not exist
with self.assertRaises(Realm.DoesNotExist):
get_realm(string_id)
# Create new realm with the email
result = self.client_post("/new/", {"email": email})
self.assertEqual(result.status_code, 302)
self.assertTrue(result["Location"].endswith(f"/accounts/new/send_confirm/{email}"))
result = self.client_get(result["Location"])
self.assert_in_response("Check your email so we can get started.", result)
# Visit the confirmation link.
confirmation_url = self.get_confirmation_url_from_outbox(email)
result = self.client_get(confirmation_url)
self.assertEqual(result.status_code, 200)
# Simulate the initial POST that is made by confirm-preregistration.js
# by triggering submit on confirm_preregistration.html.
payload = {
"full_name": "",
"key": find_key_by_email(email),
"from_confirmation": "1",
}
result = self.client_post("/accounts/register/", payload)
# Assert that the form did not prompt the user for enabling
# marketing emails.
self.assert_not_in_success_response(['input id="id_enable_marketing_emails"'], result)
result = self.submit_reg_form_for_user(
email,
password,
realm_subdomain=string_id,
realm_name=realm_name,
)
self.assertEqual(result.status_code, 302)
result = self.client_get(result.url, subdomain=string_id)
self.assertEqual(result.status_code, 302)
self.assertEqual(result.url, "http://zuliptest.testserver")
# Make sure the realm is created
realm = get_realm(string_id)
self.assertEqual(realm.string_id, string_id)
user = get_user(email, realm)
self.assertEqual(user.realm, realm)
self.assertFalse(user.enable_marketing_emails)
@override_settings(OPEN_REALM_CREATION=True)
def test_create_realm_with_marketing_emails_disabled(self) -> None:
password = "test"

View File

@ -511,6 +511,7 @@ def accounts_register(
"MAX_NAME_LENGTH": str(UserProfile.MAX_NAME_LENGTH),
"MAX_PASSWORD_LENGTH": str(form.MAX_PASSWORD_LENGTH),
"MAX_REALM_SUBDOMAIN_LENGTH": str(Realm.MAX_REALM_SUBDOMAIN_LENGTH),
"corporate_enabled": settings.CORPORATE_ENABLED,
"sorted_realm_types": sorted(
Realm.ORG_TYPES.values(), key=lambda d: d["display_order"]
),