diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index 0361ccf4d54..524d97db1fb 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -70,14 +70,13 @@ class UserUpdater TagUser.batch_set(user, level, attributes[attribute]) end - save_options = false OPTION_ATTR.each do |attribute| if attributes.key?(attribute) save_options = true - if [true,false].include?(user.user_option.send(attribute)) + if [true, false].include?(user.user_option.send(attribute)) val = attributes[attribute].to_s == 'true' user.user_option.send("#{attribute}=", val) else @@ -86,6 +85,9 @@ class UserUpdater end end + # automatically disable digests when mailing_list_mode is enabled + user.user_option.email_digests = false if user.user_option.mailing_list_mode + fields = attributes[:custom_fields] if fields.present? user.custom_fields = user.custom_fields.merge(fields) diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rb index aa5f6f5734b..0a1b538ab4a 100644 --- a/spec/services/user_updater_spec.rb +++ b/spec/services/user_updater_spec.rb @@ -91,6 +91,19 @@ describe UserUpdater do expect(user.date_of_birth).to eq(date_of_birth.to_date) end + it "disables email_digests when enabling mailing_list_mode" do + user = Fabricate(:user) + updater = UserUpdater.new(acting_user, user) + + val = updater.update(mailing_list_mode: true, email_digests: true) + expect(val).to be_truthy + + user.reload + + expect(user.user_option.email_digests).to eq false + expect(user.user_option.mailing_list_mode).to eq true + end + context 'when sso overrides bio' do it 'does not change bio' do SiteSetting.enable_sso = true