Commit e6843b17 authored by Ruben Davila's avatar Ruben Davila

Check if license allows the use of Deploy Board feature

parent 42c9bde5
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]
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment