Commit 0de36bd5 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ee-move-permission-check-manual-actions-on-deployments' into 'master'

Move manual actions permission check to BE

See merge request gitlab-org/gitlab-ee!9422
parents b3e21507 aed5c9ee
...@@ -22,10 +22,6 @@ export default { ...@@ -22,10 +22,6 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
canCreateDeployment: {
type: Boolean,
required: true,
},
canReadEnvironment: { canReadEnvironment: {
type: Boolean, type: Boolean,
required: true, required: true,
...@@ -75,7 +71,6 @@ export default { ...@@ -75,7 +71,6 @@ export default {
<div v-if="!isLoading && environments.length > 0" class="table-holder"> <div v-if="!isLoading && environments.length > 0" class="table-holder">
<environment-table <environment-table
:environments="environments" :environments="environments"
:can-create-deployment="canCreateDeployment"
:can-read-environment="canReadEnvironment" :can-read-environment="canReadEnvironment"
:canary-deployment-feature-id="canaryDeploymentFeatureId" :canary-deployment-feature-id="canaryDeploymentFeatureId"
:show-canary-deployment-callout="showCanaryDeploymentCallout" :show-canary-deployment-callout="showCanaryDeploymentCallout"
......
...@@ -47,12 +47,6 @@ export default { ...@@ -47,12 +47,6 @@ export default {
default: () => ({}), default: () => ({}),
}, },
canCreateDeployment: {
type: Boolean,
required: false,
default: false,
},
canReadEnvironment: { canReadEnvironment: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -151,7 +145,7 @@ export default { ...@@ -151,7 +145,7 @@ export default {
}, },
actions() { actions() {
if (!this.model || !this.model.last_deployment || !this.canCreateDeployment) { if (!this.model || !this.model.last_deployment) {
return []; return [];
} }
...@@ -576,7 +570,7 @@ export default { ...@@ -576,7 +570,7 @@ export default {
/> />
<rollback-component <rollback-component
v-if="canRetry && canCreateDeployment" v-if="canRetry"
:is-last-deployment="isLastDeployment" :is-last-deployment="isLastDeployment"
:retry-url="retryUrl" :retry-url="retryUrl"
/> />
......
...@@ -24,10 +24,6 @@ export default { ...@@ -24,10 +24,6 @@ export default {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
canCreateDeployment: {
type: Boolean,
required: true,
},
canReadEnvironment: { canReadEnvironment: {
type: Boolean, type: Boolean,
required: true, required: true,
...@@ -138,7 +134,6 @@ export default { ...@@ -138,7 +134,6 @@ export default {
:is-loading="isLoading" :is-loading="isLoading"
:environments="state.environments" :environments="state.environments"
:pagination="state.paginationInformation" :pagination="state.paginationInformation"
:can-create-deployment="canCreateDeployment"
:can-read-environment="canReadEnvironment" :can-read-environment="canReadEnvironment"
:canary-deployment-feature-id="canaryDeploymentFeatureId" :canary-deployment-feature-id="canaryDeploymentFeatureId"
:show-canary-deployment-callout="showCanaryDeploymentCallout" :show-canary-deployment-callout="showCanaryDeploymentCallout"
......
...@@ -33,12 +33,6 @@ export default { ...@@ -33,12 +33,6 @@ export default {
default: false, default: false,
}, },
canCreateDeployment: {
type: Boolean,
required: false,
default: false,
},
// ee-only start // ee-only start
canaryDeploymentFeatureId: { canaryDeploymentFeatureId: {
type: String, type: String,
...@@ -105,7 +99,6 @@ export default { ...@@ -105,7 +99,6 @@ export default {
is="environment-item" is="environment-item"
:key="`environment-item-${i}`" :key="`environment-item-${i}`"
:model="model" :model="model"
:can-create-deployment="canCreateDeployment"
:can-read-environment="canReadEnvironment" :can-read-environment="canReadEnvironment"
/> />
...@@ -135,7 +128,6 @@ export default { ...@@ -135,7 +128,6 @@ export default {
v-for="(children, index) in model.children" v-for="(children, index) in model.children"
:key="`env-item-${i}-${index}`" :key="`env-item-${i}-${index}`"
:model="children" :model="children"
:can-create-deployment="canCreateDeployment"
:can-read-environment="canReadEnvironment" :can-read-environment="canReadEnvironment"
/> />
......
...@@ -25,7 +25,6 @@ export default () => ...@@ -25,7 +25,6 @@ export default () =>
endpoint: environmentsData.environmentsDataEndpoint, endpoint: environmentsData.environmentsDataEndpoint,
folderName: environmentsData.environmentsDataFolderName, folderName: environmentsData.environmentsDataFolderName,
cssContainerClass: environmentsData.cssClass, cssContainerClass: environmentsData.cssClass,
canCreateDeployment: parseBoolean(environmentsData.environmentsDataCanCreateDeployment),
canReadEnvironment: parseBoolean(environmentsData.environmentsDataCanReadEnvironment), canReadEnvironment: parseBoolean(environmentsData.environmentsDataCanReadEnvironment),
}; };
}, },
...@@ -35,7 +34,6 @@ export default () => ...@@ -35,7 +34,6 @@ export default () =>
endpoint: this.endpoint, endpoint: this.endpoint,
folderName: this.folderName, folderName: this.folderName,
cssContainerClass: this.cssContainerClass, cssContainerClass: this.cssContainerClass,
canCreateDeployment: this.canCreateDeployment,
canReadEnvironment: this.canReadEnvironment, canReadEnvironment: this.canReadEnvironment,
// ee-only start // ee-only start
canaryDeploymentFeatureId: this.canaryDeploymentFeatureId, canaryDeploymentFeatureId: this.canaryDeploymentFeatureId,
......
...@@ -23,10 +23,6 @@ export default { ...@@ -23,10 +23,6 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
canCreateDeployment: {
type: Boolean,
required: true,
},
canReadEnvironment: { canReadEnvironment: {
type: Boolean, type: Boolean,
required: true, required: true,
...@@ -77,7 +73,6 @@ export default { ...@@ -77,7 +73,6 @@ export default {
:is-loading="isLoading" :is-loading="isLoading"
:environments="state.environments" :environments="state.environments"
:pagination="state.paginationInformation" :pagination="state.paginationInformation"
:can-create-deployment="canCreateDeployment"
:can-read-environment="canReadEnvironment" :can-read-environment="canReadEnvironment"
:canary-deployment-feature-id="canaryDeploymentFeatureId" :canary-deployment-feature-id="canaryDeploymentFeatureId"
:show-canary-deployment-callout="showCanaryDeploymentCallout" :show-canary-deployment-callout="showCanaryDeploymentCallout"
......
...@@ -27,7 +27,6 @@ export default () => ...@@ -27,7 +27,6 @@ export default () =>
helpPagePath: environmentsData.helpPagePath, helpPagePath: environmentsData.helpPagePath,
cssContainerClass: environmentsData.cssClass, cssContainerClass: environmentsData.cssClass,
canCreateEnvironment: parseBoolean(environmentsData.canCreateEnvironment), canCreateEnvironment: parseBoolean(environmentsData.canCreateEnvironment),
canCreateDeployment: parseBoolean(environmentsData.canCreateDeployment),
canReadEnvironment: parseBoolean(environmentsData.canReadEnvironment), canReadEnvironment: parseBoolean(environmentsData.canReadEnvironment),
}; };
}, },
...@@ -39,7 +38,6 @@ export default () => ...@@ -39,7 +38,6 @@ export default () =>
helpPagePath: this.helpPagePath, helpPagePath: this.helpPagePath,
cssContainerClass: this.cssContainerClass, cssContainerClass: this.cssContainerClass,
canCreateEnvironment: this.canCreateEnvironment, canCreateEnvironment: this.canCreateEnvironment,
canCreateDeployment: this.canCreateDeployment,
canReadEnvironment: this.canReadEnvironment, canReadEnvironment: this.canReadEnvironment,
// ee-only start // ee-only start
canaryDeploymentFeatureId: this.canaryDeploymentFeatureId, canaryDeploymentFeatureId: this.canaryDeploymentFeatureId,
......
...@@ -13,7 +13,6 @@ module EnvironmentsHelper ...@@ -13,7 +13,6 @@ module EnvironmentsHelper
{ {
"endpoint" => folder_project_environments_path(@project, @folder, format: :json), "endpoint" => folder_project_environments_path(@project, @folder, format: :json),
"folder-name" => @folder, "folder-name" => @folder,
"can-create-deployment" => can?(current_user, :create_deployment, @project).to_s,
"can-read-environment" => can?(current_user, :read_environment, @project).to_s "can-read-environment" => can?(current_user, :read_environment, @project).to_s
} }
end end
......
...@@ -24,6 +24,12 @@ class DeploymentEntity < Grape::Entity ...@@ -24,6 +24,12 @@ class DeploymentEntity < Grape::Entity
expose :user, using: UserEntity expose :user, using: UserEntity
expose :commit, using: CommitEntity expose :commit, using: CommitEntity
expose :deployable, using: JobEntity expose :deployable, using: JobEntity
expose :manual_actions, using: JobEntity expose :manual_actions, using: JobEntity, if: -> (*) { can_create_deployment? }
expose :scheduled_actions, using: JobEntity expose :scheduled_actions, using: JobEntity, if: -> (*) { can_create_deployment? }
private
def can_create_deployment?
can?(request.current_user, :create_deployment, request.project)
end
end end
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
- page_title _("Environments") - page_title _("Environments")
#environments-list-view{ data: { environments_data: environments_list_data, #environments-list-view{ data: { environments_data: environments_list_data,
"can-create-deployment" => can?(current_user, :create_deployment, @project).to_s,
"can-read-environment" => can?(current_user, :read_environment, @project).to_s, "can-read-environment" => can?(current_user, :read_environment, @project).to_s,
"can-create-environment" => can?(current_user, :create_environment, @project).to_s, "can-create-environment" => can?(current_user, :create_environment, @project).to_s,
"new-environment-path" => new_project_environment_path(@project), "new-environment-path" => new_project_environment_path(@project),
......
---
title: Move permission check of manual actions of deployments
merge_request: 24660
author:
type: other
...@@ -26,7 +26,6 @@ describe('Environment item', () => { ...@@ -26,7 +26,6 @@ describe('Environment item', () => {
component = new EnvironmentItem({ component = new EnvironmentItem({
propsData: { propsData: {
model: mockItem, model: mockItem,
canCreateDeployment: false,
canReadEnvironment: true, canReadEnvironment: true,
toggleDeployBoard: () => {}, toggleDeployBoard: () => {},
store: {}, store: {},
...@@ -121,7 +120,6 @@ describe('Environment item', () => { ...@@ -121,7 +120,6 @@ describe('Environment item', () => {
component = new EnvironmentItem({ component = new EnvironmentItem({
propsData: { propsData: {
model: environment, model: environment,
canCreateDeployment: true,
canReadEnvironment: true, canReadEnvironment: true,
toggleDeployBoard: () => {}, toggleDeployBoard: () => {},
store: {}, store: {},
......
...@@ -27,7 +27,6 @@ describe('Environment table', () => { ...@@ -27,7 +27,6 @@ describe('Environment table', () => {
vm = mountComponent(Component, { vm = mountComponent(Component, {
environments: [mockItem], environments: [mockItem],
canCreateDeployment: false,
canReadEnvironment: true, canReadEnvironment: true,
// ee-only start // ee-only start
canaryDeploymentFeatureId: 'canary_deployment', canaryDeploymentFeatureId: 'canary_deployment',
......
...@@ -9,7 +9,6 @@ describe('Environment', () => { ...@@ -9,7 +9,6 @@ describe('Environment', () => {
const mockData = { const mockData = {
endpoint: 'environments.json', endpoint: 'environments.json',
canCreateEnvironment: true, canCreateEnvironment: true,
canCreateDeployment: true,
canReadEnvironment: true, canReadEnvironment: true,
cssContainerClass: 'container', cssContainerClass: 'container',
newEnvironmentPath: 'environments/new', newEnvironmentPath: 'environments/new',
......
...@@ -13,7 +13,6 @@ describe('Environments Folder View', () => { ...@@ -13,7 +13,6 @@ describe('Environments Folder View', () => {
const mockData = { const mockData = {
endpoint: 'environments.json', endpoint: 'environments.json',
folderName: 'review', folderName: 'review',
canCreateDeployment: true,
canReadEnvironment: true, canReadEnvironment: true,
cssContainerClass: 'container', cssContainerClass: 'container',
// ee-only start // ee-only start
......
require 'spec_helper' require 'spec_helper'
describe DeploymentEntity do describe DeploymentEntity do
let(:user) { create(:user) } let(:user) { developer }
let(:developer) { create(:user) }
let(:reporter) { create(:user) }
let(:project) { create(:project) }
let(:request) { double('request') } let(:request) { double('request') }
let(:deployment) { create(:deployment) } let(:deployment) { create(:deployment, deployable: build, project: project) }
let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:entity) { described_class.new(deployment, request: request) } let(:entity) { described_class.new(deployment, request: request) }
subject { entity.as_json } subject { entity.as_json }
before do before do
project.add_developer(developer)
project.add_reporter(reporter)
allow(request).to receive(:current_user).and_return(user) allow(request).to receive(:current_user).and_return(user)
allow(request).to receive(:project).and_return(project)
end end
it 'exposes internal deployment id' do it 'exposes internal deployment id' do
...@@ -23,6 +31,24 @@ describe DeploymentEntity do ...@@ -23,6 +31,24 @@ describe DeploymentEntity do
expect(subject).to include(:created_at) expect(subject).to include(:created_at)
end end
context 'when the pipeline has another manual action' do
let(:other_build) { create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline) }
let!(:other_deployment) { create(:deployment, deployable: other_build) }
it 'returns another manual action' do
expect(subject[:manual_actions].count).to eq(1)
expect(subject[:manual_actions].first[:name]).to eq('another deploy')
end
context 'when user is a reporter' do
let(:user) { reporter }
it 'returns another manual action' do
expect(subject[:manual_actions]).not_to be_present
end
end
end
describe 'scheduled_actions' do describe 'scheduled_actions' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) } let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
......
...@@ -10,6 +10,10 @@ describe EnvironmentSerializer do ...@@ -10,6 +10,10 @@ describe EnvironmentSerializer do
.represent(resource) .represent(resource)
end end
before do
project.add_developer(user)
end
context 'when there is a single object provided' do context 'when there is a single object provided' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:deployable) { create(:ci_build) } let(:deployable) { create(:ci_build) }
......
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