Commit bfa4ebdd authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'compliance-frameworks-do-not-submit-pipeline-config-when-disabled' into 'master'

Exclude the pipeline configuration path from form submission if it is disabled

See merge request gitlab-org/gitlab!56740
parents f254fe87 377354af
...@@ -4,7 +4,7 @@ import { visitUrl } from '~/lib/utils/url_utility'; ...@@ -4,7 +4,7 @@ import { visitUrl } from '~/lib/utils/url_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { SAVE_ERROR } from '../constants'; import { SAVE_ERROR } from '../constants';
import createComplianceFrameworkMutation from '../graphql/queries/create_compliance_framework.mutation.graphql'; import createComplianceFrameworkMutation from '../graphql/queries/create_compliance_framework.mutation.graphql';
import { initialiseFormData } from '../utils'; import { getSubmissionParams, initialiseFormData } from '../utils';
import FormStatus from './form_status.vue'; import FormStatus from './form_status.vue';
import SharedForm from './shared_form.vue'; import SharedForm from './shared_form.vue';
...@@ -51,18 +51,16 @@ export default { ...@@ -51,18 +51,16 @@ export default {
this.errorMessage = ''; this.errorMessage = '';
try { try {
const { name, description, pipelineConfigurationFullPath, color } = this.formData; const params = getSubmissionParams(
this.formData,
this.pipelineConfigurationFullPathEnabled,
);
const { data } = await this.$apollo.mutate({ const { data } = await this.$apollo.mutate({
mutation: createComplianceFrameworkMutation, mutation: createComplianceFrameworkMutation,
variables: { variables: {
input: { input: {
namespacePath: this.groupPath, namespacePath: this.groupPath,
params: { params,
name,
description,
pipelineConfigurationFullPath,
color,
},
}, },
}, },
}); });
......
...@@ -7,7 +7,7 @@ import { __ } from '~/locale'; ...@@ -7,7 +7,7 @@ import { __ } from '~/locale';
import { FETCH_ERROR, SAVE_ERROR } from '../constants'; import { FETCH_ERROR, SAVE_ERROR } from '../constants';
import getComplianceFrameworkQuery from '../graphql/queries/get_compliance_framework.query.graphql'; import getComplianceFrameworkQuery from '../graphql/queries/get_compliance_framework.query.graphql';
import updateComplianceFrameworkMutation from '../graphql/queries/update_compliance_framework.mutation.graphql'; import updateComplianceFrameworkMutation from '../graphql/queries/update_compliance_framework.mutation.graphql';
import { initialiseFormData } from '../utils'; import { getSubmissionParams, initialiseFormData } from '../utils';
import FormStatus from './form_status.vue'; import FormStatus from './form_status.vue';
import SharedForm from './shared_form.vue'; import SharedForm from './shared_form.vue';
...@@ -114,18 +114,16 @@ export default { ...@@ -114,18 +114,16 @@ export default {
this.saveErrorMessage = ''; this.saveErrorMessage = '';
try { try {
const { name, description, pipelineConfigurationFullPath, color } = this.formData; const params = getSubmissionParams(
this.formData,
this.pipelineConfigurationFullPathEnabled,
);
const { data } = await this.$apollo.mutate({ const { data } = await this.$apollo.mutate({
mutation: updateComplianceFrameworkMutation, mutation: updateComplianceFrameworkMutation,
variables: { variables: {
input: { input: {
id: this.graphqlId, id: this.graphqlId,
params: { params,
name,
description,
pipelineConfigurationFullPath,
color,
},
}, },
}, },
}); });
......
...@@ -18,6 +18,16 @@ export const initialiseFormData = () => ({ ...@@ -18,6 +18,16 @@ export const initialiseFormData = () => ({
color: null, color: null,
}); });
export const getSubmissionParams = (formData, pipelineConfigurationFullPathEnabled) => {
const params = { ...formData };
if (!pipelineConfigurationFullPathEnabled) {
delete params.pipelineConfigurationFullPath;
}
return params;
};
export const getPipelineConfigurationPathParts = (path) => { export const getPipelineConfigurationPathParts = (path) => {
const [, file, group, project] = path.match(PIPELINE_CONFIGURATION_PATH_FORMAT) || []; const [, file, group, project] = path.match(PIPELINE_CONFIGURATION_PATH_FORMAT) || [];
......
...@@ -41,6 +41,43 @@ describe('Utils', () => { ...@@ -41,6 +41,43 @@ describe('Utils', () => {
}); });
}); });
describe('getSubmissionParams', () => {
const baseFormData = {
name: 'a',
description: 'b',
color: '#000',
};
it.each([true, false])(
'should return the initial object when pipelineConfigurationFullPath is undefined and pipelineConfigurationFullPathEnabled is %s',
(enabled) => {
expect(Utils.getSubmissionParams(baseFormData, enabled)).toStrictEqual(baseFormData);
},
);
it.each`
pipelineConfigurationFullPath | pipelineConfigurationFullPathEnabled
${'a/b'} | ${true}
${null} | ${true}
${'a/b'} | ${false}
${null} | ${false}
`(
'should return the correct object when pipelineConfigurationFullPathEnabled is $pipelineConfigurationFullPathEnabled',
({ pipelineConfigurationFullPath, pipelineConfigurationFullPathEnabled }) => {
const formData = Utils.getSubmissionParams(
{ ...baseFormData, pipelineConfigurationFullPath },
pipelineConfigurationFullPathEnabled,
);
if (pipelineConfigurationFullPathEnabled) {
expect(formData).toStrictEqual({ ...baseFormData, pipelineConfigurationFullPath });
} else {
expect(formData).toStrictEqual(baseFormData);
}
},
);
});
describe('getPipelineConfigurationPathParts', () => { describe('getPipelineConfigurationPathParts', () => {
it.each` it.each`
path | parts path | parts
......
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