Commit f84043ad authored by Lukas 'Eipi' Eipert's avatar Lukas 'Eipi' Eipert

Move permissions based on paths into vuex

Currently we define permissions in the MR Widget store and in the
entrypoint for the pipelines view. This moves this definition into a
VueX getter based on the actual paths.
parent 3e47dc4c
Pipeline #75656796 passed with stages
in 89 minutes and 6 seconds
......@@ -60,9 +60,6 @@ export default () => {
sastContainerHeadPath,
dastHelpPath,
sastContainerHelpPath,
canCreateIssue: Boolean(createVulnerabilityFeedbackIssuePath),
canCreateMergeRequest: Boolean(createVulnerabilityFeedbackMergeRequestPath),
canDismissVulnerability: Boolean(createVulnerabilityFeedbackDismissalPath),
},
on: {
updateBadgeCount: count => {
......
......@@ -276,9 +276,6 @@ export default {
:create-vulnerability-feedback-dismissal-path="mr.createVulnerabilityFeedbackDismissalPath"
:pipeline-path="mr.pipeline.path"
:pipeline-id="mr.securityReportsPipelineId"
:can-create-issue="mr.canCreateIssue"
:can-create-merge-request="mr.canCreateMergeRequest"
:can-dismiss-vulnerability="mr.canDismissVulnerability"
/>
<mr-widget-licenses
v-if="shouldRenderLicenseReport"
......
......@@ -26,10 +26,6 @@ export default class MergeRequestStore extends CEMergeRequestStore {
data.create_vulnerability_feedback_merge_request_path;
this.createVulnerabilityFeedbackDismissalPath =
data.create_vulnerability_feedback_dismissal_path;
this.canCreateIssue = Boolean(this.createVulnerabilityFeedbackIssuePath);
this.canCreateMergeRequest = Boolean(this.createVulnerabilityFeedbackMergeRequestPath);
this.canDismissVulnerability = Boolean(this.createVulnerabilityFeedbackDismissalPath);
this.canCreateFeedback = data.can_create_feedback || false;
this.visualReviewAppAvailable = Boolean(data.visual_review_app_available);
this.appUrl = gon && gon.gitlab_url;
......
......@@ -129,18 +129,6 @@ export default {
required: false,
default: undefined,
},
canDismissVulnerability: {
type: Boolean,
required: true,
},
canCreateMergeRequest: {
type: Boolean,
required: true,
},
canCreateIssue: {
type: Boolean,
required: true,
},
},
componentNames,
computed: {
......@@ -154,6 +142,9 @@ export default {
'sastContainerStatusIcon',
'dastStatusIcon',
'dependencyScanningStatusIcon',
'canCreateIssue',
'canCreateMergeRequest',
'canDismissVulnerability',
]),
...mapGetters('sast', ['groupedSastText', 'sastStatusIcon']),
securityTab() {
......
<script>
import { mapActions, mapState } from 'vuex';
import { mapActions, mapGetters, mapState } from 'vuex';
import { s__, sprintf, n__ } from '~/locale';
import createFlash from '~/flash';
import ReportSection from '~/reports/components/report_section.vue';
......@@ -101,23 +101,13 @@ export default {
required: false,
default: null,
},
canCreateIssue: {
type: Boolean,
required: true,
},
canCreateMergeRequest: {
type: Boolean,
required: true,
},
canDismissVulnerability: {
type: Boolean,
required: true,
},
},
componentNames,
computed: {
...mapState(['sast', 'dependencyScanning', 'sastContainer', 'dast', 'modal']),
...mapGetters(['canCreateIssue', 'canCreateMergeRequest', 'canDismissVulnerability']),
sastText() {
return this.summaryTextBuilder(messages.SAST, this.sast.newIssues.length);
},
......
......@@ -130,5 +130,13 @@ export const anyReportHasIssues = state =>
state.sastContainer.newIssues.length > 0 ||
state.dependencyScanning.newIssues.length > 0;
export const canCreateIssue = state => Boolean(state.createVulnerabilityFeedbackIssuePath);
export const canCreateMergeRequest = state =>
Boolean(state.createVulnerabilityFeedbackMergeRequestPath);
export const canDismissVulnerability = state =>
Boolean(state.createVulnerabilityFeedbackDismissalPath);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
......@@ -13,10 +13,14 @@ import {
dependencyScanningStatusIcon,
anyReportHasError,
summaryCounts,
canCreateIssue,
canCreateMergeRequest,
canDismissVulnerability,
} from 'ee/vue_shared/security_reports/store/getters';
const BASE_PATH = 'fake/base/path.json';
const HEAD_PATH = 'fake/head/path.json';
const MOCK_PATH = 'fake/path.json';
describe('Security reports getters', () => {
function removeBreakLine(data) {
......@@ -530,4 +534,40 @@ describe('Security reports getters', () => {
expect(noBaseInAllReports(state)).toEqual(false);
});
});
describe('canCreateIssue', () => {
it('returns false if no feedback path is defined', () => {
expect(canCreateIssue(state)).toEqual(false);
});
it('returns true if a feedback path is defined', () => {
state.createVulnerabilityFeedbackIssuePath = MOCK_PATH;
expect(canCreateIssue(state)).toEqual(true);
});
});
describe('canCreateMergeRequest', () => {
it('returns false if no feedback path is defined', () => {
expect(canCreateMergeRequest(state)).toEqual(false);
});
it('returns true if a feedback path is defined', () => {
state.createVulnerabilityFeedbackMergeRequestPath = MOCK_PATH;
expect(canCreateMergeRequest(state)).toEqual(true);
});
});
describe('canDismissVulnerability', () => {
it('returns false if no feedback path is defined', () => {
expect(canDismissVulnerability(state)).toEqual(false);
});
it('returns true if a feedback path is defined', () => {
state.createVulnerabilityFeedbackDismissalPath = MOCK_PATH;
expect(canDismissVulnerability(state)).toEqual(true);
});
});
});
......@@ -66,9 +66,6 @@ describe('Grouped security reports app', () => {
vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json',
vulnerabilityFeedbackHelpPath: 'path',
pipelineId: 123,
canCreateIssue: true,
canCreateMergeRequest: true,
canDismissVulnerability: true,
});
Promise.all([
......@@ -129,9 +126,6 @@ describe('Grouped security reports app', () => {
vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json',
vulnerabilityFeedbackHelpPath: 'path',
pipelineId: 123,
canCreateIssue: true,
canCreateMergeRequest: true,
canDismissVulnerability: true,
});
});
......@@ -180,9 +174,6 @@ describe('Grouped security reports app', () => {
vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json',
vulnerabilityFeedbackHelpPath: 'path',
pipelineId: 123,
canCreateIssue: true,
canCreateMergeRequest: true,
canDismissVulnerability: true,
});
Promise.all([
......@@ -260,9 +251,6 @@ describe('Grouped security reports app', () => {
beforeEach(() => {
vm = mountComponent(Component, {
headBlobPath: 'path',
canCreateIssue: false,
canCreateMergeRequest: false,
canDismissVulnerability: false,
pipelinePath,
});
});
......
......@@ -46,9 +46,6 @@ describe('Split security reports app', () => {
dastHelpPath: 'path',
sastContainerHelpPath: 'path',
pipelineId: 123,
canCreateIssue: true,
canCreateMergeRequest: true,
canDismissVulnerability: true,
},
});
});
......@@ -90,9 +87,6 @@ describe('Split security reports app', () => {
dastHelpPath: 'path',
sastContainerHelpPath: 'path',
pipelineId: 123,
canCreateIssue: true,
canCreateMergeRequest: true,
canDismissVulnerability: true,
},
});
});
......@@ -172,9 +166,6 @@ describe('Split security reports app', () => {
dastHelpPath: 'path',
sastContainerHelpPath: 'path',
pipelineId: 123,
canCreateIssue: true,
canCreateMergeRequest: true,
canDismissVulnerability: true,
},
});
});
......
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