mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
FIX: send a PM to moderators when a post has been flagged as sockpuppet
This commit is contained in:
parent
d0b83c6fb2
commit
2fcd199f48
4 changed files with 28 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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,15 +14,16 @@ 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
|
||||
!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
|
||||
|
||||
|
|
|
@ -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 <a href="/guidelines">our community guidelines</a>.'
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue