issue.rb 2.08 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
class Issue < ActiveRecord::Base
2 3
  include Upvote

4 5
  acts_as_taggable_on :labels

gitlabhq's avatar
gitlabhq committed
6
  belongs_to :project
7
  belongs_to :milestone
gitlabhq's avatar
gitlabhq committed
8 9
  belongs_to :author, :class_name => "User"
  belongs_to :assignee, :class_name => "User"
10
  has_many :notes, :as => :noteable, :dependent => :destroy
gitlabhq's avatar
gitlabhq committed
11 12

  attr_protected :author, :author_id, :project, :project_id
13
  attr_accessor :author_id_of_changes
gitlabhq's avatar
gitlabhq committed
14 15 16 17

  validates_presence_of :project_id
  validates_presence_of :author_id

18
  delegate :name,
19 20
           :email,
           :to => :author,
21 22
           :prefix => true

gitlabhq's avatar
gitlabhq committed
23 24 25
  delegate :name,
           :email,
           :to => :assignee,
randx's avatar
randx committed
26
           :allow_nil => true,
gitlabhq's avatar
gitlabhq committed
27 28
           :prefix => true

gitlabhq's avatar
gitlabhq committed
29 30 31
  validates :title,
            :presence => true,
            :length   => { :within => 0..255 }
32

Steven Verbeek's avatar
Steven Verbeek committed
33 34
  validates :description,
            :length   => { :within => 0..2000 }
Nihad Abbasov's avatar
Nihad Abbasov committed
35

gitlabhq's avatar
gitlabhq committed
36 37 38
  scope :critical, where(:critical => true)
  scope :non_critical, where(:critical => false)

gitlabhq's avatar
gitlabhq committed
39 40 41
  scope :opened, where(:closed => false)
  scope :closed, where(:closed => true)
  scope :assigned, lambda { |u| where(:assignee_id => u.id)}
VSizov's avatar
VSizov committed
42 43

  acts_as_list
gitlabhq's avatar
gitlabhq committed
44

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
45 46 47 48
  def self.open_for(user)
    opened.assigned(user)
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
49 50 51 52
  def self.search query
    where("title like :query", :query => "%#{query}%")
  end

gitlabhq's avatar
gitlabhq committed
53 54 55
  def today?
    Date.today == created_at.to_date
  end
Nihad Abbasov's avatar
Nihad Abbasov committed
56

gitlabhq's avatar
gitlabhq committed
57 58 59
  def new?
    today? && created_at == updated_at
  end
60

randx's avatar
randx committed
61 62 63 64
  def is_assigned?
    !!assignee_id
  end

65 66 67
  def is_being_reassigned?
    assignee_id_changed?
  end
68 69 70 71

  def is_being_closed?
    closed_changed? && closed
  end
72 73 74 75

  def is_being_reopened?
    closed_changed? && !closed
  end
gitlabhq's avatar
gitlabhq committed
76 77 78 79 80
end
# == Schema Information
#
# Table name: issues
#
randx's avatar
randx committed
81 82 83 84 85 86 87 88 89 90 91 92 93
#  id           :integer(4)      not null, primary key
#  title        :string(255)
#  assignee_id  :integer(4)
#  author_id    :integer(4)
#  project_id   :integer(4)
#  created_at   :datetime        not null
#  updated_at   :datetime        not null
#  closed       :boolean(1)      default(FALSE), not null
#  position     :integer(4)      default(0)
#  critical     :boolean(1)      default(FALSE), not null
#  branch_name  :string(255)
#  description  :text
#  milestone_id :integer(4)
gitlabhq's avatar
gitlabhq committed
94 95
#