2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
class Board < ApplicationRecord
|
2023-07-09 08:55:56 +05:30
|
|
|
include EachBatch
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
RECENT_BOARDS_SIZE = 4
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
belongs_to :group
|
2016-09-13 17:45:13 +05:30
|
|
|
belongs_to :project
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
has_many :lists, -> { ordered }, dependent: :delete_all, inverse_of: :board # rubocop:disable Cop/ActiveRecordDependent
|
|
|
|
has_many :destroyable_lists, -> { destroyable.ordered }, class_name: "List", inverse_of: :board
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
validates :name, presence: true
|
2018-03-17 18:26:18 +05:30
|
|
|
validates :project, presence: true, if: :project_needed?
|
2018-03-27 19:54:05 +05:30
|
|
|
validates :group, presence: true, unless: :project
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
scope :with_associations, -> { preload(:destroyable_lists) }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
# Sort by case-insensitive name, then ascending ids. This ensures that we will always
|
|
|
|
# get the same list/first board no matter how many other boards are named the same
|
|
|
|
scope :order_by_name_asc, -> { order(arel_table[:name].lower.asc).order(id: :asc) }
|
2023-04-23 21:23:45 +05:30
|
|
|
scope :first_board, -> { where(id: order_by_name_asc.limit(1).select(:id)) }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def project_needed?
|
2018-03-27 19:54:05 +05:30
|
|
|
!group
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def resource_parent
|
|
|
|
@resource_parent ||= group || project
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def group_board?
|
2018-03-27 19:54:05 +05:30
|
|
|
group_id.present?
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
def project_board?
|
|
|
|
project_id.present?
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
def scoped?
|
|
|
|
false
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
def self.to_type
|
|
|
|
name.demodulize
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_type
|
|
|
|
self.class.to_type
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
def disabled_for?(current_user)
|
|
|
|
namespace = group_board? ? resource_parent.root_ancestor : resource_parent.root_namespace
|
|
|
|
|
|
|
|
namespace.issue_repositioning_disabled? || !Ability.allowed?(current_user, :create_non_backlog_issues, self)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Board.prepend_mod_with('Board')
|