create-realm: Update notification message sent to admin realm.

When a new realm is created, a notification message is sent to
the realm configured as the settings.SYSTEM_BOT_REALM if there
is a "signups" stream that exists in that realm. This is used
for Zulip Cloud, but is an undocumented feature.

The topic of the message has been the subdomain of the new realm,
and the message content has been "Signups enabled" translated
into the default language of the new realm.

In order to make these messages more explicitly for Zulip Cloud,
the settings.CORPORATE_ENABLED is checked before sending these
messages.

To make these messages more useful, the topic for these
notifications is changed to be "new organizations". The content
of these messages is updated to have the new realm name (with a
link to the admin realm's activity support page for the realm),
subdomain (with a link to the realm), and organization type.
This commit is contained in:
Lauryn Menard
2023-03-10 16:03:18 +01:00
committed by Tim Abbott
parent 36475daba7
commit ffcdc13819
2 changed files with 41 additions and 21 deletions

View File

@@ -1251,6 +1251,7 @@ class RealmCreationTest(ZulipTestCase):
signups_stream, _ = create_stream_if_needed(notification_bot.realm, "signups")
string_id = "zuliptest"
org_name = "Zulip Test"
# Make sure the realm does not exist
with self.assertRaises(Realm.DoesNotExist):
get_realm(string_id)
@@ -1276,7 +1277,9 @@ class RealmCreationTest(ZulipTestCase):
result = self.client_get(confirmation_url)
self.assertEqual(result.status_code, 200)
result = self.submit_reg_form_for_user(email, password, realm_subdomain=string_id)
result = self.submit_reg_form_for_user(
email, password, realm_subdomain=string_id, realm_name=org_name
)
self.assertEqual(result.status_code, 302)
self.assertTrue(
result["Location"].startswith("http://zuliptest.testserver/accounts/login/subdomain/")
@@ -1307,12 +1310,15 @@ class RealmCreationTest(ZulipTestCase):
self.assert_length(messages, message_count)
self.assertIn(text, messages[0].content)
# Check signup messages
# Check admin organization's signups stream messages
recipient = signups_stream.recipient
messages = Message.objects.filter(recipient=recipient).order_by("id")
self.assert_length(messages, 1)
self.assertIn("Signups enabled", messages[0].content)
self.assertEqual("zuliptest", messages[0].topic_name())
# Check organization name, subdomain and organization type are in message content
self.assertIn("Zulip Test", messages[0].content)
self.assertIn("zuliptest", messages[0].content)
self.assertIn("Organization type: Business", messages[0].content)
self.assertEqual("new organizations", messages[0].topic_name())
realm_creation_audit_log = RealmAuditLog.objects.get(
realm=realm, event_type=RealmAuditLog.REALM_CREATED