mirror of https://github.com/zulip/zulip.git
onboarding: Deduplicate realm creation initial user logic.
We now call this function inside do_create_user(..., realm_creation=True), which generally improves readability and robustness of the codebase. This fixes a bug where this onboarding content was not correctly done when creating a realm via LDAP, and also will be important as we add new code paths that might let you create a realm.
This commit is contained in:
parent
a117b224a7
commit
6b00c748fd
|
@ -753,6 +753,17 @@ def do_create_user(
|
|||
default_stream_groups=default_stream_groups,
|
||||
realm_creation=realm_creation,
|
||||
)
|
||||
|
||||
if realm_creation:
|
||||
assert realm.signup_notifications_stream is not None
|
||||
bulk_add_subscriptions(
|
||||
realm, [realm.signup_notifications_stream], [user_profile], acting_user=None
|
||||
)
|
||||
|
||||
from zerver.lib.onboarding import send_initial_realm_messages
|
||||
|
||||
send_initial_realm_messages(realm)
|
||||
|
||||
return user_profile
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ from zerver.forms import (
|
|||
RegistrationForm,
|
||||
)
|
||||
from zerver.lib.actions import (
|
||||
bulk_add_subscriptions,
|
||||
do_activate_mirror_dummy_user,
|
||||
do_change_full_name,
|
||||
do_change_password,
|
||||
|
@ -46,7 +45,6 @@ from zerver.lib.actions import (
|
|||
)
|
||||
from zerver.lib.email_validation import email_allowed_for_realm, validate_email_not_already_in_realm
|
||||
from zerver.lib.exceptions import RateLimited
|
||||
from zerver.lib.onboarding import send_initial_realm_messages
|
||||
from zerver.lib.pysa import mark_sanitized
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.send_email import EmailNotDeliveredException, FromAddress, send_email
|
||||
|
@ -456,12 +454,6 @@ def accounts_register(
|
|||
)
|
||||
|
||||
if realm_creation:
|
||||
assert realm.signup_notifications_stream is not None
|
||||
bulk_add_subscriptions(
|
||||
realm, [realm.signup_notifications_stream], [user_profile], acting_user=None
|
||||
)
|
||||
send_initial_realm_messages(realm)
|
||||
|
||||
# Because for realm creation, registration happens on the
|
||||
# root domain, we need to log them into the subdomain for
|
||||
# their new realm.
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
from typing import Any
|
||||
|
||||
from zerver.lib.actions import bulk_add_subscriptions, do_create_realm, do_create_user
|
||||
from zerver.lib.actions import do_create_realm, do_create_user
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
from zerver.lib.onboarding import send_initial_realm_messages
|
||||
from zerver.models import Realm, UserProfile
|
||||
|
||||
|
||||
|
@ -14,15 +13,12 @@ class Command(ZulipBaseCommand):
|
|||
realm = do_create_realm(string_id, string_id)
|
||||
|
||||
name = "{:02}-user".format(UserProfile.objects.filter(email__contains="user@").count())
|
||||
user = do_create_user(
|
||||
do_create_user(
|
||||
f"{name}@{string_id}.zulip.com",
|
||||
"password",
|
||||
realm,
|
||||
name,
|
||||
role=UserProfile.ROLE_REALM_ADMINISTRATOR,
|
||||
realm_creation=True,
|
||||
acting_user=None,
|
||||
)
|
||||
assert realm.signup_notifications_stream is not None
|
||||
bulk_add_subscriptions(realm, [realm.signup_notifications_stream], [user], acting_user=None)
|
||||
|
||||
send_initial_realm_messages(realm)
|
||||
|
|
Loading…
Reference in New Issue