Commit a2deab8f authored by Markus Koller's avatar Markus Koller

Merge branch '218695-autofix-settings-permissions-fe' into 'master'

Disable auto-fix settings toggle for unauthorized users

See merge request gitlab-org/gitlab!32789
parents 30793167 4560589b
...@@ -40,6 +40,10 @@ export default { ...@@ -40,6 +40,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
canToggleAutoFixSettings: {
type: Boolean,
required: true,
},
}, },
data() { data() {
// In this first iteration, the auto-fix settings is toggled for all features at once via a // In this first iteration, the auto-fix settings is toggled for all features at once via a
...@@ -52,6 +56,11 @@ export default { ...@@ -52,6 +56,11 @@ export default {
autoFixStatusLoading: false, autoFixStatusLoading: false,
}; };
}, },
computed: {
hasAutoFixDisabled() {
return !this.canToggleAutoFixSettings || this.autoFixStatusLoading;
},
},
methods: { methods: {
toggleAutoFix(enabled) { toggleAutoFix(enabled) {
this.autoFixStatusLoading = true; this.autoFixStatusLoading = true;
...@@ -94,11 +103,7 @@ export default { ...@@ -94,11 +103,7 @@ export default {
</gl-link> </gl-link>
</h4> </h4>
<gl-card> <gl-card>
<gl-form-checkbox <gl-form-checkbox v-model="isChecked" :disabled="hasAutoFixDisabled" @change="toggleAutoFix">
v-model="isChecked"
:disabled="autoFixStatusLoading"
@change="toggleAutoFix"
>
{{ {{
__('Automatically create merge requests for vulnerabilities that have fixes available.') __('Automatically create merge requests for vulnerabilities that have fixes available.')
}} }}
......
...@@ -17,6 +17,11 @@ export default function init() { ...@@ -17,6 +17,11 @@ export default function init() {
toggleAutofixSettingEndpoint, toggleAutofixSettingEndpoint,
} = el.dataset; } = el.dataset;
// When canToggleAutoFixSettings is false in the backend, it is undefined in the frontend,
// and when it's true in the backend, it comes in as an empty string in the frontend. The next
// line ensures that we cast it to a boolean.
const canToggleAutoFixSettings = el.dataset.canToggleAutoFixSettings !== undefined;
return new Vue({ return new Vue({
el, el,
components: { components: {
...@@ -36,6 +41,7 @@ export default function init() { ...@@ -36,6 +41,7 @@ export default function init() {
autoFixUserPath, autoFixUserPath,
containerScanningHelpPath, containerScanningHelpPath,
dependencyScanningHelpPath, dependencyScanningHelpPath,
canToggleAutoFixSettings,
toggleAutofixSettingEndpoint, toggleAutofixSettingEndpoint,
}, },
}, },
......
...@@ -52,6 +52,7 @@ module Projects ...@@ -52,6 +52,7 @@ module Projects
dependency_scanning: true, dependency_scanning: true,
container_scanning: true container_scanning: true
}.to_json, }.to_json,
can_toggle_auto_fix_settings: true, # To be replaced with the real value in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/32783
auto_fix_user_path: '/' # TODO: real link will be updated with https://gitlab.com/gitlab-org/gitlab/-/issues/215669 auto_fix_user_path: '/' # TODO: real link will be updated with https://gitlab.com/gitlab-org/gitlab/-/issues/215669
} }
end end
......
...@@ -40,6 +40,7 @@ describe('Auto-fix Settings', () => { ...@@ -40,6 +40,7 @@ describe('Auto-fix Settings', () => {
containerScanningHelpPath: CONTAINER_SCANNING_HELP_PATH, containerScanningHelpPath: CONTAINER_SCANNING_HELP_PATH,
dependencyScanningHelpPath: DEPENDENCY_SCANNING_HELP_PATH, dependencyScanningHelpPath: DEPENDENCY_SCANNING_HELP_PATH,
toggleAutofixSettingEndpoint: TOGGLE_AUTO_FIX_ENDPOINT, toggleAutofixSettingEndpoint: TOGGLE_AUTO_FIX_ENDPOINT,
canToggleAutoFixSettings: true,
...props, ...props,
}, },
}); });
...@@ -59,6 +60,8 @@ describe('Auto-fix Settings', () => { ...@@ -59,6 +60,8 @@ describe('Auto-fix Settings', () => {
.text() .text()
.trim(); .trim();
const expectCheckboxDisabled = () => expect(findCheckbox().attributes().disabled).toBeTruthy();
const toggleCheckbox = () => findCheckbox().setChecked(!wrapper.vm.autoFixEnabledLocal); const toggleCheckbox = () => findCheckbox().setChecked(!wrapper.vm.autoFixEnabledLocal);
const expectCorrectLinks = () => { const expectCorrectLinks = () => {
...@@ -101,7 +104,7 @@ describe('Auto-fix Settings', () => { ...@@ -101,7 +104,7 @@ describe('Auto-fix Settings', () => {
const itSendsPostRequest = () => { const itSendsPostRequest = () => {
it('sends a post request and sets loading state', () => { it('sends a post request and sets loading state', () => {
expect(axiosMock.history.post).toHaveLength(1); expect(axiosMock.history.post).toHaveLength(1);
expect(findCheckbox().element.disabled).toBe(true); expectCheckboxDisabled();
}); });
}; };
...@@ -133,7 +136,7 @@ describe('Auto-fix Settings', () => { ...@@ -133,7 +136,7 @@ describe('Auto-fix Settings', () => {
itShowsToggleSuccessState(); itShowsToggleSuccessState();
it('resets loading state', () => { it('resets loading state', () => {
expect(findCheckbox().element.disabled).toBe(false); expect(findCheckbox().attributes().disabled).toBeFalsy();
}); });
}); });
}); });
...@@ -161,4 +164,17 @@ describe('Auto-fix Settings', () => { ...@@ -161,4 +164,17 @@ describe('Auto-fix Settings', () => {
}); });
}, },
); );
describe("when user isn't allowed to toggle auto-fix settings", () => {
beforeEach(() => {
createComponent({
canToggleAutoFixSettings: false,
autoFixEnabled: AUTO_FIX_ENABLED_PROPS,
});
});
it('disables the checkbox', () => {
expectCheckboxDisabled();
});
});
}); });
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