
This change fixes two javascript errors:
1. TypeError: Cannot read property 'name' of undefined. This existed
when a project without global capabilities was loaded after one with
global capabilities. Inside of the section dom-repeat, the old
section id was being used to compute the permission name. This is
fixed by resetting sections to an empty array before setting the
new value returned by the api.
2. TypeError: Cannot read property 'values' of undefined. This existed
when _computeLabel was called with a label is not included in the
list of 'labels' returned by the api. In this case, label values
should not be rendered, the permission still exists, and acts like a
non-label permission
Bug: Issue 7497
Change-Id: Ib7451f2bae5d2349289f41070a305bf086017c65
(cherry picked from commit 4d039c8db2
)
95 lines
2.5 KiB
JavaScript
95 lines
2.5 KiB
JavaScript
// Copyright (C) 2017 The Android Open Source Project
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
(function() {
|
|
'use strict';
|
|
|
|
Polymer({
|
|
is: 'gr-project-access',
|
|
|
|
properties: {
|
|
project: {
|
|
type: String,
|
|
observer: '_projectChanged',
|
|
},
|
|
// The current path
|
|
path: String,
|
|
|
|
_isAdmin: {
|
|
type: Boolean,
|
|
value: false,
|
|
},
|
|
_capabilities: Object,
|
|
_groups: Object,
|
|
/** @type {?} */
|
|
_inheritsFrom: Object,
|
|
_labels: Object,
|
|
_local: Object,
|
|
_editing: {
|
|
type: Boolean,
|
|
value: false,
|
|
},
|
|
_sections: Array,
|
|
},
|
|
|
|
behaviors: [
|
|
Gerrit.AccessBehavior,
|
|
Gerrit.BaseUrlBehavior,
|
|
Gerrit.URLEncodingBehavior,
|
|
],
|
|
|
|
/**
|
|
* @param {string} project
|
|
* @return {!Promise}
|
|
*/
|
|
_projectChanged(project) {
|
|
if (!project) { return Promise.resolve(); }
|
|
const promises = [];
|
|
// 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;
|
|
this._groups = res.groups;
|
|
return this.toSortedArray(this._local);
|
|
}));
|
|
|
|
promises.push(this.$.restAPI.getCapabilities().then(res => {
|
|
return res;
|
|
}));
|
|
|
|
promises.push(this.$.restAPI.getProject(project).then(res => {
|
|
return res.labels;
|
|
}));
|
|
|
|
promises.push(this.$.restAPI.getIsAdmin().then(isAdmin => {
|
|
this._isAdmin = isAdmin;
|
|
}));
|
|
|
|
return Promise.all(promises).then(([sections, capabilities, labels]) => {
|
|
this._capabilities = capabilities;
|
|
this._labels = labels;
|
|
this._sections = sections;
|
|
});
|
|
},
|
|
|
|
_computeAdminClass(isAdmin) {
|
|
return isAdmin ? 'admin' : '';
|
|
},
|
|
|
|
_computeParentHref(projectName) {
|
|
return this.getBaseUrl() +
|
|
`/admin/projects/${this.encodeURL(projectName, true)},access`;
|
|
},
|
|
});
|
|
})(); |