Remove deleted rules for the new added section

Bug: Issue 11339
Change-Id: Ief0944afe03c55a3ee48b7ed23a3997c569b3354
(cherry picked from commit 324adea67b)
This commit is contained in:
Tao Zhou
2019-08-26 20:13:56 +02:00
committed by Paladox none
parent eca3a9db67
commit a25a84c0ee
2 changed files with 72 additions and 0 deletions

View File

@@ -342,6 +342,12 @@
} else if (obj[k].added) {
this._updateAddRemoveObj(addRemoveObj,
path.concat(ref), 'add', obj[k]);
/**
* As add / delete both can happen in the new section,
* so here to make sure it will remove the deleted ones.
* @see Issue 11339
*/
this._recursivelyRemoveDeleted(addRemoveObj.add[k]);
continue;
}
this._recursivelyUpdateAddRemoveObj(obj[k], addRemoveObj,

View File

@@ -414,6 +414,72 @@ limitations under the License.
assert.deepEqual(obj, expectedResult);
});
test('_recursivelyUpdateAddRemoveObj on new added section', () => {
const obj = {
'refs/for/*': {
permissions: {
'label-Code-Review': {
rules: {
e798fed07afbc9173a587f876ef8760c78d240c1: {
min: -2,
max: 2,
action: 'ALLOW',
added: true,
},
},
added: true,
label: 'Code-Review',
},
'labelAs-Code-Review': {
rules: {
'ldap:gerritcodereview-eng': {
min: -2,
max: 2,
action: 'ALLOW',
added: true,
deleted: true,
},
},
added: true,
label: 'Code-Review',
},
},
added: true,
},
};
const expectedResult = {
add: {
'refs/for/*': {
permissions: {
'label-Code-Review': {
rules: {
e798fed07afbc9173a587f876ef8760c78d240c1: {
min: -2,
max: 2,
action: 'ALLOW',
added: true,
},
},
added: true,
label: 'Code-Review',
},
'labelAs-Code-Review': {
rules: {},
added: true,
label: 'Code-Review',
},
},
added: true,
},
},
remove: {},
};
const updateObj = {add: {}, remove: {}};
element._recursivelyUpdateAddRemoveObj(obj, updateObj);
assert.deepEqual(updateObj, expectedResult);
});
test('_handleSaveForReview with no changes', () => {
assert.deepEqual(element._computeAddAndRemove(), {add: {}, remove: {}});
});