Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
onboarding: Refactor setup_realm_internal_bots call.
Tim Abbotta117b224a7c1
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex f98ddf982e6..c84d962881e 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -5593,6 +5593,27 @@ def set_realm_permissions_based_on_org_type(realm: Realm) -> None:realm.move_messages_between_streams_policy = Realm.POLICY_MODERATORS_ONLY+def setup_realm_internal_bots(realm: Realm) -> None:+ """Create this realm's internal bots.++ This function is idempotent; it does nothing for a bot that+ already exists.+ """+ internal_bots = [+ (bot["name"], bot["email_template"] % (settings.INTERNAL_BOT_DOMAIN,))+ for bot in settings.REALM_INTERNAL_BOTS+ ]+ create_users(realm, internal_bots, bot_type=UserProfile.DEFAULT_BOT)+ bots = UserProfile.objects.filter(+ realm=realm,+ email__in=[bot_info[1] for bot_info in internal_bots],+ bot_owner__isnull=True,+ )+ for bot in bots:+ bot.bot_owner = bot+ bot.save()++def do_create_realm(string_id: str,name: str,@@ -5701,6 +5722,8 @@ def do_create_realm(# 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++ setup_realm_internal_bots(realm)return realmdiff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.pyindex 12b3d9fff09..aa05cc2f83f 100644--- a/zerver/lib/onboarding.py+++ b/zerver/lib/onboarding.py@@ -6,11 +6,11 @@ from django.db.models import Countfrom django.utils.translation import gettext as _from zerver.lib.actions import (- create_users,do_add_reaction,do_send_messages,internal_prep_stream_message_by_name,internal_send_private_message,+ setup_realm_internal_bots,)from zerver.lib.emoji import emoji_name_to_emoji_codefrom zerver.lib.message import SendMessageRequest@@ -29,27 +29,6 @@ def missing_any_realm_internal_bots() -> bool:return any(bot_counts.get(email, 0) < realm_count for email in bot_emails)-def setup_realm_internal_bots(realm: Realm) -> None:- """Create this realm's internal bots.-- This function is idempotent; it does nothing for a bot that- already exists.- """- internal_bots = [- (bot["name"], bot["email_template"] % (settings.INTERNAL_BOT_DOMAIN,))- for bot in settings.REALM_INTERNAL_BOTS- ]- create_users(realm, internal_bots, bot_type=UserProfile.DEFAULT_BOT)- bots = UserProfile.objects.filter(- realm=realm,- email__in=[bot_info[1] for bot_info in internal_bots],- bot_owner__isnull=True,- )- for bot in bots:- bot.bot_owner = bot- bot.save()--def create_if_missing_realm_internal_bots() -> None:"""This checks if there is any realm internal bot missing.diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 102eeb252bb..10e5a305ff4 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -46,7 +46,7 @@ from zerver.lib.actions import ()from zerver.lib.email_validation import email_allowed_for_realm, validate_email_not_already_in_realmfrom zerver.lib.exceptions import RateLimited-from zerver.lib.onboarding import send_initial_realm_messages, setup_realm_internal_bots+from zerver.lib.onboarding import send_initial_realm_messagesfrom zerver.lib.pysa import mark_sanitizedfrom zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.send_email import EmailNotDeliveredException, FromAddress, send_email@@ -343,7 +343,6 @@ def accounts_register(realm = do_create_realm(string_id, realm_name, org_type=realm_type, is_demo_organization=is_demo_org)- setup_realm_internal_bots(realm)assert realm is not Nonefull_name = form.cleaned_data["full_name"]