2016-08-16 14:10:34 -04:00
|
|
|
class IssuePolicy < IssuablePolicy
|
2016-11-01 16:18:51 -04:00
|
|
|
# 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.
|
|
|
|
|
2016-08-16 14:10:34 -04:00
|
|
|
def issue
|
|
|
|
@subject
|
|
|
|
end
|
|
|
|
|
|
|
|
def rules
|
|
|
|
super
|
|
|
|
|
|
|
|
if @subject.confidential? && !can_read_confidential?
|
|
|
|
cannot! :read_issue
|
|
|
|
cannot! :update_issue
|
2016-10-12 08:01:34 -04:00
|
|
|
cannot! :admin_issue
|
2016-08-16 14:10:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_read_confidential?
|
|
|
|
return false unless @user
|
2016-08-30 18:55:37 -04:00
|
|
|
|
2016-10-07 09:20:57 -04:00
|
|
|
IssueCollection.new([@subject]).visible_to(@user).any?
|
2016-08-16 14:10:34 -04:00
|
|
|
end
|
|
|
|
end
|