diff --git a/zerver/lib/bulk_create.py b/zerver/lib/bulk_create.py index f6dbced416..b214146223 100644 --- a/zerver/lib/bulk_create.py +++ b/zerver/lib/bulk_create.py @@ -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: diff --git a/zerver/lib/create_user.py b/zerver/lib/create_user.py index 4beea78cd7..bc66512228 100644 --- a/zerver/lib/create_user.py +++ b/zerver/lib/create_user.py @@ -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, diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 3ddfaddd92..b427ac92c3 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -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",