Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
create-realm: Update notification message sent to admin realm.
Lauryn Menardffcdc13819e9
diff --git a/zerver/actions/create_realm.py b/zerver/actions/create_realm.pyindex f8baebfc6cb..c67c3e73718 100644--- a/zerver/actions/create_realm.py+++ b/zerver/actions/create_realm.py@@ -5,7 +5,6 @@ from typing import Any, Dict, Optionalfrom django.conf import settingsfrom django.db import transactionfrom django.utils.timezone import now as timezone_now-from django.utils.translation import gettext as _from zerver.actions.message_send import internal_send_stream_messagefrom zerver.actions.realm_settings import (@@ -24,10 +23,14 @@ from zerver.models import (RealmUserDefault,Stream,UserProfile,+ get_org_type_display_name,get_realm,get_system_bot,)+if settings.CORPORATE_ENABLED:+ from corporate.lib.support import get_support_url+def do_change_realm_subdomain(realm: Realm,@@ -254,25 +257,36 @@ def do_create_realm(# We use acting_user=None for setting the initial plan type.do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)- admin_realm = get_realm(settings.SYSTEM_BOT_REALM)- sender = get_system_bot(settings.NOTIFICATION_BOT, admin_realm.id)- # Send a notification to the admin realm- signup_message = _("Signups enabled")+ # Send a notification to the admin realm when a new organization registers.+ if settings.CORPORATE_ENABLED:+ admin_realm = get_realm(settings.SYSTEM_BOT_REALM)+ sender = get_system_bot(settings.NOTIFICATION_BOT, admin_realm.id)- try:- signups_stream = get_signups_stream(admin_realm)- topic = realm.display_subdomain+ support_url = get_support_url(realm)+ organization_type = get_org_type_display_name(realm.org_type)- internal_send_stream_message(- sender,- signups_stream,- topic,- signup_message,+ message = "[{name}]({support_link}) ([{subdomain}]({realm_link})). Organization type: {type}".format(+ name=realm.name,+ subdomain=realm.display_subdomain,+ realm_link=realm.uri,+ support_link=support_url,+ type=organization_type,)- except Stream.DoesNotExist: # nocoverage- # If the signups stream hasn't been created in the admin- # realm, don't auto-create it to send to it; just do nothing.- pass+ topic = "new organizations"++ try:+ signups_stream = get_signups_stream(admin_realm)++ internal_send_stream_message(+ sender,+ signups_stream,+ topic,+ message,+ )+ except Stream.DoesNotExist: # nocoverage+ # If the signups stream hasn't been created in the admin+ # realm, don't auto-create it to send to it; just do nothing.+ passsetup_realm_internal_bots(realm)return realmdiff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 3ff63cf1c71..e86891d3e04 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -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 existwith 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 messagesrecipient = signups_stream.recipientmessages = 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