board.rb 691 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
class Board < ActiveRecord::Base
4
  belongs_to :group
5 6
  belongs_to :project

7
  has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
8

Felipe Artur's avatar
Felipe Artur committed
9
  validates :project, presence: true, if: :project_needed?
10
  validates :group, presence: true, unless: :project
Felipe Artur's avatar
Felipe Artur committed
11 12

  def project_needed?
13
    !group
Felipe Artur's avatar
Felipe Artur committed
14
  end
15

Felipe Artur's avatar
Felipe Artur committed
16
  def parent
17
    @parent ||= group || project
Felipe Artur's avatar
Felipe Artur committed
18 19 20
  end

  def group_board?
21
    group_id.present?
Felipe Artur's avatar
Felipe Artur committed
22 23
  end

24 25 26 27
  def project_board?
    project_id.present?
  end

28 29 30 31
  def backlog_list
    lists.merge(List.backlog).take
  end

32 33
  def closed_list
    lists.merge(List.closed).take
34
  end
35 36 37 38

  def scoped?
    false
  end
39
end