mirror of https://github.com/zulip/zulip.git
bulk_create: Copy realm-level defaults in bulk_create_users.
This commit adds code to copy the realm-level default of
settings while creating users through bulk_create_users.
We do not directly call 'copy_default_settings' as it
calls ".save()" but here we want to bulk_create the objects
for efficiency.
We also add the code to set realm-default of enter_sends as
True for the Zulip dev server as done in 754b547e8
and thus
we remove enter_sends argument from create_user_profile as
it is of no use now.
This commit is contained in:
parent
8ff0cec2ed
commit
aa98b39429
|
@ -5,7 +5,15 @@ from django.db.models import Model
|
|||
from zerver.lib.create_user import create_user_profile, get_display_email_address
|
||||
from zerver.lib.initial_password import initial_password
|
||||
from zerver.lib.streams import render_stream_description
|
||||
from zerver.models import Realm, RealmAuditLog, Recipient, Stream, Subscription, UserProfile
|
||||
from zerver.models import (
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
RealmUserDefault,
|
||||
Recipient,
|
||||
Stream,
|
||||
Subscription,
|
||||
UserProfile,
|
||||
)
|
||||
|
||||
|
||||
def bulk_create_users(
|
||||
|
@ -24,6 +32,7 @@ def bulk_create_users(
|
|||
UserProfile.objects.filter(realm=realm).values_list("email", flat=True)
|
||||
)
|
||||
users = sorted(user_raw for user_raw in users_raw if user_raw[0] not in existing_users)
|
||||
realm_user_default = RealmUserDefault.objects.get(realm=realm)
|
||||
|
||||
# Now create user_profiles
|
||||
profiles_to_create: List[UserProfile] = []
|
||||
|
@ -40,8 +49,20 @@ def bulk_create_users(
|
|||
tos_version,
|
||||
timezone,
|
||||
tutorial_status=UserProfile.TUTORIAL_FINISHED,
|
||||
enter_sends=True,
|
||||
)
|
||||
|
||||
if bot_type is None:
|
||||
# This block simulates copy_default_settings from
|
||||
# zerver/lib/create_user.py.
|
||||
#
|
||||
# We cannot use 'copy_default_settings' directly here
|
||||
# because it calls '.save' after copying the settings, and
|
||||
# we are bulk creating the objects here instead.
|
||||
for settings_name in RealmUserDefault.property_types:
|
||||
if settings_name in ["default_language", "enable_login_emails"]:
|
||||
continue
|
||||
value = getattr(realm_user_default, settings_name)
|
||||
setattr(profile, settings_name, value)
|
||||
profiles_to_create.append(profile)
|
||||
|
||||
if realm.email_address_visibility == Realm.EMAIL_ADDRESS_VISIBILITY_EVERYONE:
|
||||
|
|
|
@ -86,7 +86,6 @@ def create_user_profile(
|
|||
timezone: Optional[str],
|
||||
default_language: str = "en",
|
||||
tutorial_status: str = UserProfile.TUTORIAL_WAITING,
|
||||
enter_sends: bool = False,
|
||||
force_id: Optional[int] = None,
|
||||
force_date_joined: Optional[datetime] = None,
|
||||
) -> UserProfile:
|
||||
|
@ -115,7 +114,6 @@ def create_user_profile(
|
|||
tos_version=tos_version,
|
||||
timezone=timezone,
|
||||
tutorial_status=tutorial_status,
|
||||
enter_sends=enter_sends,
|
||||
onboarding_steps=orjson.dumps([]).decode(),
|
||||
default_language=default_language,
|
||||
delivery_email=email,
|
||||
|
|
|
@ -50,6 +50,7 @@ from zerver.models import (
|
|||
Realm,
|
||||
RealmAuditLog,
|
||||
RealmDomain,
|
||||
RealmUserDefault,
|
||||
Recipient,
|
||||
Service,
|
||||
Stream,
|
||||
|
@ -329,6 +330,10 @@ class Command(BaseCommand):
|
|||
zulip_realm.notifications_stream.description = "A city in Italy"
|
||||
zulip_realm.notifications_stream.save(update_fields=["name", "description"])
|
||||
|
||||
realm_user_default = RealmUserDefault.objects.get(realm=zulip_realm)
|
||||
realm_user_default.enter_sends = True
|
||||
realm_user_default.save()
|
||||
|
||||
if options["test_suite"]:
|
||||
mit_realm = do_create_realm(
|
||||
string_id="zephyr",
|
||||
|
|
Loading…
Reference in New Issue