diff --git a/polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js b/polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js index b99327ce25..2ba1eedb44 100644 --- a/polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js +++ b/polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js @@ -95,6 +95,10 @@ if (!permission.value.label) { return; } const labelName = permission.value.label; + + // It is possible to have a label name that is not included in the + // 'labels' object. In this case, treat it like anything else. + if (!labels[labelName]) { return; } const label = { name: labelName, values: this._computeLabelValues(labels[labelName].values), diff --git a/polygerrit-ui/app/elements/admin/gr-permission/gr-permission_test.html b/polygerrit-ui/app/elements/admin/gr-permission/gr-permission_test.html index 73eac54adb..179d221fd9 100644 --- a/polygerrit-ui/app/elements/admin/gr-permission/gr-permission_test.html +++ b/polygerrit-ui/app/elements/admin/gr-permission/gr-permission_test.html @@ -101,7 +101,7 @@ limitations under the License. }, }, }; - const permission = { + let permission = { id: 'label-Code-Review', value: { label: 'Code-Review', @@ -140,6 +140,25 @@ limitations under the License. assert.deepEqual(element._computeLabel(permission, labels), expectedLabel); + + permission = { + id: 'label-reviewDB', + value: { + label: 'reviewDB', + rules: { + 'global:Project-Owners': { + action: 'ALLOW', + force: false, + }, + '4c97682e6ce6b7247f3381b6f1789356666de7f': { + action: 'ALLOW', + force: false, + }, + }, + }, + }; + + assert.isNotOk(element._computeLabel(permission, labels)); }); test('_computeSectionClass', () => { diff --git a/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access.js b/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access.js index 470cf70e1d..d736dac7df 100644 --- a/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access.js +++ b/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access.js @@ -55,9 +55,8 @@ _projectChanged(project) { if (!project) { return Promise.resolve(); } const promises = []; - if (!this._sections) { - this._sections = []; - } + // Always reset sections when a project changes. + this._sections = []; promises.push(this.$.restAPI.getProjectAccessRights(project).then(res => { this._inheritsFrom = res.inherits_from; this._local = res.local; @@ -77,15 +76,10 @@ this._isAdmin = isAdmin; })); - return Promise.all(promises).then(value => { - this._capabilities = value[1]; - this._labels = value[2]; - - // Use splice instead of setting _sections directly so that dom-repeat - // renders new sections properly. Otherwise, gr-access-section is not - // aware that the section has updated. - this.splice(...['_sections', 0, this._sections.length] - .concat(value[0])); + return Promise.all(promises).then(([sections, capabilities, labels]) => { + this._capabilities = capabilities; + this._labels = labels; + this._sections = sections; }); }, diff --git a/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access_test.html b/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access_test.html index e3aa29a6a5..8ea14cf781 100644 --- a/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access_test.html +++ b/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access_test.html @@ -58,14 +58,33 @@ limitations under the License. id: 'accessDatabase', name: 'Access Database', }, + createAccount: { + id: 'createAccount', + name: 'Create Account', + }, }; const accessRes = { + local: { + 'refs/*': { + permissions: { + owner: { + rules: { + 234: {}, + }, + }, + }, + }, + }, + }; + const accessRes2 = { local: { GLOBAL_CAPABILITIES: { permissions: { accessDatabase: { rules: { - 123: {}, + group1: { + action: 'ALLOW', + }, }, }, }, @@ -78,9 +97,15 @@ limitations under the License. }, }; const accessStub = sandbox.stub(element.$.restAPI, - 'getProjectAccessRights').returns(Promise.resolve(accessRes)); + 'getProjectAccessRights'); + + + accessStub.withArgs('New Project').returns(Promise.resolve(accessRes)); + accessStub.withArgs('Another New Project') + .returns(Promise.resolve(accessRes2)); const capabilitiesStub = sandbox.stub(element.$.restAPI, - 'getCapabilities').returns(Promise.resolve(capabilitiesRes)); + 'getCapabilities'); + capabilitiesStub.returns(Promise.resolve(capabilitiesRes)); const projectStub = sandbox.stub(element.$.restAPI, 'getProject').returns( Promise.resolve(projectRes)); const adminStub = sandbox.stub(element.$.restAPI, 'getIsAdmin').returns( @@ -96,8 +121,13 @@ limitations under the License. assert.deepEqual(element._sections, element.toSortedArray(accessRes.local)); assert.deepEqual(element._labels, projectRes.labels); - done(); - }); + return element._projectChanged('Another New Project'); + }) + .then(() => { + assert.deepEqual(element._sections, + element.toSortedArray(accessRes2.local)); + done(); + }); }); test('_projectChanged when project changes to undefined returns', done => {