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
6baaa8a9
Commit
6baaa8a9
authored
May 01, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new ability check for stopping environment
parent
52bfc0ef
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
8 deletions
+71
-8
app/policies/environment_policy.rb
app/policies/environment_policy.rb
+12
-1
app/services/ci/stop_environments_service.rb
app/services/ci/stop_environments_service.rb
+2
-7
spec/policies/environment_policy_spec.rb
spec/policies/environment_policy_spec.rb
+57
-0
No files found.
app/policies/environment_policy.rb
View file @
6baaa8a9
class
EnvironmentPolicy
<
BasePolicy
alias_method
:environment
,
:subject
def
rules
delegate!
@subject
.
project
delegate!
environment
.
project
if
environment
.
stop_action?
delegate!
environment
.
stop_action
end
if
can?
(
:create_deployment
)
&&
can?
(
:play_build
)
can!
:stop_environment
end
end
end
app/services/ci/stop_environments_service.rb
View file @
6baaa8a9
...
...
@@ -5,12 +5,11 @@ module Ci
def
execute
(
branch_name
)
@ref
=
branch_name
return
unless
has_ref?
return
unless
can?
(
current_user
,
:create_deployment
,
project
)
return
unless
@ref
.
present?
environments
.
each
do
|
environment
|
next
unless
environment
.
stop_action?
next
unless
can?
(
current_user
,
:
play_build
,
environment
.
stop_action
)
next
unless
can?
(
current_user
,
:
stop_environment
,
environment
)
environment
.
stop_with_action!
(
current_user
)
end
...
...
@@ -18,10 +17,6 @@ module Ci
private
def
has_ref?
@ref
.
present?
end
def
environments
@environments
||=
EnvironmentsFinder
.
new
(
project
,
current_user
,
ref:
@ref
,
recently_updated:
true
)
...
...
spec/policies/environment_policy_spec.rb
0 → 100644
View file @
6baaa8a9
require
'spec_helper'
describe
Ci
::
EnvironmentPolicy
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:environment
)
do
create
(
:environment
,
:with_review_app
,
project:
project
)
end
let
(
:policies
)
do
described_class
.
abilities
(
user
,
environment
).
to_set
end
describe
'#rules'
do
context
'when user does not have access to the project'
do
let
(
:project
)
{
create
(
:project
,
:private
)
}
it
'does not include ability to stop environment'
do
expect
(
policies
).
not_to
include
:stop_environment
end
end
context
'when anonymous user has access to the project'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
it
'does not include ability to stop environment'
do
expect
(
policies
).
not_to
include
:stop_environment
end
end
context
'when team member has access to the project'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
before
do
project
.
add_master
(
user
)
end
context
'when team member has ability to stop environment'
do
it
'does includes ability to stop environment'
do
expect
(
policies
).
to
include
:stop_environment
end
end
context
'when team member has no ability to stop environment'
do
before
do
create
(
:protected_branch
,
:no_one_can_push
,
name:
'master'
,
project:
project
)
end
it
'does not include ability to stop environment'
do
expect
(
policies
).
not_to
include
:stop_environment
end
end
end
end
end
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