BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
f7d900aa
Commit
f7d900aa
authored
Feb 07, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '24147-delete-env-button' into 'master'
Makes stop button visible in environment page Closes #24147 See merge request !7379
parents
a658654c
0886b0fe
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
111 additions
and
53 deletions
+111
-53
environment_item.js.es6
...vascripts/environments/components/environment_item.js.es6
+4
-4
environments_controller.rb
app/controllers/projects/environments_controller.rb
+8
-3
merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
deployment.rb
app/models/deployment.rb
+1
-1
environment.rb
app/models/environment.rb
+5
-5
environment_entity.rb
app/serializers/environment_entity.rb
+1
-1
stop_environments_service.rb
app/services/ci/stop_environments_service.rb
+1
-2
_stop.html.haml
app/views/projects/environments/_stop.html.haml
+1
-1
show.html.haml
app/views/projects/environments/show.html.haml
+1
-1
24147-delete-env-button.yml
changelogs/unreleased/24147-delete-env-button.yml
+4
-0
environment_spec.rb
spec/features/environment_spec.rb
+30
-18
environments_spec.rb
spec/features/environments_spec.rb
+16
-0
environment_item_spec.js.es6
spec/javascripts/environments/environment_item_spec.js.es6
+1
-1
mock_data.js.es6
spec/javascripts/environments/mock_data.js.es6
+5
-5
deployment_spec.rb
spec/models/deployment_spec.rb
+2
-2
environment_spec.rb
spec/models/environment_spec.rb
+28
-6
stop_environments_service_spec.rb
spec/services/ci/stop_environments_service_spec.rb
+2
-2
No files found.
app/assets/javascripts/environments/components/environment_item.js.es6
View file @
f7d900aa
...
...
@@ -147,12 +147,12 @@ require('./environment_terminal_button');
},
/**
* Returns the value of the `stop
pable
?` key provided in the response.
* Returns the value of the `stop
_action
?` key provided in the response.
*
* @returns {Boolean}
*/
isStoppable
() {
return this.model['stop
pable
?'];
hasStopAction
() {
return this.model['stop
_action
?'];
},
/**
...
...
@@ -508,7 +508,7 @@ require('./environment_terminal_button');
</external-url-component>
</div>
<div v-if="
isStoppable
&& canCreateDeployment"
<div v-if="
hasStopAction
&& canCreateDeployment"
class="inline js-stop-component-container">
<stop-component
:stop-url="model.stop_path">
...
...
app/controllers/projects/environments_controller.rb
View file @
f7d900aa
...
...
@@ -52,10 +52,15 @@ 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
.
stop_with_action!
(
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
def
terminal
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
f7d900aa
...
...
@@ -454,7 +454,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_commit
)
stop_url
=
if
environment
.
stop
pable
?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
if
environment
.
stop
_action
?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
stop_namespace_project_environment_path
(
project
.
namespace
,
project
,
environment
)
end
...
...
app/models/deployment.rb
View file @
f7d900aa
...
...
@@ -91,7 +91,7 @@ class Deployment < ActiveRecord::Base
@stop_action
||=
manual_actions
.
find_by
(
name:
on_stop
)
end
def
stop
pable
?
def
stop
_action
?
stop_action
.
present?
end
...
...
app/models/environment.rb
View file @
f7d900aa
...
...
@@ -110,15 +110,15 @@ class Environment < ActiveRecord::Base
external_url
.
gsub
(
/\A.*?:\/\//
,
''
)
end
def
stop
pable
?
def
stop
_action
?
available?
&&
stop_action
.
present?
end
def
stop!
(
current_user
)
return
unless
stopp
able?
def
stop
_with_action
!
(
current_user
)
return
unless
avail
able?
stop
stop_action
.
play
(
current_user
)
stop
!
stop_action
.
play
(
current_user
)
if
stop_action
end
def
actions_for
(
environment
)
...
...
app/serializers/environment_entity.rb
View file @
f7d900aa
...
...
@@ -7,7 +7,7 @@ class EnvironmentEntity < Grape::Entity
expose
:external_url
expose
:environment_type
expose
:last_deployment
,
using:
DeploymentEntity
expose
:stop
pable
?
expose
:stop
_action
?
expose
:environment_path
do
|
environment
|
namespace_project_environment_path
(
...
...
app/services/ci/stop_environments_service.rb
View file @
f7d900aa
...
...
@@ -8,10 +8,9 @@ module Ci
return
unless
has_ref?
environments
.
each
do
|
environment
|
next
unless
environment
.
stoppable?
next
unless
can?
(
current_user
,
:create_deployment
,
project
)
environment
.
stop!
(
current_user
)
environment
.
stop
_with_action
!
(
current_user
)
end
end
...
...
app/views/projects/environments/_stop.html.haml
View file @
f7d900aa
-
if
can?
(
current_user
,
:create_deployment
,
environment
)
&&
environment
.
stop
pable
?
-
if
can?
(
current_user
,
:create_deployment
,
environment
)
&&
environment
.
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 @
f7d900aa
...
...
@@ -12,7 +12,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
)
&&
@environment
.
stoppable
?
-
if
can?
(
current_user
,
:create_deployment
,
@environment
)
&&
@environment
.
can_stop
?
=
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
...
...
changelogs/unreleased/24147-delete-env-button.yml
0 → 100644
View file @
f7d900aa
---
title
:
Adds back ability to stop all environments
merge_request
:
7379
author
:
spec/features/environment_spec.rb
View file @
f7d900aa
...
...
@@ -64,10 +64,6 @@ feature 'Environment', :feature do
expect
(
page
).
to
have_link
(
'Re-deploy'
)
end
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
end
scenario
'does not show terminal button'
do
expect
(
page
).
not_to
have_terminal_button
end
...
...
@@ -116,27 +112,43 @@ feature 'Environment', :feature do
end
end
context
'with stop action'
do
given
(
:manual
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
,
name:
'close_app'
)
}
given
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
deployable:
build
,
on_stop:
'close_app'
)
}
context
'when environment is available'
do
context
'with stop action'
do
given
(
:manual
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
,
name:
'close_app'
)
}
given
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
deployable:
build
,
on_stop:
'close_app'
)
}
scenario
'does show stop button'
do
expect
(
page
).
to
have_link
(
'Stop'
)
end
scenario
'does show stop button'
do
expect
(
page
).
to
have_link
(
'Stop'
)
end
scenario
'does allow to stop environment'
do
click_link
(
'Stop'
)
scenario
'does allow to stop environment'
do
click_link
(
'Stop'
)
expect
(
page
).
to
have_content
(
'close_app'
)
end
expect
(
page
).
to
have_content
(
'close_app'
)
end
context
'for reporter'
do
let
(
:role
)
{
:reporter
}
context
'for reporter'
do
let
(
:role
)
{
:reporter
}
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
end
end
end
context
'without stop action'
do
scenario
'does allow to stop environment'
do
click_link
(
'Stop'
)
end
end
end
context
'when environment is stopped'
do
given
(
:environment
)
{
create
(
:environment
,
project:
project
,
state: :stopped
)
}
scenario
'does not show stop button'
do
expect
(
page
).
not_to
have_link
(
'Stop'
)
end
end
end
end
...
...
spec/features/environments_spec.rb
View file @
f7d900aa
...
...
@@ -52,6 +52,22 @@ feature 'Environments page', :feature, :js do
scenario
'does show no deployments'
do
expect
(
page
).
to
have_content
(
'No deployments yet'
)
end
context
'for available environment'
do
given
(
:environment
)
{
create
(
:environment
,
project:
project
,
state: :available
)
}
scenario
'does not shows stop button'
do
expect
(
page
).
not_to
have_selector
(
'.stop-env-link'
)
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_selector
(
'.stop-env-link'
)
end
end
end
context
'with deployments'
do
...
...
spec/javascripts/environments/environment_item_spec.js.es6
View file @
f7d900aa
...
...
@@ -119,7 +119,7 @@ describe('Environment item', () => {
},
],
},
'stop
pable
?': true,
'stop
_action
?': true,
environment_path: 'root/ci-folders/environments/31',
created_at: '2016-11-07T11:11:16.525Z',
updated_at: '2016-11-10T15:55:58.778Z',
...
...
spec/javascripts/environments/mock_data.js.es6
View file @
f7d900aa
...
...
@@ -50,7 +50,7 @@ const environmentsList = [
},
manual_actions: [],
},
'stop
pable
?': true,
'stop
_action
?': true,
environment_path: '/root/ci-folders/environments/31',
created_at: '2016-11-07T11:11:16.525Z',
updated_at: '2016-11-07T11:11:16.525Z',
...
...
@@ -105,7 +105,7 @@ const environmentsList = [
},
manual_actions: [],
},
'stop
pable
?': false,
'stop
_action
?': false,
environment_path: '/root/ci-folders/environments/31',
created_at: '2016-11-07T11:11:16.525Z',
updated_at: '2016-11-07T11:11:16.525Z',
...
...
@@ -116,7 +116,7 @@ const environmentsList = [
state: 'available',
environment_type: 'review',
last_deployment: null,
'stop
pable
?': true,
'stop
_action
?': true,
environment_path: '/root/ci-folders/environments/31',
created_at: '2016-11-07T11:11:16.525Z',
updated_at: '2016-11-07T11:11:16.525Z',
...
...
@@ -127,7 +127,7 @@ const environmentsList = [
state: 'available',
environment_type: 'review',
last_deployment: null,
'stop
pable
?': true,
'stop
_action
?': true,
environment_path: '/root/ci-folders/environments/31',
created_at: '2016-11-07T11:11:16.525Z',
updated_at: '2016-11-07T11:11:16.525Z',
...
...
@@ -143,7 +143,7 @@ const environment = {
external_url: 'http://production.',
environment_type: null,
last_deployment: {},
'stop
pable
?': false,
'stop
_action
?': false,
environment_path: '/root/review-app/environments/4',
stop_path: '/root/review-app/environments/4/stop',
created_at: '2016-12-16T11:51:04.690Z',
...
...
spec/models/deployment_spec.rb
View file @
f7d900aa
...
...
@@ -77,8 +77,8 @@ describe Deployment, models: true do
end
end
describe
'#stop
pable
?'
do
subject
{
deployment
.
stop
pable
?
}
describe
'#stop
_action
?'
do
subject
{
deployment
.
stop
_action
?
}
context
'when no other actions'
do
let
(
:deployment
)
{
build
(
:deployment
)
}
...
...
spec/models/environment_spec.rb
View file @
f7d900aa
...
...
@@ -112,8 +112,8 @@ describe Environment, models: true do
end
end
describe
'#stop
pable
?'
do
subject
{
environment
.
stop
pable
?
}
describe
'#stop
_action
?'
do
subject
{
environment
.
stop
_action
?
}
context
'when no other actions'
do
it
{
is_expected
.
to
be_falsey
}
...
...
@@ -142,17 +142,39 @@ describe Environment, models: true do
end
end
describe
'#stop!'
do
describe
'#stop
_with_action
!'
do
let
(
:user
)
{
create
(
:user
)
}
subject
{
environment
.
stop!
(
user
)
}
subject
{
environment
.
stop
_with_action
!
(
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
...
...
spec/services/ci/stop_environments_service_spec.rb
View file @
f7d900aa
...
...
@@ -42,10 +42,10 @@ describe Ci::StopEnvironmentsService, services: true do
end
end
context
'when environment is not stopp
able
'
do
context
'when environment is not stopp
ed
'
do
before
do
allow_any_instance_of
(
Environment
)
.
to
receive
(
:st
oppable?
).
and_return
(
false
)
.
to
receive
(
:st
ate
).
and_return
(
:stopped
)
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