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
Tatuya Kamada
gitlab-ce
Commits
1494abe9
Commit
1494abe9
authored
Nov 10, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to stop any environment
parent
13a680e3
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
21 deletions
+66
-21
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+7
-3
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
app/models/environment.rb
app/models/environment.rb
+9
-4
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+1
-1
app/views/projects/environments/_stop.html.haml
app/views/projects/environments/_stop.html.haml
+1
-1
app/views/projects/environments/show.html.haml
app/views/projects/environments/show.html.haml
+1
-1
spec/features/environments_spec.rb
spec/features/environments_spec.rb
+18
-4
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+28
-6
No files found.
app/controllers/projects/environments_controller.rb
View file @
1494abe9
...
...
@@ -47,10 +47,14 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
def
stop
return
render_404
unless
@environment
.
stopp
able?
return
render_404
unless
@environment
.
avail
able?
new_action
=
@environment
.
stop!
(
current_user
)
redirect_to
polymorphic_path
([
project
.
namespace
.
becomes
(
Namespace
),
project
,
new_action
])
stop_action
=
@environment
.
run_stop!
(
current_user
)
if
stop_action
redirect_to
polymorphic_path
([
project
.
namespace
.
becomes
(
Namespace
),
project
,
stop_action
])
else
redirect_to
namespace_project_environment_path
(
project
.
namespace
,
project
,
@environment
)
end
end
private
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
1494abe9
...
...
@@ -436,7 +436,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_commit
)
stop_url
=
if
environment
.
stoppable
?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
if
environment
.
can_run_stop_action
?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
stop_namespace_project_environment_path
(
project
.
namespace
,
project
,
environment
)
end
...
...
app/models/environment.rb
View file @
1494abe9
...
...
@@ -85,13 +85,18 @@ class Environment < ActiveRecord::Base
external_url
.
gsub
(
/\A.*?:\/\//
,
''
)
end
def
stoppable
?
def
can_run_stop_action
?
available?
&&
stop_action
.
present?
end
def
stop!
(
current_user
)
return
unless
stopp
able?
def
run_
stop!
(
current_user
)
return
unless
avail
able?
if
stop_action
.
present?
stop_action
.
play
(
current_user
)
else
stop
nil
end
end
end
app/serializers/environment_entity.rb
View file @
1494abe9
...
...
@@ -7,7 +7,7 @@ class EnvironmentEntity < Grape::Entity
expose
:external_url
expose
:environment_type
expose
:last_deployment
,
using:
DeploymentEntity
expose
:
stoppable
?
expose
:
can_run_stop_action
?
expose
:environment_url
do
|
environment
|
namespace_project_environment_url
(
...
...
app/views/projects/environments/_stop.html.haml
View file @
1494abe9
-
if
can?
(
current_user
,
:create_deployment
,
environment
)
&&
environment
.
stoppable
?
-
if
can?
(
current_user
,
:create_deployment
,
environment
)
&&
environment
.
can_run_stop_action
?
.inline
=
link_to
stop_namespace_project_environment_path
(
@project
.
namespace
,
@project
,
environment
),
method: :post
,
class:
'btn stop-env-link'
,
rel:
'nofollow'
,
data:
{
confirm:
'Are you sure you want to stop this environment?'
}
do
...
...
app/views/projects/environments/show.html.haml
View file @
1494abe9
...
...
@@ -11,7 +11,7 @@
=
render
'projects/environments/external_url'
,
environment:
@environment
-
if
can?
(
current_user
,
:update_environment
,
@environment
)
=
link_to
'Edit'
,
edit_namespace_project_environment_path
(
@project
.
namespace
,
@project
,
@environment
),
class:
'btn'
-
if
can?
(
current_user
,
:create_deployment
,
@environment
)
-
if
can?
(
current_user
,
:create_deployment
,
@environment
)
&&
@environment
.
available?
=
link_to
'Stop'
,
stop_namespace_project_environment_path
(
@project
.
namespace
,
@project
,
@environment
),
data:
{
confirm:
'Are you sure you want to stop this environment?'
},
class:
'btn btn-danger'
,
method: :post
.deployments-container
...
...
spec/features/environments_spec.rb
View file @
1494abe9
...
...
@@ -149,6 +149,24 @@ feature 'Environments', feature: true do
scenario
'does show no deployments'
do
expect
(
page
).
to
have_content
(
'You don\'t have any deployments right now.'
)
end
context
'for available environment'
do
given
(
:environment
)
{
create
(
:environment
,
project:
project
,
state: :available
)
}
scenario
'does allow to stop environment'
do
click_link
(
'Stop'
)
expect
(
page
).
to
have_content
(
environment
.
name
.
titleize
)
end
end
context
'for stopped environment'
do
given
(
:environment
)
{
create
(
:environment
,
project:
project
,
state: :stopped
)
}
scenario
'does not shows stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
end
end
end
context
'with deployments'
do
...
...
@@ -175,10 +193,6 @@ feature 'Environments', feature: true do
expect
(
page
).
to
have_link
(
'Re-deploy'
)
end
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
end
context
'with manual action'
do
given
(
:manual
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
,
name:
'deploy to production'
)
}
...
...
spec/models/environment_spec.rb
View file @
1494abe9
...
...
@@ -99,8 +99,8 @@ describe Environment, models: true do
end
end
describe
'#
stoppable
?'
do
subject
{
environment
.
stoppable
?
}
describe
'#
can_run_stop_action
?'
do
subject
{
environment
.
can_run_stop_action
?
}
context
'when no other actions'
do
it
{
is_expected
.
to
be_falsey
}
...
...
@@ -129,17 +129,39 @@ describe Environment, models: true do
end
end
describe
'#stop!'
do
describe
'#
run_
stop!'
do
let
(
:user
)
{
create
(
:user
)
}
subject
{
environment
.
stop!
(
user
)
}
subject
{
environment
.
run_
stop!
(
user
)
}
before
do
expect
(
environment
).
to
receive
(
:
stopp
able?
).
and_call_original
expect
(
environment
).
to
receive
(
:
avail
able?
).
and_call_original
end
context
'when no other actions'
do
it
{
is_expected
.
to
be_nil
}
context
'environment is available'
do
before
do
environment
.
update
(
state: :available
)
end
it
do
subject
expect
(
environment
).
to
be_stopped
end
end
context
'environment is already stopped'
do
before
do
environment
.
update
(
state: :stopped
)
end
it
do
subject
expect
(
environment
).
to
be_stopped
end
end
end
context
'when matching action is defined'
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