From 54b4fb69db1140f0ae925078ab05bd1d690743fc Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Sat, 5 Mar 2016 10:53:28 +1300 Subject: [PATCH 1/2] FEATURE: Add site setting for disabling mailing list mode site wide --- .../discourse/templates/user/preferences.hbs | 4 +++- app/models/user_option.rb | 5 +++++ config/locales/server.en.yml | 1 + config/site_settings.yml | 3 +++ spec/models/user_option_spec.rb | 22 +++++++++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/templates/user/preferences.hbs b/app/assets/javascripts/discourse/templates/user/preferences.hbs index b2fd4443d7e..eb80ccd418c 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.hbs +++ b/app/assets/javascripts/discourse/templates/user/preferences.hbs @@ -183,7 +183,9 @@ {{preference-checkbox labelKey="user.email_in_reply_to" checked=model.user_option.email_in_reply_to}} {{preference-checkbox labelKey="user.email_private_messages" checked=model.user_option.email_private_messages}} {{preference-checkbox labelKey="user.email_direct" checked=model.user_option.email_direct}} - {{preference-checkbox labelKey="user.mailing_list_mode" checked=model.user_option.mailing_list_mode}} + {{#unless siteSettings.disable_mailing_list_mode}} + {{preference-checkbox labelKey="user.mailing_list_mode" checked=model.user_option.mailing_list_mode}} + {{/unless}} {{preference-checkbox labelKey="user.email_always" checked=model.user_option.email_always}} {{#unless model.user_option.email_always}}
diff --git a/app/models/user_option.rb b/app/models/user_option.rb index 25ecee9aa60..3a2a0e53641 100644 --- a/app/models/user_option.rb +++ b/app/models/user_option.rb @@ -44,6 +44,11 @@ class UserOption < ActiveRecord::Base true end + def mailing_list_mode + return false if SiteSetting.disable_mailing_list_mode + super + end + def update_tracked_topics return unless auto_track_topics_after_msecs_changed? TrackedTopicsUpdater.new(id, auto_track_topics_after_msecs).call diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 490a94ff9b7..2cd7f6e473a 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1248,6 +1248,7 @@ en: default_email_private_messages: "Send an email when someone messages the user by default." default_email_direct: "Send an email when someone quotes/replies to/mentions or invites the user by default." default_email_mailing_list_mode: "Send an email for every new post by default." + disable_mailing_list_mode: "Disable sending an email for every new post for all users" default_email_always: "Send an email notification even when the user is active by default." default_email_previous_replies: "Include previous replies in emails by default." diff --git a/config/site_settings.yml b/config/site_settings.yml index 765e6e7484e..92ae7071354 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1074,6 +1074,9 @@ user_preferences: default_email_private_messages: true default_email_direct: true default_email_mailing_list_mode: false + disable_mailing_list_mode: + default: false + client: true default_email_always: false default_email_previous_replies: enum: 'PreviousRepliesSiteSetting' diff --git a/spec/models/user_option_spec.rb b/spec/models/user_option_spec.rb index e3144989add..b388cd8d68b 100644 --- a/spec/models/user_option_spec.rb +++ b/spec/models/user_option_spec.rb @@ -18,6 +18,28 @@ describe UserOption do end + describe ".mailing_list_mode" do + let!(:forum_user) { Fabricate(:user) } + let!(:mailing_list_user) { Fabricate(:user) } + + before do + forum_user.user_option.update(mailing_list_mode: false) + mailing_list_user.user_option.update(mailing_list_mode: true) + end + + it "should return false when `SiteSetting.disable_mailing_list_mode` is enabled" do + SiteSetting.expects(:disable_mailing_list_mode).twice.returns(true) + expect(forum_user.user_option.mailing_list_mode).to eq(false) + expect(mailing_list_user.user_option.mailing_list_mode).to eq(false) + end + + it "should return the stored value when `SiteSetting.disable_mailing_list_mode` is disabled" do + SiteSetting.expects(:disable_mailing_list_mode).twice.returns(false) + expect(forum_user.user_option.mailing_list_mode).to eq(false) + expect(mailing_list_user.user_option.mailing_list_mode).to eq(true) + end + end + describe ".redirected_to_top" do let!(:user) { Fabricate(:user) } From 2f00e2179f1d6157ef6c71a42c3e087899107a87 Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Tue, 8 Mar 2016 09:25:14 +1300 Subject: [PATCH 2/2] Don't use unnecessary stubs; site setting language update --- config/locales/server.en.yml | 2 +- spec/models/user_option_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 2cd7f6e473a..1cf86ceafcb 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1248,7 +1248,7 @@ en: default_email_private_messages: "Send an email when someone messages the user by default." default_email_direct: "Send an email when someone quotes/replies to/mentions or invites the user by default." default_email_mailing_list_mode: "Send an email for every new post by default." - disable_mailing_list_mode: "Disable sending an email for every new post for all users" + disable_mailing_list_mode: "Disallow users from enabling mailing list mode." default_email_always: "Send an email notification even when the user is active by default." default_email_previous_replies: "Include previous replies in emails by default." diff --git a/spec/models/user_option_spec.rb b/spec/models/user_option_spec.rb index b388cd8d68b..50cfd6623d8 100644 --- a/spec/models/user_option_spec.rb +++ b/spec/models/user_option_spec.rb @@ -18,7 +18,7 @@ describe UserOption do end - describe ".mailing_list_mode" do + describe "#mailing_list_mode" do let!(:forum_user) { Fabricate(:user) } let!(:mailing_list_user) { Fabricate(:user) } @@ -28,13 +28,13 @@ describe UserOption do end it "should return false when `SiteSetting.disable_mailing_list_mode` is enabled" do - SiteSetting.expects(:disable_mailing_list_mode).twice.returns(true) + SiteSetting.disable_mailing_list_mode = true expect(forum_user.user_option.mailing_list_mode).to eq(false) expect(mailing_list_user.user_option.mailing_list_mode).to eq(false) end it "should return the stored value when `SiteSetting.disable_mailing_list_mode` is disabled" do - SiteSetting.expects(:disable_mailing_list_mode).twice.returns(false) + SiteSetting.disable_mailing_list_mode = false expect(forum_user.user_option.mailing_list_mode).to eq(false) expect(mailing_list_user.user_option.mailing_list_mode).to eq(true) end