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
6c0fc62e
Commit
6c0fc62e
authored
Apr 06, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take branch access into account when stopping environment
parent
e533d43a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
7 deletions
+58
-7
app/models/deployment.rb
app/models/deployment.rb
+2
-2
app/models/environment.rb
app/models/environment.rb
+6
-0
app/services/ci/stop_environments_service.rb
app/services/ci/stop_environments_service.rb
+5
-3
spec/factories/environments.rb
spec/factories/environments.rb
+5
-1
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+25
-0
spec/services/ci/stop_environments_service_spec.rb
spec/services/ci/stop_environments_service_spec.rb
+15
-1
No files found.
app/models/deployment.rb
View file @
6c0fc62e
...
...
@@ -85,8 +85,8 @@ class Deployment < ActiveRecord::Base
end
def
stop_action
return
nil
unless
on_stop
.
present?
return
nil
unless
manual_actions
return
unless
on_stop
.
present?
return
unless
manual_actions
@stop_action
||=
manual_actions
.
find_by
(
name:
on_stop
)
end
...
...
app/models/environment.rb
View file @
6c0fc62e
...
...
@@ -122,6 +122,12 @@ class Environment < ActiveRecord::Base
available?
&&
stop_action
.
present?
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
)
return
unless
available?
...
...
app/services/ci/stop_environments_service.rb
View file @
6c0fc62e
...
...
@@ -6,9 +6,10 @@ module Ci
@ref
=
branch_name
return
unless
has_ref?
return
unless
can?
(
current_user
,
:create_deployment
,
project
)
environments
.
each
do
|
environment
|
next
unless
can?
(
current_user
,
:create_deployment
,
project
)
next
unless
environment
.
can_trigger_stop_action?
(
current_user
)
environment
.
stop_with_action!
(
current_user
)
end
...
...
@@ -21,8 +22,9 @@ module Ci
end
def
environments
@environments
||=
EnvironmentsFinder
.
new
(
project
,
current_user
,
ref:
@ref
,
recently_updated:
true
).
execute
@environments
||=
EnvironmentsFinder
.
new
(
project
,
current_user
,
ref:
@ref
,
recently_updated:
true
)
.
execute
end
end
end
spec/factories/environments.rb
View file @
6c0fc62e
...
...
@@ -20,14 +20,18 @@ FactoryGirl.define do
after
(
:create
)
do
|
environment
,
evaluator
|
pipeline
=
create
(
:ci_pipeline
,
project:
environment
.
project
)
deployable
=
create
(
:ci_build
,
name:
"
#{
environment
.
name
}
:deploy"
,
pipeline:
pipeline
)
deployment
=
create
(
:deployment
,
environment:
environment
,
project:
environment
.
project
,
deployable:
deployable
,
ref:
evaluator
.
ref
,
sha:
environment
.
project
.
commit
(
evaluator
.
ref
).
id
)
teardown_build
=
create
(
:ci_build
,
:manual
,
name:
"
#{
deployment
.
environment
.
name
}
:teardown"
,
name:
"
#{
environment
.
name
}
:teardown"
,
pipeline:
pipeline
)
deployment
.
update_column
(
:on_stop
,
teardown_build
.
name
)
...
...
spec/models/environment_spec.rb
View file @
6c0fc62e
...
...
@@ -155,6 +155,31 @@ describe Environment, models: true do
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
let
(
:user
)
{
create
(
:admin
)
}
...
...
spec/services/ci/stop_environments_service_spec.rb
View file @
6c0fc62e
...
...
@@ -55,8 +55,22 @@ describe Ci::StopEnvironmentsService, services: true do
end
context
'when user does not have permission to stop environment'
do
context
'when user has no access to manage deployments'
do
before
do
project
.
team
<<
[
user
,
:guest
]
end
it
'does not stop environment'
do
expect_environment_not_stopped_on
(
'master'
)
end
end
end
context
'when branch for stop action is protected'
do
before
do
project
.
team
<<
[
user
,
:guest
]
project
.
add_developer
(
user
)
create
(
:protected_branch
,
:no_one_can_push
,
name:
'master'
,
project:
project
)
end
it
'does not stop environment'
do
...
...
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