Commit 8dd7b4bb authored by Phil Hughes's avatar Phil Hughes

Merge branch '322714-fix-pipeline-header-actions-showing' into 'master'

Fix pipeline header actions from showing when user does not have permission

See merge request gitlab-org/gitlab!62137
parents 3e881c3e 24245841
...@@ -132,6 +132,16 @@ export default { ...@@ -132,6 +132,16 @@ export default {
}; };
} }
}, },
canRetryPipeline() {
const { retryable, userPermissions } = this.pipeline;
return retryable && userPermissions.updatePipeline;
},
canCancelPipeline() {
const { cancelable, userPermissions } = this.pipeline;
return cancelable && userPermissions.updatePipeline;
},
}, },
watch: { watch: {
isFinished(finished) { isFinished(finished) {
...@@ -219,7 +229,7 @@ export default { ...@@ -219,7 +229,7 @@ export default {
item-name="Pipeline" item-name="Pipeline"
> >
<gl-button <gl-button
v-if="pipeline.retryable" v-if="canRetryPipeline"
:loading="isRetrying" :loading="isRetrying"
:disabled="isRetrying" :disabled="isRetrying"
category="secondary" category="secondary"
...@@ -232,7 +242,7 @@ export default { ...@@ -232,7 +242,7 @@ export default {
</gl-button> </gl-button>
<gl-button <gl-button
v-if="pipeline.cancelable" v-if="canCancelPipeline"
:loading="isCanceling" :loading="isCanceling"
:disabled="isCanceling" :disabled="isCanceling"
class="gl-ml-3" class="gl-ml-3"
......
...@@ -8,6 +8,7 @@ query getPipelineHeaderData($fullPath: ID!, $iid: ID!) { ...@@ -8,6 +8,7 @@ query getPipelineHeaderData($fullPath: ID!, $iid: ID!) {
cancelable cancelable
userPermissions { userPermissions {
destroyPipeline destroyPipeline
updatePipeline
} }
detailedStatus { detailedStatus {
detailsPath detailsPath
......
...@@ -7,7 +7,9 @@ import retryPipelineMutation from '~/pipelines/graphql/mutations/retry_pipeline. ...@@ -7,7 +7,9 @@ import retryPipelineMutation from '~/pipelines/graphql/mutations/retry_pipeline.
import { import {
mockCancelledPipelineHeader, mockCancelledPipelineHeader,
mockFailedPipelineHeader, mockFailedPipelineHeader,
mockFailedPipelineNoPermissions,
mockRunningPipelineHeader, mockRunningPipelineHeader,
mockRunningPipelineNoPermissions,
mockSuccessfulPipelineHeader, mockSuccessfulPipelineHeader,
} from './mock_data'; } from './mock_data';
...@@ -168,5 +170,19 @@ describe('Pipeline details header', () => { ...@@ -168,5 +170,19 @@ describe('Pipeline details header', () => {
}); });
}); });
}); });
describe('Permissions', () => {
it('should not display the cancel action if user does not have permission', () => {
wrapper = createComponent(mockRunningPipelineNoPermissions);
expect(findCancelButton().exists()).toBe(false);
});
it('should not display the retry action if user does not have permission', () => {
wrapper = createComponent(mockFailedPipelineNoPermissions);
expect(findRetryButton().exists()).toBe(false);
});
});
}); });
}); });
...@@ -10,6 +10,7 @@ export const mockPipelineHeader = { ...@@ -10,6 +10,7 @@ export const mockPipelineHeader = {
id: 123, id: 123,
userPermissions: { userPermissions: {
destroyPipeline: true, destroyPipeline: true,
updatePipeline: true,
}, },
createdAt: threeWeeksAgo.toISOString(), createdAt: threeWeeksAgo.toISOString(),
user: { user: {
...@@ -34,6 +35,31 @@ export const mockFailedPipelineHeader = { ...@@ -34,6 +35,31 @@ export const mockFailedPipelineHeader = {
}, },
}; };
export const mockFailedPipelineNoPermissions = {
id: 123,
userPermissions: {
destroyPipeline: false,
updatePipeline: false,
},
createdAt: threeWeeksAgo.toISOString(),
user: {
name: 'Foo',
username: 'foobar',
email: 'foo@bar.com',
avatarUrl: 'link',
},
status: PIPELINE_RUNNING,
retryable: true,
cancelable: false,
detailedStatus: {
group: 'running',
icon: 'status_running',
label: 'running',
text: 'running',
detailsPath: 'path',
},
};
export const mockRunningPipelineHeader = { export const mockRunningPipelineHeader = {
...mockPipelineHeader, ...mockPipelineHeader,
status: PIPELINE_RUNNING, status: PIPELINE_RUNNING,
...@@ -48,6 +74,31 @@ export const mockRunningPipelineHeader = { ...@@ -48,6 +74,31 @@ export const mockRunningPipelineHeader = {
}, },
}; };
export const mockRunningPipelineNoPermissions = {
id: 123,
userPermissions: {
destroyPipeline: false,
updatePipeline: false,
},
createdAt: threeWeeksAgo.toISOString(),
user: {
name: 'Foo',
username: 'foobar',
email: 'foo@bar.com',
avatarUrl: 'link',
},
status: PIPELINE_RUNNING,
retryable: false,
cancelable: true,
detailedStatus: {
group: 'running',
icon: 'status_running',
label: 'running',
text: 'running',
detailsPath: 'path',
},
};
export const mockCancelledPipelineHeader = { export const mockCancelledPipelineHeader = {
...mockPipelineHeader, ...mockPipelineHeader,
status: PIPELINE_CANCELED, status: PIPELINE_CANCELED,
......
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