mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 11:43:56 +08:00
FIX: send a PM to moderators when a post has been flagged as sockpuppet
This commit is contained in:
parent
d0b83c6fb2
commit
2fcd199f48
|
@ -197,7 +197,7 @@ class PostAction < ActiveRecord::Base
|
||||||
def self.create_message_for_post_action(user, post, post_action_type_id, opts)
|
def self.create_message_for_post_action(user, post, post_action_type_id, opts)
|
||||||
post_action_type = PostActionType.types[post_action_type_id]
|
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)
|
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}")
|
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
|
raw: body
|
||||||
}
|
}
|
||||||
|
|
||||||
if post_action_type == :notify_moderators
|
if [:notify_moderators, :spam].include?(post_action_type)
|
||||||
opts[:subtype] = TopicSubtype.notify_moderators
|
opts[:subtype] = TopicSubtype.notify_moderators
|
||||||
opts[:target_group_names] = "moderators"
|
opts[:target_group_names] = "moderators"
|
||||||
else
|
else
|
||||||
|
|
|
@ -5,7 +5,7 @@ class SpamRule::FlagSockpuppets
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
if SiteSetting.flag_sockpuppets and reply_is_from_sockpuppet?
|
if SiteSetting.flag_sockpuppets && reply_is_from_sockpuppet?
|
||||||
flag_sockpuppet_users
|
flag_sockpuppet_users
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
@ -14,15 +14,16 @@ class SpamRule::FlagSockpuppets
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply_is_from_sockpuppet?
|
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
|
first_post = @post.topic.posts.by_post_number.first
|
||||||
return false if first_post.user.nil?
|
return false if first_post.user.nil?
|
||||||
|
|
||||||
!first_post.user.staff? and !@post.user.staff? and
|
!first_post.user.staff? &&
|
||||||
@post.user != first_post.user and
|
!@post.user.staff? &&
|
||||||
@post.user.ip_address == first_post.user.ip_address and
|
@post.user != first_post.user &&
|
||||||
@post.user.new_user? and
|
@post.user.ip_address == first_post.user.ip_address &&
|
||||||
|
@post.user.new_user? &&
|
||||||
!ScreenedIpAddress.is_whitelisted?(@post.user.ip_address)
|
!ScreenedIpAddress.is_whitelisted?(@post.user.ip_address)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -441,6 +441,8 @@ en:
|
||||||
title: 'Spam'
|
title: 'Spam'
|
||||||
description: 'This post is an advertisement. It is not useful or relevant to the current topic, but promotional in nature.'
|
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'
|
long_form: 'flagged this as spam'
|
||||||
|
email_title: '"%{title}" was flagged as spam'
|
||||||
|
email_body: "%{link}\n\n%{message}"
|
||||||
inappropriate:
|
inappropriate:
|
||||||
title: '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>.'
|
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
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user