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
Jérome Perrin
gitlab-ce
Commits
93636753
Commit
93636753
authored
May 05, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use update build policy instead of new play policy
parent
b6facd83
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
22 additions
and
20 deletions
+22
-20
app/policies/ci/build_policy.rb
app/policies/ci/build_policy.rb
+7
-5
app/policies/environment_policy.rb
app/policies/environment_policy.rb
+1
-1
app/serializers/build_action_entity.rb
app/serializers/build_action_entity.rb
+1
-1
app/serializers/build_entity.rb
app/serializers/build_entity.rb
+1
-1
app/services/ci/play_build_service.rb
app/services/ci/play_build_service.rb
+1
-1
app/views/projects/ci/builds/_build.html.haml
app/views/projects/ci/builds/_build.html.haml
+1
-1
lib/gitlab/ci/status/build/play.rb
lib/gitlab/ci/status/build/play.rb
+1
-1
spec/policies/ci/build_policy_spec.rb
spec/policies/ci/build_policy_spec.rb
+9
-9
No files found.
app/policies/ci/build_policy.rb
View file @
93636753
module
Ci
module
Ci
class
BuildPolicy
<
CommitStatusPolicy
class
BuildPolicy
<
CommitStatusPolicy
alias_method
:build
,
:subject
def
rules
def
rules
super
super
...
@@ -9,17 +11,17 @@ module Ci
...
@@ -9,17 +11,17 @@ module Ci
cannot!
:"
#{
rule
}
_commit_status"
unless
can?
:"
#{
rule
}
_build"
cannot!
:"
#{
rule
}
_commit_status"
unless
can?
:"
#{
rule
}
_build"
end
end
can!
:play_build
if
can_play_action?
if
can?
(
:update_build
)
&&
protected_action?
cannot!
:update_build
end
end
end
private
private
alias_method
:build
,
:subject
def
protected_action?
def
can_play_action?
return
false
unless
build
.
action?
return
false
unless
build
.
action?
::
Gitlab
::
UserAccess
!
::
Gitlab
::
UserAccess
.
new
(
user
,
project:
build
.
project
)
.
new
(
user
,
project:
build
.
project
)
.
can_push_to_branch?
(
build
.
ref
)
.
can_push_to_branch?
(
build
.
ref
)
end
end
...
...
app/policies/environment_policy.rb
View file @
93636753
...
@@ -12,6 +12,6 @@ class EnvironmentPolicy < BasePolicy
...
@@ -12,6 +12,6 @@ class EnvironmentPolicy < BasePolicy
private
private
def
can_play_stop_action?
def
can_play_stop_action?
Ability
.
allowed?
(
user
,
:
play
_build
,
environment
.
stop_action
)
Ability
.
allowed?
(
user
,
:
update
_build
,
environment
.
stop_action
)
end
end
end
end
app/serializers/build_action_entity.rb
View file @
93636753
...
@@ -19,6 +19,6 @@ class BuildActionEntity < Grape::Entity
...
@@ -19,6 +19,6 @@ class BuildActionEntity < Grape::Entity
alias_method
:build
,
:object
alias_method
:build
,
:object
def
playable?
def
playable?
build
.
playable?
&&
can?
(
request
.
user
,
:
play
_build
,
build
)
build
.
playable?
&&
can?
(
request
.
user
,
:
update
_build
,
build
)
end
end
end
end
app/serializers/build_entity.rb
View file @
93636753
...
@@ -26,7 +26,7 @@ class BuildEntity < Grape::Entity
...
@@ -26,7 +26,7 @@ class BuildEntity < Grape::Entity
alias_method
:build
,
:object
alias_method
:build
,
:object
def
playable?
def
playable?
build
.
playable?
&&
can?
(
request
.
user
,
:
play
_build
,
build
)
build
.
playable?
&&
can?
(
request
.
user
,
:
update
_build
,
build
)
end
end
def
detailed_status
def
detailed_status
...
...
app/services/ci/play_build_service.rb
View file @
93636753
module
Ci
module
Ci
class
PlayBuildService
<
::
BaseService
class
PlayBuildService
<
::
BaseService
def
execute
(
build
)
def
execute
(
build
)
unless
can?
(
current_user
,
:
play
_build
,
build
)
unless
can?
(
current_user
,
:
update
_build
,
build
)
raise
Gitlab
::
Access
::
AccessDeniedError
raise
Gitlab
::
Access
::
AccessDeniedError
end
end
...
...
app/views/projects/ci/builds/_build.html.haml
View file @
93636753
...
@@ -102,7 +102,7 @@
...
@@ -102,7 +102,7 @@
=
link_to
cancel_namespace_project_build_path
(
job
.
project
.
namespace
,
job
.
project
,
job
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Cancel'
,
class:
'btn btn-build'
do
=
link_to
cancel_namespace_project_build_path
(
job
.
project
.
namespace
,
job
.
project
,
job
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Cancel'
,
class:
'btn btn-build'
do
=
icon
(
'remove'
,
class:
'cred'
)
=
icon
(
'remove'
,
class:
'cred'
)
-
elsif
allow_retry
-
elsif
allow_retry
-
if
job
.
playable?
&&
!
admin
&&
can?
(
current_user
,
:
play
_build
,
job
)
-
if
job
.
playable?
&&
!
admin
&&
can?
(
current_user
,
:
update
_build
,
job
)
=
link_to
play_namespace_project_build_path
(
job
.
project
.
namespace
,
job
.
project
,
job
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Play'
,
class:
'btn btn-build'
do
=
link_to
play_namespace_project_build_path
(
job
.
project
.
namespace
,
job
.
project
,
job
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Play'
,
class:
'btn btn-build'
do
=
custom_icon
(
'icon_play'
)
=
custom_icon
(
'icon_play'
)
-
elsif
job
.
retryable?
-
elsif
job
.
retryable?
...
...
lib/gitlab/ci/status/build/play.rb
View file @
93636753
...
@@ -14,7 +14,7 @@ module Gitlab
...
@@ -14,7 +14,7 @@ module Gitlab
end
end
def
has_action?
def
has_action?
can?
(
user
,
:
play
_build
,
subject
)
can?
(
user
,
:
update
_build
,
subject
)
end
end
def
action_icon
def
action_icon
...
...
spec/policies/ci/build_policy_spec.rb
View file @
93636753
...
@@ -108,8 +108,8 @@ describe Ci::BuildPolicy, :models do
...
@@ -108,8 +108,8 @@ describe Ci::BuildPolicy, :models do
create
(
:ci_build
,
:manual
,
ref:
'some-ref'
,
pipeline:
pipeline
)
create
(
:ci_build
,
:manual
,
ref:
'some-ref'
,
pipeline:
pipeline
)
end
end
it
'does not include ability to
play
build'
do
it
'does not include ability to
update
build'
do
expect
(
policies
).
not_to
include
:
play
_build
expect
(
policies
).
not_to
include
:
update
_build
end
end
end
end
...
@@ -118,8 +118,8 @@ describe Ci::BuildPolicy, :models do
...
@@ -118,8 +118,8 @@ describe Ci::BuildPolicy, :models do
create
(
:ci_build
,
ref:
'some-ref'
,
pipeline:
pipeline
)
create
(
:ci_build
,
ref:
'some-ref'
,
pipeline:
pipeline
)
end
end
it
'
does not include ability to play
build'
do
it
'
includes ability to update
build'
do
expect
(
policies
).
not_to
include
:play
_build
expect
(
policies
).
to
include
:update
_build
end
end
end
end
end
end
...
@@ -128,16 +128,16 @@ describe Ci::BuildPolicy, :models do
...
@@ -128,16 +128,16 @@ describe Ci::BuildPolicy, :models do
context
'when build is a manual action'
do
context
'when build is a manual action'
do
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
)
}
it
'includes ability to
play
build'
do
it
'includes ability to
update
build'
do
expect
(
policies
).
to
include
:
play
_build
expect
(
policies
).
to
include
:
update
_build
end
end
end
end
context
'when build is not a manual action'
do
context
'when build is not a manual action'
do
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
it
'
does not include ability to play
build'
do
it
'
includes ability to update
build'
do
expect
(
policies
).
not_to
include
:play
_build
expect
(
policies
).
to
include
:update
_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