Class: Decidim::SpamSignal::Cops::CopHandler
- Inherits:
-
ApplicationHandler
- Object
- Rectify::Command
- Decidim::SpamSignal::Command
- ApplicationHandler
- Decidim::SpamSignal::Cops::CopHandler
- Defined in:
- app/commands/decidim/spam_signal/cops/cop_handler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#admin_reporter ⇒ Object
readonly
Returns the value of attribute admin_reporter.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#current_organization ⇒ Object
readonly
Returns the value of attribute current_organization.
-
#error_key ⇒ Object
readonly
Returns the value of attribute error_key.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#justification ⇒ Object
readonly
Returns the value of attribute justification.
-
#reportable ⇒ Object
readonly
Returns the value of attribute reportable.
-
#suspicious_user ⇒ Object
readonly
Returns the value of attribute suspicious_user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(errors:, error_key: :base, suspicious_user:, config:, reportable: nil, justification: nil, admin_reporter: nil) ⇒ CopHandler
constructor
A new instance of CopHandler.
- #now_tag ⇒ Object
- #sinalize!(send_emails = true) ⇒ Object
Methods inherited from ApplicationHandler
form, handler_name, #handler_name
Constructor Details
#initialize(errors:, error_key: :base, suspicious_user:, config:, reportable: nil, justification: nil, admin_reporter: nil) ⇒ CopHandler
Returns a new instance of CopHandler.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 9 def initialize( errors:, error_key: :base, suspicious_user:, config:, reportable: nil, justification: nil, admin_reporter: nil ) @errors = errors @error_key = error_key @reportable = reportable || suspicious_user @suspicious_user = suspicious_user @current_organization = suspicious_user.organization @config = config @justification = justification @admin_reporter = admin_reporter || CopBot.get(suspicious_user.organization) end |
Instance Attribute Details
#admin_reporter ⇒ Object (readonly)
Returns the value of attribute admin_reporter.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def admin_reporter @admin_reporter end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def config @config end |
#current_organization ⇒ Object (readonly)
Returns the value of attribute current_organization.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def current_organization @current_organization end |
#error_key ⇒ Object (readonly)
Returns the value of attribute error_key.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def error_key @error_key end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def errors @errors end |
#justification ⇒ Object (readonly)
Returns the value of attribute justification.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def justification @justification end |
#reportable ⇒ Object (readonly)
Returns the value of attribute reportable.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def reportable @reportable end |
#suspicious_user ⇒ Object (readonly)
Returns the value of attribute suspicious_user.
7 8 9 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 7 def suspicious_user @suspicious_user end |
Class Method Details
.i18n_key ⇒ Object
29 30 31 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 29 def self.i18n_key "decidim.spam_signal.cops.#{handler_name}" end |
Instance Method Details
#now_tag ⇒ Object
32 33 34 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 32 def now_tag "\n[#{DateTime.now.strftime("%d/%m/%Y %H:%M")}]" end |
#sinalize!(send_emails = true) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/commands/decidim/spam_signal/cops/cop_handler.rb', line 35 def sinalize!(send_emails=true) is_user_reported = reportable == suspicious_user if is_user_reported moderation = Decidim::UserModeration.find_or_create_by!(user: suspicious_user) do |moderation| moderation.report_count = 0 end else moderation = Decidim::Moderation.find_or_create_by!(reportable: reportable, participatory_space: reportable.participatory_space) do |moderation| moderation.report_count = 0 end end is_new = moderation.report_count == 0 moderation.update(report_count: moderation.report_count + 1) if is_user_reported user_report = Decidim::UserReport.find_or_create_by!(moderation: moderation) do |report| report.moderation = moderation report.user = admin_reporter report.reason = "spam" report.details = "#{now_tag}#{justification}" end else user_report = Decidim::Report.find_or_create_by!(moderation: moderation) do |report| report.moderation = moderation report.user = admin_reporter report.reason = "spam" report.details = "#{now_tag}#{justification}" end end # append the new bad things (to have a log). user_report.update(details: "#{user_report.details}#{now_tag} #{justification}") unless is_new admin_accountable = Decidim::User.where(admin: true, email: ENV.fetch("ANTISPAM_ADMIN", "[email protected]")).first Decidim::UserReportJob.perform_later(admin, admin_reporter, "spam", reportable) end |