settings: Set enable_marketing_emails after copying user settings.

We set the enable_marketing_emails setting after copying user
settings to override the value selected in registration form.
This change is also necessary because enable_marketing_emails
field is present in RealmUserDefault to avoid copying code
but we do not use this value actually and instead we want
the setting to be set according to the value in registration
form.

We set this setting only for non-bot users since we generally
do not set any settings for bots.
This commit is contained in:
Sahil Batra
2021-09-03 21:45:40 +05:30
committed by Tim Abbott
parent 2eec0772fb
commit 03a0cfda64
3 changed files with 6 additions and 3 deletions

View File

@@ -142,7 +142,6 @@ def create_user(
user_profile.timezone = timezone
user_profile.default_sending_stream = default_sending_stream
user_profile.default_events_register_stream = default_events_register_stream
user_profile.enable_marketing_emails = enable_marketing_emails
if role is not None:
user_profile.role = role
# Allow the ORM default to be used if not provided
@@ -161,6 +160,10 @@ def create_user(
else:
user_profile.save()
if bot_type is None:
user_profile.enable_marketing_emails = enable_marketing_emails
user_profile.save(update_fields=["enable_marketing_emails"])
if not user_profile.email_address_is_realm_public():
# With restricted access to email addresses, we can't generate
# the fake email addresses we use for display purposes without