Merge "Fix access javascript errors"

This commit is contained in:
Becky Siegel
2017-11-07 23:49:37 +00:00
committed by Gerrit Code Review
4 changed files with 65 additions and 18 deletions

View File

@@ -95,6 +95,10 @@
if (!permission.value.label) { return; } if (!permission.value.label) { return; }
const labelName = permission.value.label; 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 = { const label = {
name: labelName, name: labelName,
values: this._computeLabelValues(labels[labelName].values), values: this._computeLabelValues(labels[labelName].values),

View File

@@ -101,7 +101,7 @@ limitations under the License.
}, },
}, },
}; };
const permission = { let permission = {
id: 'label-Code-Review', id: 'label-Code-Review',
value: { value: {
label: 'Code-Review', label: 'Code-Review',
@@ -140,6 +140,25 @@ limitations under the License.
assert.deepEqual(element._computeLabel(permission, labels), assert.deepEqual(element._computeLabel(permission, labels),
expectedLabel); 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', () => { test('_computeSectionClass', () => {

View File

@@ -55,9 +55,8 @@
_projectChanged(project) { _projectChanged(project) {
if (!project) { return Promise.resolve(); } if (!project) { return Promise.resolve(); }
const promises = []; const promises = [];
if (!this._sections) { // Always reset sections when a project changes.
this._sections = []; this._sections = [];
}
promises.push(this.$.restAPI.getProjectAccessRights(project).then(res => { promises.push(this.$.restAPI.getProjectAccessRights(project).then(res => {
this._inheritsFrom = res.inherits_from; this._inheritsFrom = res.inherits_from;
this._local = res.local; this._local = res.local;
@@ -77,15 +76,10 @@
this._isAdmin = isAdmin; this._isAdmin = isAdmin;
})); }));
return Promise.all(promises).then(value => { return Promise.all(promises).then(([sections, capabilities, labels]) => {
this._capabilities = value[1]; this._capabilities = capabilities;
this._labels = value[2]; this._labels = labels;
this._sections = sections;
// 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]));
}); });
}, },

View File

@@ -58,14 +58,33 @@ limitations under the License.
id: 'accessDatabase', id: 'accessDatabase',
name: 'Access Database', name: 'Access Database',
}, },
createAccount: {
id: 'createAccount',
name: 'Create Account',
},
}; };
const accessRes = { const accessRes = {
local: {
'refs/*': {
permissions: {
owner: {
rules: {
234: {},
},
},
},
},
},
};
const accessRes2 = {
local: { local: {
GLOBAL_CAPABILITIES: { GLOBAL_CAPABILITIES: {
permissions: { permissions: {
accessDatabase: { accessDatabase: {
rules: { rules: {
123: {}, group1: {
action: 'ALLOW',
},
}, },
}, },
}, },
@@ -78,9 +97,15 @@ limitations under the License.
}, },
}; };
const accessStub = sandbox.stub(element.$.restAPI, 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, 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( const projectStub = sandbox.stub(element.$.restAPI, 'getProject').returns(
Promise.resolve(projectRes)); Promise.resolve(projectRes));
const adminStub = sandbox.stub(element.$.restAPI, 'getIsAdmin').returns( const adminStub = sandbox.stub(element.$.restAPI, 'getIsAdmin').returns(
@@ -96,6 +121,11 @@ limitations under the License.
assert.deepEqual(element._sections, assert.deepEqual(element._sections,
element.toSortedArray(accessRes.local)); element.toSortedArray(accessRes.local));
assert.deepEqual(element._labels, projectRes.labels); assert.deepEqual(element._labels, projectRes.labels);
return element._projectChanged('Another New Project');
})
.then(() => {
assert.deepEqual(element._sections,
element.toSortedArray(accessRes2.local));
done(); done();
}); });
}); });