port CommitStatus/Build

This commit is contained in:
http://jneen.net/ 2016-08-16 12:05:44 -07:00
parent 0928610930
commit 16fe6dc7b1
4 changed files with 24 additions and 1 deletions

View file

@ -74,7 +74,8 @@ class Ability
when Issue then IssuePolicy.abilities(user, subject)
when MergeRequest then MergeRequestPolicy.abilities(user, subject)
when CommitStatus then commit_status_abilities(user, subject)
when Ci::Build then Ci::BuildPolicy.abilities(user, subject)
when CommitStatus then CommitStatus.abilities(user, subject)
when Note then note_abilities(user, subject)
when ProjectSnippet then project_snippet_abilities(user, subject)
when PersonalSnippet then personal_snippet_abilities(user, subject)

View file

@ -30,6 +30,10 @@ class BasePolicy
@can.merge(BasePolicy.class_for(new_subject).abilities(@user, new_subject))
end
def can?(rule)
@can.include?(rule) && !@cannot.include?(rule)
end
def can!(*rules)
@can.merge(rules)
end

View file

@ -0,0 +1,13 @@
module Ci
class BuildPolicy < CommitStatusPolicy
def rules
super
# If we can't read build we should also not have that
# ability when looking at this in context of commit_status
%w(read create update admin).each do |rule|
cannot! :"#{rule}_commit_status" unless can? :"#{rule}_build"
end
end
end
end

View file

@ -0,0 +1,5 @@
class CommitStatusPolicy < BasePolicy
def rules
delegate! @subject.project
end
end