BigW Consortium Gitlab

issue_policy.rb 633 Bytes
Newer Older
1
class IssuePolicy < IssuablePolicy
2 3 4 5
  # This class duplicates the same check of Issue#readable_by? for performance reasons
  # Make sure to sync this class checks with issue.rb to avoid security problems.
  # Check commit 002ad215818450d2cbbc5fa065850a953dc7ada8 for more information.

6 7 8 9 10 11 12 13 14 15
  def issue
    @subject
  end

  def rules
    super

    if @subject.confidential? && !can_read_confidential?
      cannot! :read_issue
      cannot! :update_issue
Yorick Peterse committed
16
      cannot! :admin_issue
17 18 19 20 21 22 23
    end
  end

  private

  def can_read_confidential?
    return false unless @user
24

25
    IssueCollection.new([@subject]).visible_to(@user).any?
26 27
  end
end