Repository: zulip/zulip

Issue:
Self-hosted installation incorrectly prompts to “Subscribe me to Zulip's low-traffic newsletter”
The checkbox added by #19573 (tweaked by 191b1ac2be46fe4219c170ab318aa10c714cb49a) for “Subscribe me to Zulip's low-traffic newsletter (a few emails a year)” should not show up on self-hosted installations, where it doesn’t in fact subscribe you to anything. It should be conditional on `settings.CORPORATE_ENABLED`.

Cc @eeshangarg


Discussion:
Hello @zulip/server-misc members, this issue was labeled with the "area: portico" label, so you may want to check it out!

<!-- areaLabelAddition -->

@zulipbot claim
Hello @Biki-das!

Thanks for your interest in Zulip! You have attempted to claim an issue without the labels "help wanted", "good first issue". Since you're a new contributor, you can only claim and submit pull requests for issues with the [help wanted](https://github.com/zulip/zulip/issues?q=is%3Aopen+is%3Aissue+no%3Aassignee+label%3A%22help+wanted%22) or [good first issue](https://github.com/zulip/zulip/issues?q=is%3Aopen+is%3Aissue+no%3Aassignee+label%3A%22good+first+issue%22) labels.

If this is your first time here, we recommend reading our [guide for new contributors](https://zulip.readthedocs.io/en/latest/overview/contributing.html) before getting started.


Resolving patch:
diff --git a/zerver/views/registration.py b/zerver/views/registration.py
--- a/zerver/views/registration.py
+++ b/zerver/views/registration.py
@@ -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"]
             ),


Test patch:
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -653,7 +653,7 @@ def submit_reg_form_for_user(
         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 @@ def submit_reg_form_for_user(
             "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:
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -3232,6 +3232,60 @@ def test_create_realm_with_marketing_emails_enabled(self) -> None:
         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"