Class: SpamRule::FlagSockpuppets

Inherits:
Object
  • Object
show all
Defined in:
app/services/spam_rule/flag_sockpuppets.rb

Instance Method Summary collapse

Constructor Details

#initialize(post) ⇒ FlagSockpuppets

Returns a new instance of FlagSockpuppets.



4
5
6
# File 'app/services/spam_rule/flag_sockpuppets.rb', line 4

def initialize(post)
  @post = post
end

Instance Method Details

#flag_sockpuppet_usersObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/spam_rule/flag_sockpuppets.rb', line 29

def flag_sockpuppet_users
  message =
    I18n.t(
      "flag_reason.sockpuppet",
      ip_address: @post.user.ip_address,
      base_path: Discourse.base_path,
      locale: SiteSetting.default_locale,
    )

  flag_post(@post, message)

  flag_post(first_post, message) if first_post&.user&.new_user?
end

#performObject



8
9
10
11
12
13
14
15
16
17
# File 'app/services/spam_rule/flag_sockpuppets.rb', line 8

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

#reply_is_from_sockpuppet?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'app/services/spam_rule/flag_sockpuppets.rb', line 19

def reply_is_from_sockpuppet?
  return false if @post.try(:post_number) == 1
  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_allowed?(@post.user.ip_address)
end