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
e6843b17
Commit
e6843b17
authored
Apr 04, 2017
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if license allows the use of Deploy Board feature
parent
42c9bde5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
8 deletions
+68
-8
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+1
-0
app/policies/project_policy.rb
app/policies/project_policy.rb
+4
-0
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+6
-5
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+34
-0
spec/requests/git_http_spec.rb
spec/requests/git_http_spec.rb
+1
-1
spec/serializers/environment_entity_spec.rb
spec/serializers/environment_entity_spec.rb
+22
-2
No files found.
app/controllers/projects/environments_controller.rb
View file @
e6843b17
class
Projects::EnvironmentsController
<
Projects
::
ApplicationController
layout
'project'
before_action
:authorize_read_environment!
before_action
:authorize_read_deploy_board!
,
only: :status
before_action
:authorize_create_environment!
,
only:
[
:new
,
:create
]
before_action
:authorize_create_deployment!
,
only:
[
:stop
]
before_action
:authorize_update_environment!
,
only:
[
:edit
,
:update
]
...
...
app/policies/project_policy.rb
View file @
e6843b17
...
...
@@ -73,6 +73,10 @@ class ProjectPolicy < BasePolicy
can!
:read_environment
can!
:read_deployment
can!
:read_merge_request
if
License
.
current
&
.
add_on?
(
'GitLab_DeployBoard'
)
can!
:read_deploy_board
end
end
# Permissions given when an user is team member of a project
...
...
app/serializers/environment_entity.rb
View file @
e6843b17
...
...
@@ -39,11 +39,12 @@ class EnvironmentEntity < Grape::Entity
end
expose
:rollout_status_path
,
if:
->
(
environment
,
_
)
{
environment
.
deployment_service_ready?
}
do
|
environment
|
status_namespace_project_environment_path
(
environment
.
project
.
namespace
,
environment
.
project
,
environment
,
format: :json
)
can?
(
request
.
user
,
:read_deploy_board
,
environment
.
project
)
&&
status_namespace_project_environment_path
(
environment
.
project
.
namespace
,
environment
.
project
,
environment
,
format: :json
)
end
expose
:created_at
,
:updated_at
...
...
spec/controllers/projects/environments_controller_spec.rb
View file @
e6843b17
...
...
@@ -11,6 +11,8 @@ describe Projects::EnvironmentsController do
end
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
and_return
(
false
)
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
...
...
@@ -27,6 +29,8 @@ describe Projects::EnvironmentsController do
context
'when requesting JSON response for folders'
do
before
do
allow_any_instance_of
(
Environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
create
(
:environment
,
project:
project
,
name:
'staging/review-1'
,
state: :available
)
...
...
@@ -44,15 +48,19 @@ describe Projects::EnvironmentsController do
context
'when requesting available environments scope'
do
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_DeployBoard'
).
and_return
(
true
)
get
:index
,
environment_params
(
format: :json
,
scope: :available
)
end
it
'responds with a payload describing available environments'
do
expect
(
environments
.
count
).
to
eq
2
expect
(
environments
.
first
[
'name'
]).
to
eq
'production'
expect
(
environments
.
first
[
'latest'
][
'rollout_status_path'
]).
to
be_present
expect
(
environments
.
second
[
'name'
]).
to
eq
'staging'
expect
(
environments
.
second
[
'size'
]).
to
eq
2
expect
(
environments
.
second
[
'latest'
][
'name'
]).
to
eq
'staging/review-2'
expect
(
environments
.
second
[
'latest'
][
'rollout_status_path'
]).
to
be_present
end
it
'contains values describing environment scopes sizes'
do
...
...
@@ -78,6 +86,19 @@ describe Projects::EnvironmentsController do
expect
(
json_response
[
'stopped_count'
]).
to
eq
1
end
end
context
'when license does not has the GitLab_DeployBoard add-on'
do
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_DeployBoard'
).
and_return
(
false
)
get
:index
,
environment_params
(
format: :json
)
end
it
'does not return the rollout_status_path attribute'
do
expect
(
environments
.
first
[
'latest'
][
'rollout_status_path'
]).
to
be_blank
expect
(
environments
.
second
[
'latest'
][
'rollout_status_path'
]).
to
be_blank
end
end
end
end
...
...
@@ -233,6 +254,7 @@ describe Projects::EnvironmentsController do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_DeployBoard'
).
and_return
(
true
)
allow_any_instance_of
(
Environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
end
...
...
@@ -256,6 +278,18 @@ describe Projects::EnvironmentsController do
expect
(
response
.
status
).
to
eq
(
200
)
end
end
context
'when license does not has the GitLab_DeployBoard add-on'
do
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_DeployBoard'
).
and_return
(
false
)
end
it
'does not return any data'
do
get
:status
,
environment_params
expect
(
response
).
to
have_http_status
(
:not_found
)
end
end
end
describe
'GET #metrics'
do
...
...
spec/requests/git_http_spec.rb
View file @
e6843b17
...
...
@@ -292,7 +292,7 @@ describe 'Git HTTP requests', lib: true do
it
'responds with status 403'
do
msg
=
'No GitLab Enterprise Edition license has been provided yet. Pushing code and creation of issues and merge requests has been disabled. Ask an admin to upload a license to activate this functionality.'
allow
(
License
).
to
receive
(
:current
).
and_return
(
false
)
allow
(
License
).
to
receive
(
:current
).
and_return
(
nil
)
upload
(
path
,
env
)
do
|
response
|
expect
(
response
).
to
have_http_status
(
403
)
...
...
spec/serializers/environment_entity_spec.rb
View file @
e6843b17
require
'spec_helper'
describe
EnvironmentEntity
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:environment
)
{
create
(
:environment
)
}
let
(
:entity
)
do
described_class
.
new
(
environment
,
request:
double
(
user:
nil
))
described_class
.
new
(
environment
,
request:
double
(
user:
user
))
end
let
(
:environment
)
{
create
(
:environment
)
}
subject
{
entity
.
as_json
}
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
and_return
(
false
)
environment
.
project
.
team
<<
[
user
,
:master
]
end
it
'exposes latest deployment'
do
expect
(
subject
).
to
include
(
:last_deployment
)
end
...
...
@@ -38,6 +46,7 @@ describe EnvironmentEntity do
context
'with deployment service ready'
do
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_DeployBoard'
).
and_return
(
true
)
allow
(
environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
end
...
...
@@ -47,4 +56,15 @@ describe EnvironmentEntity do
expect
(
subject
[
:rollout_status_path
]).
to
eq
(
expected
)
end
end
context
'when license does not has the GitLab_DeployBoard add-on'
do
before
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_DeployBoard'
).
and_return
(
false
)
allow
(
environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
end
it
'does not expose rollout_status_path'
do
expect
(
subject
[
:rollout_status_path
]).
to
be_blank
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