Class: RailsImagePostSolution::ImageReport

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/rails_image_post_solution/image_report.rb

Constant Summary collapse

STATUSES =

Status constants

{
  pending: "pending",         # Not reviewed yet
  reviewed: "reviewed",       # Reviewed (no action needed)
  confirmed: "confirmed",     # Confirmed (flagged as inappropriate)
  dismissed: "dismissed"      # Dismissed (no issues found)
}.freeze
REASON_CATEGORIES =

Report reason category keys (translations via I18n.t(“rails_image_post_solution.image_report.categories.#key”))

%i[r18 r18g copyright spam harassment other].freeze

Class Method Summary collapse

Class Method Details

.categories_for_selectObject

Get category list (for use in views)



24
25
26
# File 'app/models/rails_image_post_solution/image_report.rb', line 24

def self.categories_for_select
  REASON_CATEGORIES.map { |key| [ key, category_text(key) ] }
end

.category_text(key) ⇒ Object

Get category translation text



19
20
21
# File 'app/models/rails_image_post_solution/image_report.rb', line 19

def self.category_text(key)
  I18n.t("rails_image_post_solution.image_report.categories.#{key}")
end

.image_reported?(attachment_id) ⇒ Boolean

Check if image has been reported as inappropriate

Returns:

  • (Boolean)


46
47
48
49
50
# File 'app/models/rails_image_post_solution/image_report.rb', line 46

def self.image_reported?(attachment_id)
  where(active_storage_attachment_id: attachment_id)
    .where(status: [ STATUSES[:pending], STATUSES[:confirmed] ])
    .exists?
end

.report_count(attachment_id) ⇒ Object

Get report count for image



53
54
55
# File 'app/models/rails_image_post_solution/image_report.rb', line 53

def self.report_count(attachment_id)
  where(active_storage_attachment_id: attachment_id).count
end