Commit 9723f5a3 authored by Payton Burdette's avatar Payton Burdette Committed by Natalia Tepluhina

Fix admin setting bug

Fix admin setting bug where
user has enviroment variables
enabled by default.
parent ee8c2f61
...@@ -46,6 +46,7 @@ export default { ...@@ -46,6 +46,7 @@ export default {
'isGroup', 'isGroup',
'maskableRegex', 'maskableRegex',
'selectedEnvironment', 'selectedEnvironment',
'isProtectedByDefault',
]), ]),
canSubmit() { canSubmit() {
return ( return (
...@@ -123,6 +124,7 @@ export default { ...@@ -123,6 +124,7 @@ export default {
'addWildCardScope', 'addWildCardScope',
'resetSelectedEnvironment', 'resetSelectedEnvironment',
'setSelectedEnvironment', 'setSelectedEnvironment',
'setVariableProtected',
]), ]),
deleteVarAndClose() { deleteVarAndClose() {
this.deleteVariable(this.variableBeingEdited); this.deleteVariable(this.variableBeingEdited);
...@@ -147,6 +149,11 @@ export default { ...@@ -147,6 +149,11 @@ export default {
} }
this.hideModal(); this.hideModal();
}, },
setVariableProtectedByDefault() {
if (this.isProtectedByDefault && !this.variableBeingEdited) {
this.setVariableProtected();
}
},
}, },
}; };
</script> </script>
...@@ -159,6 +166,7 @@ export default { ...@@ -159,6 +166,7 @@ export default {
static static
lazy lazy
@hidden="resetModalHandler" @hidden="resetModalHandler"
@shown="setVariableProtectedByDefault"
> >
<form> <form>
<ci-key-field <ci-key-field
......
...@@ -5,14 +5,16 @@ import { parseBoolean } from '~/lib/utils/common_utils'; ...@@ -5,14 +5,16 @@ import { parseBoolean } from '~/lib/utils/common_utils';
export default () => { export default () => {
const el = document.getElementById('js-ci-project-variables'); const el = document.getElementById('js-ci-project-variables');
const { endpoint, projectId, group, maskableRegex } = el.dataset; const { endpoint, projectId, group, maskableRegex, protectedByDefault } = el.dataset;
const isGroup = parseBoolean(group); const isGroup = parseBoolean(group);
const isProtectedByDefault = parseBoolean(protectedByDefault);
const store = createStore({ const store = createStore({
endpoint, endpoint,
projectId, projectId,
isGroup, isGroup,
maskableRegex, maskableRegex,
isProtectedByDefault,
}); });
return new Vue({ return new Vue({
......
...@@ -20,6 +20,10 @@ export const resetEditing = ({ commit, dispatch }) => { ...@@ -20,6 +20,10 @@ export const resetEditing = ({ commit, dispatch }) => {
commit(types.RESET_EDITING); commit(types.RESET_EDITING);
}; };
export const setVariableProtected = ({ commit }) => {
commit(types.SET_VARIABLE_PROTECTED);
};
export const requestAddVariable = ({ commit }) => { export const requestAddVariable = ({ commit }) => {
commit(types.REQUEST_ADD_VARIABLE); commit(types.REQUEST_ADD_VARIABLE);
}; };
......
...@@ -2,6 +2,7 @@ export const TOGGLE_VALUES = 'TOGGLE_VALUES'; ...@@ -2,6 +2,7 @@ export const TOGGLE_VALUES = 'TOGGLE_VALUES';
export const VARIABLE_BEING_EDITED = 'VARIABLE_BEING_EDITED'; export const VARIABLE_BEING_EDITED = 'VARIABLE_BEING_EDITED';
export const RESET_EDITING = 'RESET_EDITING'; export const RESET_EDITING = 'RESET_EDITING';
export const CLEAR_MODAL = 'CLEAR_MODAL'; export const CLEAR_MODAL = 'CLEAR_MODAL';
export const SET_VARIABLE_PROTECTED = 'SET_VARIABLE_PROTECTED';
export const REQUEST_VARIABLES = 'REQUEST_VARIABLES'; export const REQUEST_VARIABLES = 'REQUEST_VARIABLES';
export const RECEIVE_VARIABLES_SUCCESS = 'RECEIVE_VARIABLES_SUCCESS'; export const RECEIVE_VARIABLES_SUCCESS = 'RECEIVE_VARIABLES_SUCCESS';
......
...@@ -104,4 +104,8 @@ export default { ...@@ -104,4 +104,8 @@ export default {
[types.SET_SELECTED_ENVIRONMENT](state, environment) { [types.SET_SELECTED_ENVIRONMENT](state, environment) {
state.selectedEnvironment = environment; state.selectedEnvironment = environment;
}, },
[types.SET_VARIABLE_PROTECTED](state) {
state.variable.protected = true;
},
}; };
...@@ -5,6 +5,7 @@ export default () => ({ ...@@ -5,6 +5,7 @@ export default () => ({
projectId: null, projectId: null,
isGroup: null, isGroup: null,
maskableRegex: null, maskableRegex: null,
isProtectedByDefault: null,
isLoading: false, isLoading: false,
isDeleting: false, isDeleting: false,
variable: { variable: {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
- if Feature.enabled?(:new_variables_ui, @project || @group, default_enabled: true) - if Feature.enabled?(:new_variables_ui, @project || @group, default_enabled: true)
- is_group = !@group.nil? - is_group = !@group.nil?
#js-ci-project-variables{ data: { endpoint: save_endpoint, project_id: @project&.id || '', group: is_group.to_s, maskable_regex: ci_variable_maskable_regex} } #js-ci-project-variables{ data: { endpoint: save_endpoint, project_id: @project&.id || '', group: is_group.to_s, maskable_regex: ci_variable_maskable_regex, protected_by_default: ci_variable_protected_by_default?.to_s} }
- else - else
.row .row
......
---
title: Fixes bug where variables were not protected by default when using the correct
CI/CD admin setting
merge_request: 31655
author:
type: fixed
...@@ -96,6 +96,13 @@ describe('Ci variable modal', () => { ...@@ -96,6 +96,13 @@ describe('Ci variable modal', () => {
findModal().vm.$emit('hidden'); findModal().vm.$emit('hidden');
expect(store.dispatch).toHaveBeenCalledWith('clearModal'); expect(store.dispatch).toHaveBeenCalledWith('clearModal');
}); });
it('should dispatch setVariableProtected when admin settings are configured to protect variables', () => {
store.state.isProtectedByDefault = true;
findModal().vm.$emit('shown');
expect(store.dispatch).toHaveBeenCalledWith('setVariableProtected');
});
}); });
describe('Editing a variable', () => { describe('Editing a variable', () => {
......
...@@ -75,6 +75,16 @@ describe('CI variable list store actions', () => { ...@@ -75,6 +75,16 @@ describe('CI variable list store actions', () => {
}); });
}); });
describe('setVariableProtected', () => {
it('commits SET_VARIABLE_PROTECTED mutation', () => {
testAction(actions.setVariableProtected, {}, {}, [
{
type: types.SET_VARIABLE_PROTECTED,
},
]);
});
});
describe('deleteVariable', () => { describe('deleteVariable', () => {
it('dispatch correct actions on successful deleted variable', done => { it('dispatch correct actions on successful deleted variable', done => {
mock.onPatch(state.endpoint).reply(200); mock.onPatch(state.endpoint).reply(200);
......
...@@ -97,4 +97,12 @@ describe('CI variable list mutations', () => { ...@@ -97,4 +97,12 @@ describe('CI variable list mutations', () => {
expect(stateCopy.environments).toEqual(['dev', 'production', 'staging']); expect(stateCopy.environments).toEqual(['dev', 'production', 'staging']);
}); });
}); });
describe('SET_VARIABLE_PROTECTED', () => {
it('should set protected value to true', () => {
mutations[types.SET_VARIABLE_PROTECTED](stateCopy);
expect(stateCopy.variable.protected).toBe(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