issue.rb 1.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
# == Schema Information
#
# Table name: issues
#
#  id           :integer          not null, primary key
#  title        :string(255)
#  assignee_id  :integer
#  author_id    :integer
#  project_id   :integer
#  created_at   :datetime         not null
#  updated_at   :datetime         not null
Andrew8xx8's avatar
Andrew8xx8 committed
12
#  state        :string           default(FALSE), not null
13 14 15 16 17 18
#  position     :integer          default(0)
#  branch_name  :string(255)
#  description  :text
#  milestone_id :integer
#

gitlabhq's avatar
gitlabhq committed
19
class Issue < ActiveRecord::Base
20
  include Issuable
21

Andrew8xx8's avatar
Andrew8xx8 committed
22 23 24
  attr_accessible :title, :assignee_id, :position, :description,
                  :milestone_id, :label_list, :author_id_of_changes,
                  :state_event
25

26 27
  acts_as_taggable_on :labels

28 29 30 31 32
  class << self
    def cared(user)
      where('assignee_id = :user', user: user.id)
    end

33 34 35 36
    def authored(user)
      where('author_id = :user', user: user.id)
    end

37 38 39
    def open_for(user)
      opened.assigned(user)
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
40
  end
41

Andrew8xx8's avatar
Andrew8xx8 committed
42
  state_machine :state, initial: :opened do
Andrew8xx8's avatar
Andrew8xx8 committed
43 44 45 46 47
    event :close do
      transition [:reopened, :opened] => :closed
    end

    event :reopen do
Andrew8xx8's avatar
Andrew8xx8 committed
48
      transition closed: :reopened
Andrew8xx8's avatar
Andrew8xx8 committed
49 50 51 52 53 54 55 56
    end

    state :opened

    state :reopened

    state :closed
  end
gitlabhq's avatar
gitlabhq committed
57
end