port CommitStatus/Build
This commit is contained in:
parent
0928610930
commit
16fe6dc7b1
4 changed files with 24 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
13
app/policies/ci/build_policy.rb
Normal file
13
app/policies/ci/build_policy.rb
Normal 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
|
5
app/policies/commit_status_policy.rb
Normal file
5
app/policies/commit_status_policy.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class CommitStatusPolicy < BasePolicy
|
||||
def rules
|
||||
delegate! @subject.project
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue