diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 1f10c6f26f8..e0330cc93bf 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -197,7 +197,7 @@ class PostAction < ActiveRecord::Base def self.create_message_for_post_action(user, post, post_action_type_id, opts) post_action_type = PostActionType.types[post_action_type_id] - return unless opts[:message] && [:notify_moderators, :notify_user].include?(post_action_type) + return unless opts[:message] && [:notify_moderators, :notify_user, :spam].include?(post_action_type) title = I18n.t("post_action_types.#{post_action_type}.email_title", title: post.topic.title) body = I18n.t("post_action_types.#{post_action_type}.email_body", message: opts[:message], link: "#{Discourse.base_url}#{post.url}") @@ -210,7 +210,7 @@ class PostAction < ActiveRecord::Base raw: body } - if post_action_type == :notify_moderators + if [:notify_moderators, :spam].include?(post_action_type) opts[:subtype] = TopicSubtype.notify_moderators opts[:target_group_names] = "moderators" else diff --git a/app/services/spam_rule/flag_sockpuppets.rb b/app/services/spam_rule/flag_sockpuppets.rb index 813ab1d8b82..b6223df7211 100644 --- a/app/services/spam_rule/flag_sockpuppets.rb +++ b/app/services/spam_rule/flag_sockpuppets.rb @@ -5,7 +5,7 @@ class SpamRule::FlagSockpuppets end def perform - if SiteSetting.flag_sockpuppets and reply_is_from_sockpuppet? + if SiteSetting.flag_sockpuppets && reply_is_from_sockpuppet? flag_sockpuppet_users true else @@ -14,16 +14,17 @@ class SpamRule::FlagSockpuppets end def reply_is_from_sockpuppet? - return false if @post.post_number and @post.post_number == 1 + return false if @post.try(:post_number) == 1 first_post = @post.topic.posts.by_post_number.first return false if first_post.user.nil? - !first_post.user.staff? and !@post.user.staff? and - @post.user != first_post.user and - @post.user.ip_address == first_post.user.ip_address and - @post.user.new_user? and - !ScreenedIpAddress.is_whitelisted?(@post.user.ip_address) + !first_post.user.staff? && + !@post.user.staff? && + @post.user != first_post.user && + @post.user.ip_address == first_post.user.ip_address && + @post.user.new_user? && + !ScreenedIpAddress.is_whitelisted?(@post.user.ip_address) end def flag_sockpuppet_users @@ -34,4 +35,4 @@ class SpamRule::FlagSockpuppets end end -end \ No newline at end of file +end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 4b8c47df021..0294b309f68 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -441,6 +441,8 @@ en: title: 'Spam' description: 'This post is an advertisement. It is not useful or relevant to the current topic, but promotional in nature.' long_form: 'flagged this as spam' + email_title: '"%{title}" was flagged as spam' + email_body: "%{link}\n\n%{message}" inappropriate: title: 'Inappropriate' description: 'This post contains content that a reasonable person would consider offensive, abusive, or a violation of our community guidelines.' diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index b9d7b2fc869..b6fb5e83616 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -443,4 +443,19 @@ describe PostAction do end end + describe "#create_message_for_post_action" do + it "does not create a message when there is no message" do + message_id = PostAction.create_message_for_post_action(Discourse.system_user, post, PostActionType.types[:spam], {}) + expect(message_id).to be_nil + end + + [:notify_moderators, :notify_user, :spam].each do |post_action_type| + it "creates a message for #{post_action_type}" do + message_id = PostAction.create_message_for_post_action(Discourse.system_user, post, PostActionType.types[post_action_type], message: "WAT") + expect(message_id).to be_present + end + end + + end + end