From 7eaedb84e1fd8a0d5695172037c3d732cfb65d4e Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 19 Aug 2013 12:00:48 -0400 Subject: [PATCH] Add notify_mods_when_user_blocked site setting to control whether moderators get a message when someone is automatically blocked --- app/models/site_setting.rb | 1 + app/services/spam_rules_enforcer.rb | 2 +- config/locales/server.en.yml | 2 +- spec/services/spam_rules_enforcer_spec.rb | 6 ++++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 9803d4fd6f4..bf560381f35 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -67,6 +67,7 @@ class SiteSetting < ActiveRecord::Base setting(:num_flags_to_block_new_user, 3) setting(:num_users_to_block_new_user, 3) + setting(:notify_mods_when_user_blocked, true) # used mainly for dev, force hostname for Discourse.base_url # You would usually use multisite for this diff --git a/app/services/spam_rules_enforcer.rb b/app/services/spam_rules_enforcer.rb index abc78bd5620..4762ab264da 100644 --- a/app/services/spam_rules_enforcer.rb +++ b/app/services/spam_rules_enforcer.rb @@ -48,7 +48,7 @@ class SpamRulesEnforcer def punish_user Post.transaction do - if UserBlocker.block(@user, nil, {message: :too_many_spam_flags}) + if UserBlocker.block(@user, nil, {message: :too_many_spam_flags}) and SiteSetting.notify_mods_when_user_blocked GroupMessage.create(Group[:moderators].name, :user_automatically_blocked, {user: @user, limit_once_per: false}) end end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 43b2fc42c16..62bfdfaa788 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -505,7 +505,7 @@ en: cooldown_minutes_after_hiding_posts: "Number of minutes a user must wait before they can edit a post hidden via flagging" num_flags_to_block_new_user: "If a new user's posts get this many spam flags from (n) different users, hide all their posts and prevent future posting. 0 disables this feature." num_users_to_block_new_user: "If a new user's posts get (x) spam flags from this many different users, hide all their posts and prevent future posting. 0 disables this feature." - + notify_mods_when_user_blocked: "If a user is automatically blocked, send a message to all moderators." traditional_markdown_linebreaks: "Use traditional linebreaks in Markdown, which require two trailing spaces for a linebreak" post_undo_action_window_mins: "Number of seconds users are allowed to reverse actions on a post (like, flag, etc)" diff --git a/spec/services/spam_rules_enforcer_spec.rb b/spec/services/spam_rules_enforcer_spec.rb index 92e373b129f..25f711ce3b0 100644 --- a/spec/services/spam_rules_enforcer_spec.rb +++ b/spec/services/spam_rules_enforcer_spec.rb @@ -128,6 +128,12 @@ describe SpamRulesEnforcer do end subject.punish_user end + + it "doesn't send a pm to moderators if notify_mods_when_user_blocked is false" do + SiteSetting.stubs(:notify_mods_when_user_blocked).returns(false) + GroupMessage.expects(:create).never + subject.punish_user + end end context 'user is already blocked' do