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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
2aa211fa
Commit
2aa211fa
authored
Apr 12, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use build policy to determine if user can play build
parent
55aa727e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
6 additions
and
69 deletions
+6
-69
app/models/ci/build.rb
app/models/ci/build.rb
+0
-6
app/models/environment.rb
app/models/environment.rb
+0
-6
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/stop_environments_service.rb
app/services/ci/stop_environments_service.rb
+2
-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/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+0
-27
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+0
-25
No files found.
app/models/ci/build.rb
View file @
2aa211fa
...
@@ -115,12 +115,6 @@ module Ci
...
@@ -115,12 +115,6 @@ module Ci
commands
.
present?
commands
.
present?
end
end
def
can_play?
(
current_user
)
::
Gitlab
::
UserAccess
.
new
(
current_user
,
project:
project
)
.
can_push_to_branch?
(
ref
)
end
def
play
(
current_user
)
def
play
(
current_user
)
Ci
::
PlayBuildService
Ci
::
PlayBuildService
.
new
(
project
,
current_user
)
.
new
(
project
,
current_user
)
...
...
app/models/environment.rb
View file @
2aa211fa
...
@@ -122,12 +122,6 @@ class Environment < ActiveRecord::Base
...
@@ -122,12 +122,6 @@ class Environment < ActiveRecord::Base
available?
&&
stop_action
.
present?
available?
&&
stop_action
.
present?
end
end
def
can_trigger_stop_action?
(
current_user
)
return
false
unless
stop_action?
stop_action
.
can_play?
(
current_user
)
end
def
stop_with_action!
(
current_user
)
def
stop_with_action!
(
current_user
)
return
unless
available?
return
unless
available?
...
...
app/serializers/build_action_entity.rb
View file @
2aa211fa
...
@@ -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?
&&
build
.
can_play?
(
request
.
user
)
can?
(
request
.
user
,
:play_build
,
build
)
&&
build
.
playable?
end
end
end
end
app/serializers/build_entity.rb
View file @
2aa211fa
...
@@ -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?
&&
build
.
can_play?
(
request
.
user
)
can?
(
request
.
user
,
:play_build
,
build
)
&&
build
.
playable?
end
end
def
detailed_status
def
detailed_status
...
...
app/services/ci/stop_environments_service.rb
View file @
2aa211fa
...
@@ -9,7 +9,8 @@ module Ci
...
@@ -9,7 +9,8 @@ module Ci
return
unless
can?
(
current_user
,
:create_deployment
,
project
)
return
unless
can?
(
current_user
,
:create_deployment
,
project
)
environments
.
each
do
|
environment
|
environments
.
each
do
|
environment
|
next
unless
environment
.
can_trigger_stop_action?
(
current_user
)
next
unless
environment
.
stop_action?
next
unless
can?
(
current_user
,
:play_build
,
environment
.
stop_action
)
environment
.
stop_with_action!
(
current_user
)
environment
.
stop_with_action!
(
current_user
)
end
end
...
...
app/views/projects/ci/builds/_build.html.haml
View file @
2aa211fa
...
@@ -101,7 +101,7 @@
...
@@ -101,7 +101,7 @@
=
link_to
cancel_namespace_project_build_path
(
build
.
project
.
namespace
,
build
.
project
,
build
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Cancel'
,
class:
'btn btn-build'
do
=
link_to
cancel_namespace_project_build_path
(
build
.
project
.
namespace
,
build
.
project
,
build
,
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
build
.
playable?
&&
!
admin
&&
build
.
can_play?
(
current_user
)
-
if
build
.
playable?
&&
!
admin
&&
can?
(
current_user
,
:play_build
,
build
)
=
link_to
play_namespace_project_build_path
(
build
.
project
.
namespace
,
build
.
project
,
build
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Play'
,
class:
'btn btn-build'
do
=
link_to
play_namespace_project_build_path
(
build
.
project
.
namespace
,
build
.
project
,
build
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Play'
,
class:
'btn btn-build'
do
=
custom_icon
(
'icon_play'
)
=
custom_icon
(
'icon_play'
)
-
elsif
build
.
retryable?
-
elsif
build
.
retryable?
...
...
lib/gitlab/ci/status/build/play.rb
View file @
2aa211fa
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
end
end
def
has_action?
def
has_action?
can?
(
user
,
:
update_build
,
subject
)
&&
subject
.
can_play?
(
user
)
can?
(
user
,
:
play_build
,
subject
)
end
end
def
action_icon
def
action_icon
...
...
spec/models/ci/build_spec.rb
View file @
2aa211fa
...
@@ -925,33 +925,6 @@ describe Ci::Build, :models do
...
@@ -925,33 +925,6 @@ describe Ci::Build, :models do
end
end
end
end
describe
'#can_play?'
do
before
do
project
.
add_developer
(
user
)
end
let
(
:build
)
do
create
(
:ci_build
,
ref:
'some-ref'
,
pipeline:
pipeline
)
end
context
'when branch build is running for is protected'
do
before
do
create
(
:protected_branch
,
:no_one_can_push
,
name:
'some-ref'
,
project:
project
)
end
it
'indicates that user can not trigger an action'
do
expect
(
build
.
can_play?
(
user
)).
to
be_falsey
end
end
context
'when branch build is running for is not protected'
do
it
'indicates that user can trigger an action'
do
expect
(
build
.
can_play?
(
user
)).
to
be_truthy
end
end
end
describe
'#play'
do
describe
'#play'
do
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
)
}
...
...
spec/models/environment_spec.rb
View file @
2aa211fa
...
@@ -155,31 +155,6 @@ describe Environment, models: true do
...
@@ -155,31 +155,6 @@ describe Environment, models: true do
end
end
end
end
describe
'#can_trigger_stop_action?'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:environment
)
do
create
(
:environment
,
:with_review_app
,
project:
project
)
end
context
'when user can trigger stop action'
do
before
do
project
.
add_developer
(
user
)
end
it
'returns value that evaluates to true'
do
expect
(
environment
.
can_trigger_stop_action?
(
user
)).
to
be_truthy
end
end
context
'when user is not allowed to trigger stop action'
do
it
'returns value that evaluates to false'
do
expect
(
environment
.
can_trigger_stop_action?
(
user
)).
to
be_falsey
end
end
end
describe
'#stop_with_action!'
do
describe
'#stop_with_action!'
do
let
(
:user
)
{
create
(
:admin
)
}
let
(
:user
)
{
create
(
:admin
)
}
...
...
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