Commit d6b72d43 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '353433-fix-mirror-auth-fields' into 'master'

Fix pull/push mirror authentication fields

See merge request gitlab-org/gitlab!81419
parents 15062426 c8ce96c6
......@@ -31,36 +31,40 @@ export default class ProtectedBranchEdit {
const wrap = this.$wrap.get(0);
const forcePushToggle = initToggle(wrap.querySelector('.js-force-push-toggle'));
forcePushToggle.$on('change', (value) => {
forcePushToggle.isLoading = true;
forcePushToggle.disabled = true;
this.updateProtectedBranch(
{
allow_force_push: value,
},
() => {
forcePushToggle.isLoading = false;
forcePushToggle.disabled = false;
},
);
});
if (this.hasLicense) {
const codeOwnerToggle = initToggle(wrap.querySelector('.js-code-owner-toggle'));
codeOwnerToggle.$on('change', (value) => {
codeOwnerToggle.isLoading = true;
codeOwnerToggle.disabled = true;
if (forcePushToggle) {
forcePushToggle.$on('change', (value) => {
forcePushToggle.isLoading = true;
forcePushToggle.disabled = true;
this.updateProtectedBranch(
{
code_owner_approval_required: value,
allow_force_push: value,
},
() => {
codeOwnerToggle.isLoading = false;
codeOwnerToggle.disabled = false;
forcePushToggle.isLoading = false;
forcePushToggle.disabled = false;
},
);
});
}
if (this.hasLicense) {
const codeOwnerToggle = initToggle(wrap.querySelector('.js-code-owner-toggle'));
if (codeOwnerToggle) {
codeOwnerToggle.$on('change', (value) => {
codeOwnerToggle.isLoading = true;
codeOwnerToggle.disabled = true;
this.updateProtectedBranch(
{
code_owner_approval_required: value,
},
() => {
codeOwnerToggle.isLoading = false;
codeOwnerToggle.disabled = false;
},
);
});
}
}
}
updateProtectedBranch(formData, callback) {
......
......@@ -73,6 +73,21 @@ describe('ProtectedBranchEdit', () => {
});
});
describe('when toggles are not available in the DOM on page load', () => {
beforeEach(() => {
create({ hasLicense: true });
setFixtures('');
});
it('does not instantiate the force push toggle', () => {
expect(findForcePushToggle()).toBe(null);
});
it('does not instantiate the code owner toggle', () => {
expect(findCodeOwnerToggle()).toBe(null);
});
});
describe.each`
description | checkedOption | patchParam | finder
${'force push'} | ${'forcePushToggleChecked'} | ${'allow_force_push'} | ${findForcePushToggle}
......
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