1 # frozen_string_literal: true
 
   3 # == Schema Information
 
   7 #  id         :integer          not null, primary key
 
   8 #  issue_id   :integer          not null
 
   9 #  user_id    :integer          not null
 
  10 #  details    :text             not null
 
  11 #  category   :string           not null
 
  12 #  created_at :datetime         not null
 
  13 #  updated_at :datetime         not null
 
  17 #  index_reports_on_issue_id  (issue_id)
 
  18 #  index_reports_on_user_id   (user_id)
 
  22 #  reports_issue_id_fkey  (issue_id => issues.id)
 
  23 #  reports_user_id_fkey   (user_id => users.id)
 
  26 class Report < ApplicationRecord
 
  27   belongs_to :issue, :counter_cache => true
 
  30   validates :details, :presence => true, :characters => true
 
  31   validates :category, :presence => true
 
  33   def self.categories_for(reportable)
 
  34     case reportable.class.name
 
  35     when "DiaryEntry", "DiaryComment" then %w[spam offensive threat other]
 
  36     when "User" then %w[spam offensive threat vandal other]
 
  37     when "Note" then %w[spam personal abusive other]
 
  43     RichText.new("markdown", self[:details])