Commit 727830ed authored by Allen Cook's avatar Allen Cook Committed by Jacques Erasmus

Move read permission check for environments to backend

parent 6f2ab170
...@@ -22,10 +22,6 @@ export default { ...@@ -22,10 +22,6 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
canReadEnvironment: {
type: Boolean,
required: true,
},
}, },
methods: { methods: {
onChangePage(page) { onChangePage(page) {
...@@ -42,7 +38,7 @@ export default { ...@@ -42,7 +38,7 @@ export default {
<slot name="empty-state"></slot> <slot name="empty-state"></slot>
<div v-if="!isLoading && environments.length > 0" class="table-holder"> <div v-if="!isLoading && environments.length > 0" class="table-holder">
<environment-table :environments="environments" :can-read-environment="canReadEnvironment" /> <environment-table :environments="environments" />
<table-pagination <table-pagination
v-if="pagination && pagination.totalPages > 1" v-if="pagination && pagination.totalPages > 1"
......
...@@ -48,12 +48,6 @@ export default { ...@@ -48,12 +48,6 @@ export default {
mixins: [timeagoMixin], mixins: [timeagoMixin],
props: { props: {
canReadEnvironment: {
type: Boolean,
required: false,
default: false,
},
model: { model: {
type: Object, type: Object,
required: true, required: true,
...@@ -790,14 +784,14 @@ export default { ...@@ -790,14 +784,14 @@ export default {
/> />
<external-url-component <external-url-component
v-if="externalURL && canReadEnvironment" v-if="externalURL"
:external-url="externalURL" :external-url="externalURL"
data-track-action="click_button" data-track-action="click_button"
data-track-label="environment_url" data-track-label="environment_url"
/> />
<monitoring-button-component <monitoring-button-component
v-if="monitoringUrl && canReadEnvironment" v-if="monitoringUrl"
:monitoring-url="monitoringUrl" :monitoring-url="monitoringUrl"
data-track-action="click_button" data-track-action="click_button"
data-track-label="environment_monitoring" data-track-label="environment_monitoring"
......
...@@ -52,10 +52,6 @@ export default { ...@@ -52,10 +52,6 @@ export default {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
canReadEnvironment: {
type: Boolean,
required: true,
},
newEnvironmentPath: { newEnvironmentPath: {
type: String, type: String,
required: true, required: true,
...@@ -210,7 +206,6 @@ export default { ...@@ -210,7 +206,6 @@ export default {
:is-loading="isLoading" :is-loading="isLoading"
:environments="state.environments" :environments="state.environments"
:pagination="state.paginationInformation" :pagination="state.paginationInformation"
:can-read-environment="canReadEnvironment"
@onChangePage="onChangePage" @onChangePage="onChangePage"
> >
<template v-if="!isLoading && state.environments.length === 0" #empty-state> <template v-if="!isLoading && state.environments.length === 0" #empty-state>
......
...@@ -27,10 +27,6 @@ export default { ...@@ -27,10 +27,6 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
canReadEnvironment: {
type: Boolean,
required: true,
},
canAdminEnvironment: { canAdminEnvironment: {
type: Boolean, type: Boolean,
required: true, required: true,
...@@ -84,7 +80,7 @@ export default { ...@@ -84,7 +80,7 @@ export default {
return this.environment.isAvailable && Boolean(this.environment.autoStopAt); return this.environment.isAvailable && Boolean(this.environment.autoStopAt);
}, },
shouldShowExternalUrlButton() { shouldShowExternalUrlButton() {
return this.canReadEnvironment && Boolean(this.environment.externalUrl); return Boolean(this.environment.externalUrl);
}, },
shouldShowStopButton() { shouldShowStopButton() {
return this.canStopEnvironment && this.environment.isAvailable; return this.canStopEnvironment && this.environment.isAvailable;
...@@ -138,7 +134,7 @@ export default { ...@@ -138,7 +134,7 @@ export default {
>{{ $options.i18n.externalButtonText }}</gl-button >{{ $options.i18n.externalButtonText }}</gl-button
> >
<gl-button <gl-button
v-if="canReadEnvironment" v-if="shouldShowExternalUrlButton"
data-testid="metrics-button" data-testid="metrics-button"
:href="metricsPath" :href="metricsPath"
:title="$options.i18n.metricsButtonTitle" :title="$options.i18n.metricsButtonTitle"
......
...@@ -23,11 +23,6 @@ export default { ...@@ -23,11 +23,6 @@ export default {
required: true, required: true,
default: () => [], default: () => [],
}, },
canReadEnvironment: {
type: Boolean,
required: false,
default: false,
},
}, },
data() { data() {
return { return {
...@@ -155,7 +150,6 @@ export default { ...@@ -155,7 +150,6 @@ export default {
<environment-item <environment-item
:key="`environment-item-${i}`" :key="`environment-item-${i}`"
:model="model" :model="model"
:can-read-environment="canReadEnvironment"
:table-data="tableData" :table-data="tableData"
data-qa-selector="environment_item" data-qa-selector="environment_item"
/> />
...@@ -191,7 +185,6 @@ export default { ...@@ -191,7 +185,6 @@ export default {
<environment-item <environment-item
:key="`environment-row-${i}-${index}`" :key="`environment-row-${i}-${index}`"
:model="child" :model="child"
:can-read-environment="canReadEnvironment"
:table-data="tableData" :table-data="tableData"
data-qa-selector="environment_item" data-qa-selector="environment_item"
/> />
......
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { parseBoolean } from '../../lib/utils/common_utils';
import Translate from '../../vue_shared/translate'; import Translate from '../../vue_shared/translate';
import environmentsFolderApp from './environments_folder_view.vue'; import environmentsFolderApp from './environments_folder_view.vue';
...@@ -31,7 +30,6 @@ export default () => { ...@@ -31,7 +30,6 @@ export default () => {
endpoint: environmentsData.environmentsDataEndpoint, endpoint: environmentsData.environmentsDataEndpoint,
folderName: environmentsData.environmentsDataFolderName, folderName: environmentsData.environmentsDataFolderName,
cssContainerClass: environmentsData.cssClass, cssContainerClass: environmentsData.cssClass,
canReadEnvironment: parseBoolean(environmentsData.environmentsDataCanReadEnvironment),
}; };
}, },
render(createElement) { render(createElement) {
...@@ -40,7 +38,6 @@ export default () => { ...@@ -40,7 +38,6 @@ export default () => {
endpoint: this.endpoint, endpoint: this.endpoint,
folderName: this.folderName, folderName: this.folderName,
cssContainerClass: this.cssContainerClass, cssContainerClass: this.cssContainerClass,
canReadEnvironment: this.canReadEnvironment,
}, },
}); });
}, },
......
...@@ -30,10 +30,6 @@ export default { ...@@ -30,10 +30,6 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
canReadEnvironment: {
type: Boolean,
required: true,
},
}, },
methods: { methods: {
successCallback(resp) { successCallback(resp) {
...@@ -72,7 +68,6 @@ export default { ...@@ -72,7 +68,6 @@ export default {
:is-loading="isLoading" :is-loading="isLoading"
:environments="state.environments" :environments="state.environments"
:pagination="state.paginationInformation" :pagination="state.paginationInformation"
:can-read-environment="canReadEnvironment"
@onChangePage="onChangePage" @onChangePage="onChangePage"
/> />
</div> </div>
......
...@@ -32,7 +32,6 @@ export default () => { ...@@ -32,7 +32,6 @@ export default () => {
newEnvironmentPath: environmentsData.newEnvironmentPath, newEnvironmentPath: environmentsData.newEnvironmentPath,
helpPagePath: environmentsData.helpPagePath, helpPagePath: environmentsData.helpPagePath,
canCreateEnvironment: parseBoolean(environmentsData.canCreateEnvironment), canCreateEnvironment: parseBoolean(environmentsData.canCreateEnvironment),
canReadEnvironment: parseBoolean(environmentsData.canReadEnvironment),
}; };
}, },
render(createElement) { render(createElement) {
...@@ -42,7 +41,6 @@ export default () => { ...@@ -42,7 +41,6 @@ export default () => {
newEnvironmentPath: this.newEnvironmentPath, newEnvironmentPath: this.newEnvironmentPath,
helpPagePath: this.helpPagePath, helpPagePath: this.helpPagePath,
canCreateEnvironment: this.canCreateEnvironment, canCreateEnvironment: this.canCreateEnvironment,
canReadEnvironment: this.canReadEnvironment,
}, },
}); });
}, },
......
...@@ -36,7 +36,6 @@ export const initHeader = () => { ...@@ -36,7 +36,6 @@ export const initHeader = () => {
environment: this.environment, environment: this.environment,
canDestroyEnvironment: dataset.canDestroyEnvironment, canDestroyEnvironment: dataset.canDestroyEnvironment,
canUpdateEnvironment: dataset.canUpdateEnvironment, canUpdateEnvironment: dataset.canUpdateEnvironment,
canReadEnvironment: dataset.canReadEnvironment,
canStopEnvironment: dataset.canStopEnvironment, canStopEnvironment: dataset.canStopEnvironment,
canAdminEnvironment: dataset.canAdminEnvironment, canAdminEnvironment: dataset.canAdminEnvironment,
cancelAutoStopPath: dataset.environmentCancelAutoStopPath, cancelAutoStopPath: dataset.environmentCancelAutoStopPath,
......
...@@ -73,7 +73,6 @@ module EnvironmentHelper ...@@ -73,7 +73,6 @@ module EnvironmentHelper
external_url: environment.external_url, external_url: environment.external_url,
can_update_environment: can?(current_user, :update_environment, environment), can_update_environment: can?(current_user, :update_environment, environment),
can_destroy_environment: can_destroy_environment?(environment), can_destroy_environment: can_destroy_environment?(environment),
can_read_environment: can?(current_user, :read_environment, environment),
can_stop_environment: can?(current_user, :stop_environment, environment), can_stop_environment: can?(current_user, :stop_environment, environment),
can_admin_environment: can?(current_user, :admin_environment, project), can_admin_environment: can?(current_user, :admin_environment, project),
environment_metrics_path: environment_metrics_path(environment), environment_metrics_path: environment_metrics_path(environment),
......
...@@ -11,7 +11,6 @@ describe('Environment', () => { ...@@ -11,7 +11,6 @@ describe('Environment', () => {
const mockData = { const mockData = {
canCreateEnvironment: true, canCreateEnvironment: true,
canReadEnvironment: true,
endpoint: 'environments.json', endpoint: 'environments.json',
helpCanaryDeploymentsPath: 'help/canary-deployments', helpCanaryDeploymentsPath: 'help/canary-deployments',
helpPagePath: 'help', helpPagePath: 'help',
......
...@@ -36,7 +36,6 @@ describe('Environment table', () => { ...@@ -36,7 +36,6 @@ describe('Environment table', () => {
{ {
propsData: { propsData: {
environments: [mockItem], environments: [mockItem],
canReadEnvironment: true,
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments', helpCanaryDeploymentsPath: 'help/canary-deployments',
......
...@@ -31,7 +31,6 @@ describe('Environment item', () => { ...@@ -31,7 +31,6 @@ describe('Environment item', () => {
factory({ factory({
propsData: { propsData: {
model: environment, model: environment,
canReadEnvironment: true,
tableData, tableData,
}, },
}); });
...@@ -135,7 +134,6 @@ describe('Environment item', () => { ...@@ -135,7 +134,6 @@ describe('Environment item', () => {
factory({ factory({
propsData: { propsData: {
model: environmentWithoutDeployable, model: environmentWithoutDeployable,
canReadEnvironment: true,
tableData, tableData,
}, },
}); });
...@@ -161,7 +159,6 @@ describe('Environment item', () => { ...@@ -161,7 +159,6 @@ describe('Environment item', () => {
factory({ factory({
propsData: { propsData: {
model: environmentWithoutUpcomingDeployment, model: environmentWithoutUpcomingDeployment,
canReadEnvironment: true,
tableData, tableData,
}, },
}); });
...@@ -177,7 +174,6 @@ describe('Environment item', () => { ...@@ -177,7 +174,6 @@ describe('Environment item', () => {
factory({ factory({
propsData: { propsData: {
model: environment, model: environment,
canReadEnvironment: true,
tableData, tableData,
shouldShowAutoStopDate: true, shouldShowAutoStopDate: true,
}, },
...@@ -205,7 +201,6 @@ describe('Environment item', () => { ...@@ -205,7 +201,6 @@ describe('Environment item', () => {
...environment, ...environment,
auto_stop_at: futureDate, auto_stop_at: futureDate,
}, },
canReadEnvironment: true,
tableData, tableData,
shouldShowAutoStopDate: true, shouldShowAutoStopDate: true,
}, },
...@@ -241,7 +236,6 @@ describe('Environment item', () => { ...@@ -241,7 +236,6 @@ describe('Environment item', () => {
...environment, ...environment,
auto_stop_at: pastDate, auto_stop_at: pastDate,
}, },
canReadEnvironment: true,
tableData, tableData,
shouldShowAutoStopDate: true, shouldShowAutoStopDate: true,
}, },
...@@ -360,7 +354,6 @@ describe('Environment item', () => { ...@@ -360,7 +354,6 @@ describe('Environment item', () => {
factory({ factory({
propsData: { propsData: {
model: folder, model: folder,
canReadEnvironment: true,
tableData, tableData,
}, },
}); });
......
...@@ -28,7 +28,6 @@ describe('Environment table', () => { ...@@ -28,7 +28,6 @@ describe('Environment table', () => {
factory({ factory({
propsData: { propsData: {
environments: [folder], environments: [folder],
canReadEnvironment: true,
...eeOnlyProps, ...eeOnlyProps,
}, },
}); });
...@@ -50,7 +49,6 @@ describe('Environment table', () => { ...@@ -50,7 +49,6 @@ describe('Environment table', () => {
await factory({ await factory({
propsData: { propsData: {
environments: [mockItem], environments: [mockItem],
canReadEnvironment: true,
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments', helpCanaryDeploymentsPath: 'help/canary-deployments',
...@@ -78,7 +76,6 @@ describe('Environment table', () => { ...@@ -78,7 +76,6 @@ describe('Environment table', () => {
propsData: { propsData: {
environments: [mockItem], environments: [mockItem],
canCreateDeployment: false, canCreateDeployment: false,
canReadEnvironment: true,
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments', helpCanaryDeploymentsPath: 'help/canary-deployments',
...@@ -114,7 +111,6 @@ describe('Environment table', () => { ...@@ -114,7 +111,6 @@ describe('Environment table', () => {
propsData: { propsData: {
environments: [mockItem], environments: [mockItem],
canCreateDeployment: false, canCreateDeployment: false,
canReadEnvironment: true,
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments', helpCanaryDeploymentsPath: 'help/canary-deployments',
...@@ -151,7 +147,6 @@ describe('Environment table', () => { ...@@ -151,7 +147,6 @@ describe('Environment table', () => {
factory({ factory({
propsData: { propsData: {
environments: [mockItem], environments: [mockItem],
canReadEnvironment: true,
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments', helpCanaryDeploymentsPath: 'help/canary-deployments',
...@@ -179,7 +174,6 @@ describe('Environment table', () => { ...@@ -179,7 +174,6 @@ describe('Environment table', () => {
propsData: { propsData: {
environments: [mockItem], environments: [mockItem],
canCreateDeployment: false, canCreateDeployment: false,
canReadEnvironment: true,
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
helpCanaryDeploymentsPath: 'help/canary-deployments', helpCanaryDeploymentsPath: 'help/canary-deployments',
...@@ -230,7 +224,6 @@ describe('Environment table', () => { ...@@ -230,7 +224,6 @@ describe('Environment table', () => {
factory({ factory({
propsData: { propsData: {
environments: mockItems, environments: mockItems,
canReadEnvironment: true,
...eeOnlyProps, ...eeOnlyProps,
}, },
}); });
...@@ -296,7 +289,6 @@ describe('Environment table', () => { ...@@ -296,7 +289,6 @@ describe('Environment table', () => {
factory({ factory({
propsData: { propsData: {
environments: mockItems, environments: mockItems,
canReadEnvironment: true,
...eeOnlyProps, ...eeOnlyProps,
}, },
}); });
...@@ -335,7 +327,6 @@ describe('Environment table', () => { ...@@ -335,7 +327,6 @@ describe('Environment table', () => {
factory({ factory({
propsData: { propsData: {
environments: mockItems, environments: mockItems,
canReadEnvironment: true,
...eeOnlyProps, ...eeOnlyProps,
}, },
}); });
...@@ -364,7 +355,6 @@ describe('Environment table', () => { ...@@ -364,7 +355,6 @@ describe('Environment table', () => {
factory({ factory({
propsData: { propsData: {
environments: mockItems, environments: mockItems,
canReadEnvironment: true,
...eeOnlyProps, ...eeOnlyProps,
}, },
}); });
...@@ -415,7 +405,6 @@ describe('Environment table', () => { ...@@ -415,7 +405,6 @@ describe('Environment table', () => {
factory({ factory({
propsData: { propsData: {
environments: mockItems, environments: mockItems,
canReadEnvironment: true,
...eeOnlyProps, ...eeOnlyProps,
}, },
}); });
......
...@@ -20,7 +20,6 @@ describe('Environment', () => { ...@@ -20,7 +20,6 @@ describe('Environment', () => {
const mockData = { const mockData = {
endpoint: 'environments.json', endpoint: 'environments.json',
canCreateEnvironment: true, canCreateEnvironment: true,
canReadEnvironment: true,
newEnvironmentPath: 'environments/new', newEnvironmentPath: 'environments/new',
helpPagePath: 'help', helpPagePath: 'help',
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
......
...@@ -44,7 +44,6 @@ describe('Environments detail header component', () => { ...@@ -44,7 +44,6 @@ describe('Environments detail header component', () => {
TimeAgo, TimeAgo,
}, },
propsData: { propsData: {
canReadEnvironment: false,
canAdminEnvironment: false, canAdminEnvironment: false,
canUpdateEnvironment: false, canUpdateEnvironment: false,
canStopEnvironment: false, canStopEnvironment: false,
...@@ -60,7 +59,7 @@ describe('Environments detail header component', () => { ...@@ -60,7 +59,7 @@ describe('Environments detail header component', () => {
describe('default state with minimal access', () => { describe('default state with minimal access', () => {
beforeEach(() => { beforeEach(() => {
createWrapper({ props: { environment: createEnvironment() } }); createWrapper({ props: { environment: createEnvironment({ externalUrl: null }) } });
}); });
it('displays the environment name', () => { it('displays the environment name', () => {
...@@ -164,7 +163,6 @@ describe('Environments detail header component', () => { ...@@ -164,7 +163,6 @@ describe('Environments detail header component', () => {
createWrapper({ createWrapper({
props: { props: {
environment: createEnvironment({ hasTerminals: true, externalUrl }), environment: createEnvironment({ hasTerminals: true, externalUrl }),
canReadEnvironment: true,
}, },
}); });
}); });
...@@ -178,8 +176,7 @@ describe('Environments detail header component', () => { ...@@ -178,8 +176,7 @@ describe('Environments detail header component', () => {
beforeEach(() => { beforeEach(() => {
createWrapper({ createWrapper({
props: { props: {
environment: createEnvironment(), environment: createEnvironment({ metricsUrl: 'my metrics url' }),
canReadEnvironment: true,
metricsPath, metricsPath,
}, },
}); });
...@@ -195,7 +192,6 @@ describe('Environments detail header component', () => { ...@@ -195,7 +192,6 @@ describe('Environments detail header component', () => {
createWrapper({ createWrapper({
props: { props: {
environment: createEnvironment(), environment: createEnvironment(),
canReadEnvironment: true,
canAdminEnvironment: true, canAdminEnvironment: true,
canStopEnvironment: true, canStopEnvironment: true,
canUpdateEnvironment: true, canUpdateEnvironment: true,
......
...@@ -11,7 +11,6 @@ describe('Environments Folder View', () => { ...@@ -11,7 +11,6 @@ describe('Environments Folder View', () => {
const mockData = { const mockData = {
endpoint: 'environments.json', endpoint: 'environments.json',
folderName: 'review', folderName: 'review',
canReadEnvironment: true,
cssContainerClass: 'container', cssContainerClass: 'container',
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
......
...@@ -14,7 +14,6 @@ describe('Environments Folder View', () => { ...@@ -14,7 +14,6 @@ describe('Environments Folder View', () => {
const mockData = { const mockData = {
endpoint: 'environments.json', endpoint: 'environments.json',
folderName: 'review', folderName: 'review',
canReadEnvironment: true,
cssContainerClass: 'container', cssContainerClass: 'container',
userCalloutsPath: '/callouts', userCalloutsPath: '/callouts',
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg', lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
......
...@@ -43,7 +43,6 @@ RSpec.describe EnvironmentHelper do ...@@ -43,7 +43,6 @@ RSpec.describe EnvironmentHelper do
external_url: environment.external_url, external_url: environment.external_url,
can_update_environment: true, can_update_environment: true,
can_destroy_environment: true, can_destroy_environment: true,
can_read_environment: true,
can_stop_environment: true, can_stop_environment: true,
can_admin_environment: true, can_admin_environment: true,
environment_metrics_path: environment_metrics_path(environment), environment_metrics_path: environment_metrics_path(environment),
......
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