Commit 61496e87 authored by Payton Burdette's avatar Payton Burdette Committed by Enrique Alcántara

Show error message for permissions

Show error message for permissions
when running a MR pipeline you dont
have permissions to run.

Changelog: changed
parent 6ad30931
import Visibility from 'visibilityjs'; import Visibility from 'visibilityjs';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { historyPushState, buildUrlWithCurrentLocation } from '~/lib/utils/common_utils'; import { historyPushState, buildUrlWithCurrentLocation } from '~/lib/utils/common_utils';
import httpStatusCodes from '~/lib/utils/http_status';
import Poll from '~/lib/utils/poll'; import Poll from '~/lib/utils/poll';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { validateParams } from '~/pipelines/utils'; import { validateParams } from '~/pipelines/utils';
...@@ -195,11 +196,20 @@ export default { ...@@ -195,11 +196,20 @@ export default {
this.$toast.show(TOAST_MESSAGE); this.$toast.show(TOAST_MESSAGE);
this.updateTable(); this.updateTable();
}) })
.catch(() => { .catch((e) => {
createFlash({ const unauthorized = e.response.status === httpStatusCodes.UNAUTHORIZED;
message: __( const badRequest = e.response.status === httpStatusCodes.BAD_REQUEST;
let errorMessage = __(
'An error occurred while trying to run a new pipeline for this merge request.', 'An error occurred while trying to run a new pipeline for this merge request.',
), );
if (unauthorized || badRequest) {
errorMessage = __('You do not have permission to run a pipeline on this branch.');
}
createFlash({
message: errorMessage,
}); });
}) })
.finally(() => this.store.toggleIsRunningPipeline(false)); .finally(() => this.store.toggleIsRunningPipeline(false));
......
...@@ -41056,6 +41056,9 @@ msgstr "" ...@@ -41056,6 +41056,9 @@ msgstr ""
msgid "You do not have permission to leave this %{namespaceType}." msgid "You do not have permission to leave this %{namespaceType}."
msgstr "" msgstr ""
msgid "You do not have permission to run a pipeline on this branch."
msgstr ""
msgid "You do not have permission to run the Web Terminal. Please contact a project administrator." msgid "You do not have permission to run the Web Terminal. Please contact a project administrator."
msgstr "" msgstr ""
......
...@@ -7,6 +7,8 @@ import { extendedWrapper } from 'helpers/vue_test_utils_helper'; ...@@ -7,6 +7,8 @@ import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import Api from '~/api'; import Api from '~/api';
import PipelinesTable from '~/commit/pipelines/pipelines_table.vue'; import PipelinesTable from '~/commit/pipelines/pipelines_table.vue';
import httpStatusCodes from '~/lib/utils/http_status';
import createFlash from '~/flash';
import { TOAST_MESSAGE } from '~/pipelines/constants'; import { TOAST_MESSAGE } from '~/pipelines/constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -14,6 +16,8 @@ const $toast = { ...@@ -14,6 +16,8 @@ const $toast = {
show: jest.fn(), show: jest.fn(),
}; };
jest.mock('~/flash');
describe('Pipelines table in Commits and Merge requests', () => { describe('Pipelines table in Commits and Merge requests', () => {
let wrapper; let wrapper;
let pipeline; let pipeline;
...@@ -184,11 +188,12 @@ describe('Pipelines table in Commits and Merge requests', () => { ...@@ -184,11 +188,12 @@ describe('Pipelines table in Commits and Merge requests', () => {
mergeRequestId: 3, mergeRequestId: 3,
}); });
jest.spyOn(Api, 'postMergeRequestPipeline').mockReturnValue(Promise.resolve());
await waitForPromises(); await waitForPromises();
}); });
describe('success', () => {
beforeEach(() => {
jest.spyOn(Api, 'postMergeRequestPipeline').mockReturnValue(Promise.resolve());
});
it('displays a toast message during pipeline creation', async () => { it('displays a toast message during pipeline creation', async () => {
await findRunPipelineBtn().trigger('click'); await findRunPipelineBtn().trigger('click');
...@@ -217,6 +222,30 @@ describe('Pipelines table in Commits and Merge requests', () => { ...@@ -217,6 +222,30 @@ describe('Pipelines table in Commits and Merge requests', () => {
}); });
}); });
describe('failure', () => {
const permissionsMsg = 'You do not have permission to run a pipeline on this branch.';
it.each`
status | message
${httpStatusCodes.BAD_REQUEST} | ${permissionsMsg}
${httpStatusCodes.UNAUTHORIZED} | ${permissionsMsg}
${httpStatusCodes.INTERNAL_SERVER_ERROR} | ${'An error occurred while trying to run a new pipeline for this merge request.'}
`('displays permissions error message', async ({ status, message }) => {
const response = { response: { status } };
jest
.spyOn(Api, 'postMergeRequestPipeline')
.mockImplementation(() => Promise.reject(response));
await findRunPipelineBtn().trigger('click');
await waitForPromises();
expect(createFlash).toHaveBeenCalledWith({ message });
});
});
});
describe('on click for fork merge request', () => { describe('on click for fork merge request', () => {
beforeEach(async () => { beforeEach(async () => {
pipelineCopy.flags.detached_merge_request_pipeline = true; pipelineCopy.flags.detached_merge_request_pipeline = 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