BigW Consortium Gitlab

issue_commonality.rb 1.16 KB
Newer Older
1 2
# Contains common functionality shared between Issues and MergeRequests
module IssueCommonality
3 4 5 6 7 8
  extend ActiveSupport::Concern

  included do
    attr_protected :author, :author_id, :project, :project_id

    belongs_to :project
9 10 11
    belongs_to :author, class_name: "User"
    belongs_to :assignee, class_name: "User"
    has_many :notes, as: :noteable, dependent: :destroy
12 13 14 15 16

    validates_presence_of :project_id
    validates_presence_of :author_id

    validates :title,
17 18
              presence: true,
              length: { within: 0..255 }
19 20


21 22 23
    scope :opened, where(closed: false)
    scope :closed, where(closed: true)
    scope :assigned, lambda { |u| where(assignee_id: u.id)}
24 25 26

    delegate :name,
             :email,
27 28
             to: :author,
             prefix: true
29 30 31

    delegate :name,
             :email,
32 33 34
             to: :assignee,
             allow_nil: true,
             prefix: true
35 36 37 38

    attr_accessor :author_id_of_changes
  end

39 40
  module ClassMethods
    def search(query)
41
      where("title like :query", query: "%#{query}%")
42
    end
43 44 45 46 47 48 49 50 51
  end

  def today?
    Date.today == created_at.to_date
  end

  def new?
    today? && created_at == updated_at
  end
52
end