gitlab-org--gitlab-foss/app/models/board.rb

46 lines
886 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Board < ApplicationRecord
2018-02-19 19:06:16 +00:00
belongs_to :group
2016-07-27 19:32:32 +00:00
belongs_to :project
has_many :lists, -> { ordered }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :destroyable_lists, -> { destroyable.ordered }, class_name: "List"
2016-07-27 19:32:32 +00:00
2017-08-28 21:56:49 +00:00
validates :project, presence: true, if: :project_needed?
2018-02-19 19:06:16 +00:00
validates :group, presence: true, unless: :project
2017-08-28 21:56:49 +00:00
scope :with_associations, -> { preload(:destroyable_lists) }
2017-08-28 21:56:49 +00:00
def project_needed?
2018-02-19 19:06:16 +00:00
!group
2017-08-28 21:56:49 +00:00
end
2017-08-31 19:34:57 +00:00
def parent
2018-02-19 19:06:16 +00:00
@parent ||= group || project
2017-08-31 19:34:57 +00:00
end
alias_method :resource_parent, :parent
2017-08-31 19:34:57 +00:00
def group_board?
2018-02-19 19:06:16 +00:00
group_id.present?
2017-08-31 19:34:57 +00:00
end
def project_board?
project_id.present?
end
def backlog_list
lists.merge(List.backlog).take
end
def closed_list
lists.merge(List.closed).take
end
def scoped?
false
end
2016-07-27 19:32:32 +00:00
end
Board.prepend_if_ee('EE::Board')