Commit 3cbea463 authored by Frédéric Caplette's avatar Frédéric Caplette

Merge branch '332268-fix-permissions-for-manual-job' into 'master'

Fix user permissions for pipeline graph

See merge request gitlab-org/gitlab!64125
parents da4a3249 ad434a48
...@@ -207,6 +207,7 @@ export default { ...@@ -207,6 +207,7 @@ export default {
:source-job-hovered="hoveredSourceJobName" :source-job-hovered="hoveredSourceJobName"
:pipeline-expanded="pipelineExpanded" :pipeline-expanded="pipelineExpanded"
:pipeline-id="pipeline.id" :pipeline-id="pipeline.id"
:user-permissions="pipeline.userPermissions"
@refreshPipelineGraph="$emit('refreshPipelineGraph')" @refreshPipelineGraph="$emit('refreshPipelineGraph')"
@jobHover="setJob" @jobHover="setJob"
@updateMeasurements="getMeasurements" @updateMeasurements="getMeasurements"
......
...@@ -60,6 +60,10 @@ export default { ...@@ -60,6 +60,10 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
userPermissions: {
type: Object,
required: true,
},
}, },
titleClasses: [ titleClasses: [
'gl-font-weight-bold', 'gl-font-weight-bold',
...@@ -90,6 +94,9 @@ export default { ...@@ -90,6 +94,9 @@ export default {
hasAction() { hasAction() {
return !isEmpty(this.action); return !isEmpty(this.action);
}, },
canUpdatePipeline() {
return this.userPermissions.updatePipeline;
},
}, },
errorCaptured(err, _vm, info) { errorCaptured(err, _vm, info) {
reportToSentry('stage_column_component', `error: ${err}, info: ${info}`); reportToSentry('stage_column_component', `error: ${err}, info: ${info}`);
...@@ -132,7 +139,7 @@ export default { ...@@ -132,7 +139,7 @@ export default {
> >
<div>{{ formattedTitle }}</div> <div>{{ formattedTitle }}</div>
<action-component <action-component
v-if="hasAction" v-if="hasAction && canUpdatePipeline"
:action-icon="action.icon" :action-icon="action.icon"
:tooltip-text="action.title" :tooltip-text="action.title"
:link="action.path" :link="action.path"
......
...@@ -29,6 +29,9 @@ query getPipelineDetails($projectPath: ID!, $iid: ID!) { ...@@ -29,6 +29,9 @@ query getPipelineDetails($projectPath: ID!, $iid: ID!) {
iid iid
complete complete
usesNeeds usesNeeds
userPermissions {
updatePipeline
}
downstream { downstream {
__typename __typename
nodes { nodes {
......
...@@ -12,6 +12,10 @@ export const mockPipelineResponse = { ...@@ -12,6 +12,10 @@ export const mockPipelineResponse = {
usesNeeds: true, usesNeeds: true,
downstream: null, downstream: null,
upstream: null, upstream: null,
userPermissions: {
__typename: 'PipelinePermissions',
updatePipeline: true,
},
stages: { stages: {
__typename: 'CiStageConnection', __typename: 'CiStageConnection',
nodes: [ nodes: [
...@@ -573,6 +577,10 @@ export const wrappedPipelineReturn = { ...@@ -573,6 +577,10 @@ export const wrappedPipelineReturn = {
iid: '38', iid: '38',
complete: true, complete: true,
usesNeeds: true, usesNeeds: true,
userPermissions: {
__typename: 'PipelinePermissions',
updatePipeline: true,
},
downstream: { downstream: {
__typename: 'PipelineConnection', __typename: 'PipelineConnection',
nodes: [], nodes: [],
......
...@@ -31,6 +31,9 @@ const defaultProps = { ...@@ -31,6 +31,9 @@ const defaultProps = {
name: 'Fish', name: 'Fish',
groups: mockGroups, groups: mockGroups,
pipelineId: 159, pipelineId: 159,
userPermissions: {
updatePipeline: true,
},
}; };
describe('stage column component', () => { describe('stage column component', () => {
...@@ -152,36 +155,52 @@ describe('stage column component', () => { ...@@ -152,36 +155,52 @@ describe('stage column component', () => {
}); });
describe('with action', () => { describe('with action', () => {
beforeEach(() => { const defaults = {
groups: [
{
id: 4259,
name: '<img src=x onerror=alert(document.domain)>',
status: {
icon: 'status_success',
label: 'success',
tooltip: '<img src=x onerror=alert(document.domain)>',
},
jobs: [mockJob],
},
],
title: 'test',
hasTriggeredBy: false,
action: {
icon: 'play',
title: 'Play all',
path: 'action',
},
};
it('renders action button if permissions are permitted', () => {
createComponent({ createComponent({
method: mount, method: mount,
props: { props: {
groups: [ ...defaults,
{
id: 4259,
name: '<img src=x onerror=alert(document.domain)>',
status: {
icon: 'status_success',
label: 'success',
tooltip: '<img src=x onerror=alert(document.domain)>',
},
jobs: [mockJob],
},
],
title: 'test',
hasTriggeredBy: false,
action: {
icon: 'play',
title: 'Play all',
path: 'action',
},
}, },
}); });
});
it('renders action button', () => {
expect(findActionComponent().exists()).toBe(true); expect(findActionComponent().exists()).toBe(true);
}); });
it('does not render action button if permissions are not permitted', () => {
createComponent({
method: mount,
props: {
...defaults,
userPermissions: {
updatePipeline: false,
},
},
});
expect(findActionComponent().exists()).toBe(false);
});
}); });
describe('without action', () => { describe('without action', () => {
......
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