OSDN Git Service

Merge branch 'feature/refactoring_scopes_pr' of https://github.com/Undev/gitlabhq...
[wvm/gitlab.git] / app / models / issue.rb
1 # == Schema Information
2 #
3 # Table name: issues
4 #
5 #  id           :integer          not null, primary key
6 #  title        :string(255)
7 #  assignee_id  :integer
8 #  author_id    :integer
9 #  project_id   :integer
10 #  created_at   :datetime         not null
11 #  updated_at   :datetime         not null
12 #  position     :integer          default(0)
13 #  branch_name  :string(255)
14 #  description  :text
15 #  milestone_id :integer
16 #  state        :string(255)
17 #
18
19 class Issue < ActiveRecord::Base
20   include Issuable
21
22   attr_accessible :title, :assignee_id, :position, :description,
23                   :milestone_id, :label_list, :author_id_of_changes,
24                   :state_event
25
26   acts_as_taggable_on :labels
27
28   scope :cared, ->(user) { where(assignee_id: user) }
29   scope :authored, ->(user) { where(author_id: user) }
30   scope :open_for, ->(user) { opened.assigned(user) }
31
32   state_machine :state, initial: :opened do
33     event :close do
34       transition [:reopened, :opened] => :closed
35     end
36
37     event :reopen do
38       transition closed: :reopened
39     end
40
41     state :opened
42
43     state :reopened
44
45     state :closed
46   end
47
48   # Both open and reopened issues should be listed as opened
49   scope :opened, -> { with_state(:opened, :reopened) }
50 end