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
1664354c
Commit
1664354c
authored
Feb 06, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update changes
parent
a8825f0c
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
47 additions
and
35 deletions
+47
-35
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+2
-1
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
app/models/environment.rb
app/models/environment.rb
+4
-4
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+1
-1
app/services/ci/stop_environments_service.rb
app/services/ci/stop_environments_service.rb
+1
-2
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/environment_spec.rb
spec/features/environment_spec.rb
+30
-18
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+4
-4
spec/services/ci/stop_environments_service_spec.rb
spec/services/ci/stop_environments_service_spec.rb
+2
-2
No files found.
app/controllers/projects/environments_controller.rb
View file @
1664354c
...
...
@@ -54,7 +54,8 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def
stop
return
render_404
unless
@environment
.
available?
stop_action
=
@environment
.
run_stop!
(
current_user
)
stop_action
=
@environment
.
stop_with_action!
(
current_user
)
if
stop_action
redirect_to
polymorphic_path
([
project
.
namespace
.
becomes
(
Namespace
),
project
,
stop_action
])
else
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
1664354c
...
...
@@ -451,7 +451,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_commit
)
stop_url
=
if
environment
.
can_run_stop_action
?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
if
environment
.
stoppable
?
&&
can?
(
current_user
,
:create_deployment
,
environment
)
stop_namespace_project_environment_path
(
project
.
namespace
,
project
,
environment
)
end
...
...
app/models/environment.rb
View file @
1664354c
...
...
@@ -110,15 +110,15 @@ class Environment < ActiveRecord::Base
external_url
.
gsub
(
/\A.*?:\/\//
,
''
)
end
def
can_run_
stop_action?
def
stop_action?
available?
&&
stop_action
.
present?
end
def
run_stop
!
(
current_user
)
def
stop_with_action
!
(
current_user
)
return
unless
available?
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 @
1664354c
...
...
@@ -7,7 +7,7 @@ class EnvironmentEntity < Grape::Entity
expose
:external_url
expose
:environment_type
expose
:last_deployment
,
using:
DeploymentEntity
expose
:
can_run_stop_action
?
expose
:
stoppable
?
expose
:environment_path
do
|
environment
|
namespace_project_environment_path
(
...
...
app/services/ci/stop_environments_service.rb
View file @
1664354c
...
...
@@ -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 @
1664354c
-
if
can?
(
current_user
,
:create_deployment
,
environment
)
&&
environment
.
can_run_stop_action
?
-
if
can?
(
current_user
,
:create_deployment
,
environment
)
&&
environment
.
stoppable
?
.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 @
1664354c
...
...
@@ -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
.
available
?
-
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
...
...
spec/features/environment_spec.rb
View file @
1664354c
...
...
@@ -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/models/environment_spec.rb
View file @
1664354c
...
...
@@ -112,8 +112,8 @@ describe Environment, models: true do
end
end
describe
'#
can_run_stop_action
?'
do
subject
{
environment
.
can_run_stop_action
?
}
describe
'#
stoppable
?'
do
subject
{
environment
.
stoppable
?
}
context
'when no other actions'
do
it
{
is_expected
.
to
be_falsey
}
...
...
@@ -142,10 +142,10 @@ describe Environment, models: true do
end
end
describe
'#
run_stop
!'
do
describe
'#
stop_with_action
!'
do
let
(
:user
)
{
create
(
:user
)
}
subject
{
environment
.
run_stop
!
(
user
)
}
subject
{
environment
.
stop_with_action
!
(
user
)
}
before
do
expect
(
environment
).
to
receive
(
:available?
).
and_call_original
...
...
spec/services/ci/stop_environments_service_spec.rb
View file @
1664354c
...
...
@@ -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