gitlab-org--gitlab-foss/app/models/board.rb
Stan Hu b2da8042b4 Fix 403 errors when adding an assignee list in project boards
Due to a bug in `BoardPolicy`, users were getting back a 403 error when
trying to assign users to an assignee list and seeing "Something went
wrong while fetching assignees list". For some reason, the declarative
policy runtime was ignoring the ternary condition.

To work around the issue, we make the project board an explicit
condition check.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/9727
2019-02-14 13:41:43 -08:00

39 lines
691 B
Ruby

# frozen_string_literal: true
class Board < ActiveRecord::Base
belongs_to :group
belongs_to :project
has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
validates :project, presence: true, if: :project_needed?
validates :group, presence: true, unless: :project
def project_needed?
!group
end
def parent
@parent ||= group || project
end
def group_board?
group_id.present?
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
end