Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
b09465f3
Commit
b09465f3
authored
Apr 12, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement new rule for manual actions in policies
parent
7bcca228
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
app/policies/ci/build_policy.rb
app/policies/ci/build_policy.rb
+14
-0
spec/policies/ci/build_policy_spec.rb
spec/policies/ci/build_policy_spec.rb
+53
-0
No files found.
app/policies/ci/build_policy.rb
View file @
b09465f3
...
...
@@ -8,6 +8,20 @@ module Ci
%w[read create update admin]
.
each
do
|
rule
|
cannot!
:"
#{
rule
}
_commit_status"
unless
can?
:"
#{
rule
}
_build"
end
can!
:play_build
if
can_play_action?
end
private
alias_method
:build
,
:subject
def
can_play_action?
return
false
unless
build
.
playable?
::
Gitlab
::
UserAccess
.
new
(
user
,
project:
build
.
project
)
.
can_push_to_branch?
(
build
.
ref
)
end
end
end
spec/policies/ci/build_policy_spec.rb
View file @
b09465f3
...
...
@@ -89,5 +89,58 @@ describe Ci::BuildPolicy, :models do
end
end
end
describe
'rules for manual actions'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
project
.
add_developer
(
user
)
end
context
'when branch build is assigned to is protected'
do
before
do
create
(
:protected_branch
,
:no_one_can_push
,
name:
'some-ref'
,
project:
project
)
end
context
'when build is a manual action'
do
let
(
:build
)
do
create
(
:ci_build
,
:manual
,
ref:
'some-ref'
,
pipeline:
pipeline
)
end
it
'does not include ability to play build'
do
expect
(
policies
).
not_to
include
:play_build
end
end
context
'when build is not a manual action'
do
let
(
:build
)
do
create
(
:ci_build
,
ref:
'some-ref'
,
pipeline:
pipeline
)
end
it
'does not include ability to play build'
do
expect
(
policies
).
not_to
include
:play_build
end
end
end
context
'when branch build is assigned to is not protected'
do
context
'when build is a manual action'
do
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
)
}
it
'includes ability to play build'
do
expect
(
policies
).
to
include
:play_build
end
end
context
'when build is not a manual action'
do
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
it
'does not include ability to play build'
do
expect
(
policies
).
not_to
include
:play_build
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment