discourse/app/services/spam_rule/flag_sockpuppets.rb
Robin Ward bc3efab816 FIX: When disagreeing with a flag that silenced a user, unsilence them
Previously it would unhide their post but leave them silenced.

This fix also cleans up some of the helper classes to make it easier
to pass extra data to the silencing code (for example, a link to the
post that caused the user to be silenced.)

This patch also refactors the auto_silence specs to avoid using
stubs.
2019-02-08 08:50:50 -05:00

44 lines
1.3 KiB
Ruby

class SpamRule::FlagSockpuppets
def initialize(post)
@post = post
end
def perform
I18n.with_locale(SiteSetting.default_locale) do
if SiteSetting.flag_sockpuppets && reply_is_from_sockpuppet?
flag_sockpuppet_users
true
else
false
end
end
end
def reply_is_from_sockpuppet?
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? &&
!@post.user.staff? &&
!first_post.user.staged? &&
!@post.user.staged? &&
@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
message = I18n.t('flag_reason.sockpuppet', ip_address: @post.user.ip_address, base_path: Discourse.base_path)
PostAction.act(Discourse.system_user, @post, PostActionType.types[:spam], message: message) rescue PostAction::AlreadyActed
if (first_post = @post.topic.posts.by_post_number.first).try(:user).try(:new_user?)
PostAction.act(Discourse.system_user, first_post, PostActionType.types[:spam], message: message) rescue PostAction::AlreadyActed
end
end
end