1 class Issue < ActiveRecord::Base
2 belongs_to :reportable, :polymorphic => true
3 belongs_to :reported_user, :class_name => "User", :foreign_key => :reported_user_id
4 belongs_to :user_updated, :class_name => "User", :foreign_key => :updated_by
6 has_many :reports, :dependent => :destroy
7 has_many :comments, :class_name => "IssueComment", :dependent => :destroy
9 validates :reportable_id, :uniqueness => { :scope => [:reportable_type] }
10 validates :reported_user_id, :presence => true
12 # Check if more statuses are needed
13 enum :status => %w[open ignored resolved]
14 enum :type => %w[administrator moderator]
16 scope :with_status, ->(issue_status) { where(:status => statuses[issue_status]) }
19 resolved_at.present? ? reports.where("updated_at < ?", resolved_at) : nil
23 resolved_at.present? ? reports.where("updated_at >= ?", resolved_at) : reports
27 aasm :column => :status, :no_direct_assignment => true do
28 state :open, :initial => true
33 transitions :from => :open, :to => :ignored
37 transitions :from => :open, :to => :resolved
39 self.resolved_at = Time.now.getutc
44 transitions :from => :resolved, :to => :open
45 transitions :from => :ignored, :to => :open