]> git.openstreetmap.org Git - rails.git/blob - app/models/report.rb
Add frozen_string_literal comments to ruby files
[rails.git] / app / models / report.rb
1 # frozen_string_literal: true
2
3 # == Schema Information
4 #
5 # Table name: reports
6 #
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
14 #
15 # Indexes
16 #
17 #  index_reports_on_issue_id  (issue_id)
18 #  index_reports_on_user_id   (user_id)
19 #
20 # Foreign Keys
21 #
22 #  reports_issue_id_fkey  (issue_id => issues.id)
23 #  reports_user_id_fkey   (user_id => users.id)
24 #
25
26 class Report < ApplicationRecord
27   belongs_to :issue, :counter_cache => true
28   belongs_to :user
29
30   validates :details, :presence => true, :characters => true
31   validates :category, :presence => true
32
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]
38     else %w[other]
39     end
40   end
41
42   def details
43     RichText.new("markdown", self[:details])
44   end
45 end