Commit e074344f authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'pb-fix-jobs-table-vue-permissions' into 'master'

Fix user permissions for job

See merge request gitlab-org/gitlab!75751
parents e385c50a 27f65902
...@@ -64,6 +64,9 @@ export default { ...@@ -64,6 +64,9 @@ export default {
canReadJob() { canReadJob() {
return this.job.userPermissions?.readBuild; return this.job.userPermissions?.readBuild;
}, },
canUpdateJob() {
return this.job.userPermissions?.updateBuild;
},
isActive() { isActive() {
return this.job.active; return this.job.active;
}, },
...@@ -139,7 +142,7 @@ export default { ...@@ -139,7 +142,7 @@ export default {
<template> <template>
<gl-button-group> <gl-button-group>
<template v-if="canReadJob"> <template v-if="canReadJob && canUpdateJob">
<gl-button <gl-button
v-if="isActive" v-if="isActive"
data-testid="cancel-button" data-testid="cancel-button"
......
...@@ -75,6 +75,7 @@ query getJobs( ...@@ -75,6 +75,7 @@ query getJobs(
userPermissions { userPermissions {
readBuild readBuild
readJobArtifacts readJobArtifacts
updateBuild
} }
} }
} }
......
...@@ -5,7 +5,14 @@ import ActionsCell from '~/jobs/components/table/cells/actions_cell.vue'; ...@@ -5,7 +5,14 @@ import ActionsCell from '~/jobs/components/table/cells/actions_cell.vue';
import JobPlayMutation from '~/jobs/components/table/graphql/mutations/job_play.mutation.graphql'; import JobPlayMutation from '~/jobs/components/table/graphql/mutations/job_play.mutation.graphql';
import JobRetryMutation from '~/jobs/components/table/graphql/mutations/job_retry.mutation.graphql'; import JobRetryMutation from '~/jobs/components/table/graphql/mutations/job_retry.mutation.graphql';
import JobUnscheduleMutation from '~/jobs/components/table/graphql/mutations/job_unschedule.mutation.graphql'; import JobUnscheduleMutation from '~/jobs/components/table/graphql/mutations/job_unschedule.mutation.graphql';
import { playableJob, retryableJob, scheduledJob } from '../../../mock_data'; import {
playableJob,
retryableJob,
scheduledJob,
cannotRetryJob,
cannotPlayJob,
cannotPlayScheduledJob,
} from '../../../mock_data';
describe('Job actions cell', () => { describe('Job actions cell', () => {
let wrapper; let wrapper;
...@@ -57,6 +64,17 @@ describe('Job actions cell', () => { ...@@ -57,6 +64,17 @@ describe('Job actions cell', () => {
expect(findDownloadArtifactsButton().exists()).toBe(false); expect(findDownloadArtifactsButton().exists()).toBe(false);
}); });
it.each`
button | action | jobType
${findPlayButton} | ${'play'} | ${cannotPlayJob}
${findRetryButton} | ${'retry'} | ${cannotRetryJob}
${findPlayScheduledJobButton} | ${'play scheduled'} | ${cannotPlayScheduledJob}
`('does not display the $action button if user cannot update build', ({ button, jobType }) => {
createComponent(jobType);
expect(button().exists()).toBe(false);
});
it.each` it.each`
button | action | jobType button | action | jobType
${findPlayButton} | ${'play'} | ${playableJob} ${findPlayButton} | ${'play'} | ${playableJob}
......
...@@ -1563,6 +1563,7 @@ export const mockJobsQueryResponse = { ...@@ -1563,6 +1563,7 @@ export const mockJobsQueryResponse = {
userPermissions: { userPermissions: {
readBuild: true, readBuild: true,
readJobArtifacts: true, readJobArtifacts: true,
updateBuild: true,
__typename: 'JobPermissions', __typename: 'JobPermissions',
}, },
__typename: 'CiJob', __typename: 'CiJob',
...@@ -1636,10 +1637,15 @@ export const retryableJob = { ...@@ -1636,10 +1637,15 @@ export const retryableJob = {
cancelable: false, cancelable: false,
active: false, active: false,
stuck: false, stuck: false,
userPermissions: { readBuild: true, __typename: 'JobPermissions' }, userPermissions: { readBuild: true, updateBuild: true, __typename: 'JobPermissions' },
__typename: 'CiJob', __typename: 'CiJob',
}; };
export const cannotRetryJob = {
...retryableJob,
userPermissions: { readBuild: true, updateBuild: false, __typename: 'JobPermissions' },
};
export const playableJob = { export const playableJob = {
artifacts: { artifacts: {
nodes: [ nodes: [
...@@ -1700,10 +1706,25 @@ export const playableJob = { ...@@ -1700,10 +1706,25 @@ export const playableJob = {
cancelable: false, cancelable: false,
active: false, active: false,
stuck: false, stuck: false,
userPermissions: { readBuild: true, readJobArtifacts: true, __typename: 'JobPermissions' }, userPermissions: {
readBuild: true,
readJobArtifacts: true,
updateBuild: true,
__typename: 'JobPermissions',
},
__typename: 'CiJob', __typename: 'CiJob',
}; };
export const cannotPlayJob = {
...playableJob,
userPermissions: {
readBuild: true,
readJobArtifacts: true,
updateBuild: false,
__typename: 'JobPermissions',
},
};
export const scheduledJob = { export const scheduledJob = {
artifacts: { nodes: [], __typename: 'CiJobArtifactConnection' }, artifacts: { nodes: [], __typename: 'CiJobArtifactConnection' },
allowFailure: false, allowFailure: false,
...@@ -1756,6 +1777,16 @@ export const scheduledJob = { ...@@ -1756,6 +1777,16 @@ export const scheduledJob = {
cancelable: false, cancelable: false,
active: false, active: false,
stuck: false, stuck: false,
userPermissions: { readBuild: true, __typename: 'JobPermissions' }, userPermissions: { readBuild: true, updateBuild: true, __typename: 'JobPermissions' },
__typename: 'CiJob', __typename: 'CiJob',
}; };
export const cannotPlayScheduledJob = {
...scheduledJob,
userPermissions: {
readBuild: true,
readJobArtifacts: true,
updateBuild: false,
__typename: 'JobPermissions',
},
};
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