]> git.openstreetmap.org Git - rails.git/blob - app/models/report.rb
Merge branch 'master' into moderation
[rails.git] / app / models / report.rb
1 # == Schema Information
2 #
3 # Table name: reports
4 #
5 #  id         :integer          not null, primary key
6 #  issue_id   :integer
7 #  user_id    :integer
8 #  details    :text             not null
9 #  category   :string           not null
10 #  created_at :datetime         not null
11 #  updated_at :datetime         not null
12 #
13 # Indexes
14 #
15 #  index_reports_on_issue_id  (issue_id)
16 #  index_reports_on_user_id   (user_id)
17 #
18 # Foreign Keys
19 #
20 #  reports_issue_id_fkey  (issue_id => issues.id) ON DELETE => cascade
21 #  reports_user_id_fkey   (user_id => users.id) ON DELETE => cascade
22 #
23
24 class Report < ActiveRecord::Base
25   belongs_to :issue, :counter_cache => true
26   belongs_to :user
27
28   validates :details, :presence => true
29   validates :category, :presence => true
30
31   def self.categories_for(reportable)
32     case reportable.class.name
33     when "DiaryEntry" then %w[spam offensive threat other]
34     when "DiaryComment" then %w[spam offensive threat other]
35     when "User" then %w[spam offensive threat vandal other]
36     when "Changeset" then %w[undiscussed_import mechanical_edit edit_error spam vandalism other]
37     when "Note" then %w[spam vandalism personal abusive other]
38     else %w[other]
39     end
40   end
41 end