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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Board < ApplicationRecord
RECENT_BOARDS_SIZE = 4
2018-02-19 14:06:16 -05:00
belongs_to :group
2016-07-27 15:32:32 -04: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 15:32:32 -04:00
validates :name, presence: true
2017-08-28 17:56:49 -04:00
validates :project, presence: true, if: :project_needed?
2018-02-19 14:06:16 -05:00
validates :group, presence: true, unless: :project
2017-08-28 17:56:49 -04:00
scope :with_associations, -> { preload(:destroyable_lists) }
# 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) }
scope :first_board, -> { where(id: self.order_by_name_asc.limit(1).select(:id)) }
2017-08-28 17:56:49 -04:00
def project_needed?
2018-02-19 14:06:16 -05:00
!group
2017-08-28 17:56:49 -04:00
end
def resource_parent
@resource_parent ||= group || project
2017-08-31 15:34:57 -04:00
end
def group_board?
2018-02-19 14:06:16 -05:00
group_id.present?
2017-08-31 15:34:57 -04:00
end
def project_board?
project_id.present?
end
def scoped?
false
end
def self.to_type
name.demodulize
end
def to_type
self.class.to_type
end
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-07-27 15:32:32 -04:00
end
Board.prepend_mod_with('Board')