]> git.openstreetmap.org Git - rails.git/blob - app/models/report.rb
Keep the behaviour backwards-compatible
[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          not null
7 #  user_id    :integer          not null
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)
21 #  reports_user_id_fkey   (user_id => users.id)
22 #
23
24 class Report < ActiveRecord::Base
25   belongs_to :issue, :counter_cache => true
26   belongs_to :user
27
28   validates :issue, :presence => true
29   validates :user, :presence => true
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" then %w[spam offensive threat other]
36     when "DiaryComment" then %w[spam offensive threat other]
37     when "User" then %w[spam offensive threat vandal other]
38     when "Note" then %w[spam personal abusive other]
39     else %w[other]
40     end
41   end
42 end