Commit f721a111 authored by Jiaan Louw's avatar Jiaan Louw Committed by Olena Horal-Koretska

Add remove all approvals on push checkbox

- Add a new checkbox to group settings > MR approval
- Update the group approvals store to handle the new setting
- Update specs for new setting
parent b72a8bf8
...@@ -36,10 +36,14 @@ export default { ...@@ -36,10 +36,14 @@ export default {
preventAuthorApprovalDocsAnchor: preventAuthorApprovalDocsAnchor:
'allowing-merge-request-authors-to-approve-their-own-merge-requests', 'allowing-merge-request-authors-to-approve-their-own-merge-requests',
requireUserPasswordDocsAnchor: 'require-authentication-when-approving-a-merge-request', requireUserPasswordDocsAnchor: 'require-authentication-when-approving-a-merge-request',
removeApprovalsOnPushDocsAnchor: 'resetting-approvals-on-push',
}, },
i18n: { i18n: {
authorApprovalLabel: __('Prevent MR approvals by the author.'), authorApprovalLabel: __('Prevent MR approvals by the author.'),
requireUserPasswordLabel: __('Require user password for approvals.'), requireUserPasswordLabel: __('Require user password for approvals.'),
removeApprovalsOnPushLabel: __(
'Remove all approvals in a merge request when new commits are pushed to its source branch.',
),
saveChanges: __('Save changes'), saveChanges: __('Save changes'),
}, },
}; };
...@@ -60,6 +64,12 @@ export default { ...@@ -60,6 +64,12 @@ export default {
:anchor="$options.links.requireUserPasswordDocsAnchor" :anchor="$options.links.requireUserPasswordDocsAnchor"
data-testid="require-user-password" data-testid="require-user-password"
/> />
<approval-settings-checkbox
v-model="settings.removeApprovalsOnPush"
:label="$options.i18n.removeApprovalsOnPushLabel"
:anchor="$options.links.removeApprovalsOnPushDocsAnchor"
data-testid="remove-approvals-on-push"
/>
</gl-form-group> </gl-form-group>
<gl-button type="submit" variant="success" category="primary" :disabled="isLoading"> <gl-button type="submit" variant="success" category="primary" :disabled="isLoading">
{{ $options.i18n.saveChanges }} {{ $options.i18n.saveChanges }}
......
...@@ -27,6 +27,7 @@ export const updateSettings = ({ commit, state }, endpoint) => { ...@@ -27,6 +27,7 @@ export const updateSettings = ({ commit, state }, endpoint) => {
const payload = { const payload = {
allow_author_approval: !state.settings.preventAuthorApproval, allow_author_approval: !state.settings.preventAuthorApproval,
require_password_to_approve: state.settings.requireUserPassword, require_password_to_approve: state.settings.requireUserPassword,
retain_approvals_on_push: !state.settings.removeApprovalsOnPush,
}; };
commit(types.REQUEST_UPDATE_SETTINGS); commit(types.REQUEST_UPDATE_SETTINGS);
......
...@@ -7,6 +7,7 @@ export default { ...@@ -7,6 +7,7 @@ export default {
[types.RECEIVE_SETTINGS_SUCCESS](state, data) { [types.RECEIVE_SETTINGS_SUCCESS](state, data) {
state.settings.preventAuthorApproval = !data.allow_author_approval; state.settings.preventAuthorApproval = !data.allow_author_approval;
state.settings.requireUserPassword = data.require_password_to_approve; state.settings.requireUserPassword = data.require_password_to_approve;
state.settings.removeApprovalsOnPush = !data.retain_approvals_on_push;
state.isLoading = false; state.isLoading = false;
}, },
[types.RECEIVE_SETTINGS_ERROR](state) { [types.RECEIVE_SETTINGS_ERROR](state) {
...@@ -18,6 +19,7 @@ export default { ...@@ -18,6 +19,7 @@ export default {
[types.UPDATE_SETTINGS_SUCCESS](state, data) { [types.UPDATE_SETTINGS_SUCCESS](state, data) {
state.settings.preventAuthorApproval = !data.allow_author_approval; state.settings.preventAuthorApproval = !data.allow_author_approval;
state.settings.requireUserPassword = data.require_password_to_approve; state.settings.requireUserPassword = data.require_password_to_approve;
state.settings.removeApprovalsOnPush = !data.retain_approvals_on_push;
state.isLoading = false; state.isLoading = false;
}, },
[types.UPDATE_SETTINGS_ERROR](state) { [types.UPDATE_SETTINGS_ERROR](state) {
......
...@@ -50,9 +50,10 @@ describe('ApprovalSettings', () => { ...@@ -50,9 +50,10 @@ describe('ApprovalSettings', () => {
}); });
describe.each` describe.each`
testid | setting | label | anchor testid | setting | label | anchor
${'prevent-author-approval'} | ${'preventAuthorApproval'} | ${'Prevent MR approvals by the author.'} | ${'allowing-merge-request-authors-to-approve-their-own-merge-requests'} ${'prevent-author-approval'} | ${'preventAuthorApproval'} | ${'Prevent MR approvals by the author.'} | ${'allowing-merge-request-authors-to-approve-their-own-merge-requests'}
${'require-user-password'} | ${'requireUserPassword'} | ${'Require user password for approvals.'} | ${'require-authentication-when-approving-a-merge-request'} ${'require-user-password'} | ${'requireUserPassword'} | ${'Require user password for approvals.'} | ${'require-authentication-when-approving-a-merge-request'}
${'remove-approvals-on-push'} | ${'removeApprovalsOnPush'} | ${'Remove all approvals in a merge request when new commits are pushed to its source branch.'} | ${'resetting-approvals-on-push'}
`('with $testid checkbox', ({ testid, setting, label, anchor }) => { `('with $testid checkbox', ({ testid, setting, label, anchor }) => {
let checkbox = null; let checkbox = null;
......
...@@ -75,13 +75,18 @@ describe('EE approvals group settings module actions', () => { ...@@ -75,13 +75,18 @@ describe('EE approvals group settings module actions', () => {
settings: { settings: {
preventAuthorApproval: false, preventAuthorApproval: false,
requireUserPassword: false, requireUserPassword: false,
removeApprovalsOnPush: false,
}, },
}; };
}); });
describe('on success', () => { describe('on success', () => {
it('dispatches the request and updates payload', () => { it('dispatches the request and updates payload', () => {
const data = { allow_author_approval: true, require_password_to_approve: true }; const data = {
allow_author_approval: true,
require_password_to_approve: true,
retain_approvals_on_push: true,
};
mock.onPut(approvalSettingsPath).replyOnce(httpStatus.OK, data); mock.onPut(approvalSettingsPath).replyOnce(httpStatus.OK, data);
return testAction( return testAction(
......
...@@ -21,10 +21,12 @@ describe('Group settings store mutations', () => { ...@@ -21,10 +21,12 @@ describe('Group settings store mutations', () => {
mutations.RECEIVE_SETTINGS_SUCCESS(state, { mutations.RECEIVE_SETTINGS_SUCCESS(state, {
allow_author_approval: true, allow_author_approval: true,
require_password_to_approve: true, require_password_to_approve: true,
retain_approvals_on_push: true,
}); });
expect(state.settings.preventAuthorApproval).toBe(false); expect(state.settings.preventAuthorApproval).toBe(false);
expect(state.settings.requireUserPassword).toBe(true); expect(state.settings.requireUserPassword).toBe(true);
expect(state.settings.removeApprovalsOnPush).toBe(false);
expect(state.isLoading).toBe(false); expect(state.isLoading).toBe(false);
}); });
}); });
...@@ -50,10 +52,12 @@ describe('Group settings store mutations', () => { ...@@ -50,10 +52,12 @@ describe('Group settings store mutations', () => {
mutations.UPDATE_SETTINGS_SUCCESS(state, { mutations.UPDATE_SETTINGS_SUCCESS(state, {
allow_author_approval: true, allow_author_approval: true,
require_password_to_approve: true, require_password_to_approve: true,
retain_approvals_on_push: true,
}); });
expect(state.settings.preventAuthorApproval).toBe(false); expect(state.settings.preventAuthorApproval).toBe(false);
expect(state.settings.requireUserPassword).toBe(true); expect(state.settings.requireUserPassword).toBe(true);
expect(state.settings.removeApprovalsOnPush).toBe(false);
expect(state.isLoading).toBe(false); expect(state.isLoading).toBe(false);
}); });
}); });
......
...@@ -25542,6 +25542,9 @@ msgstr "" ...@@ -25542,6 +25542,9 @@ msgstr ""
msgid "Remove Zoom meeting" msgid "Remove Zoom meeting"
msgstr "" msgstr ""
msgid "Remove all approvals in a merge request when new commits are pushed to its source branch."
msgstr ""
msgid "Remove all or specific assignee(s)" msgid "Remove all or specific assignee(s)"
msgstr "" msgstr ""
......
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