Files
gerrit/polygerrit-ui/app/elements/admin/gr-project-access/gr-project-access.js
Becky Siegel edd3f89e0b Don't try to load access page when there is no project
The prject access page tried to reload itself when the project changed.
However, this also occured when swithcing to a different admin view
and there is no corresponding project (ex: groups). In that case, the
admin view should not be reloaded, so return early.

Bug: Issue 7129
Change-Id: I9c0837c1d7677287b3d3ea9970ee3a804a1bece7
2017-08-31 10:52:20 -07:00

85 lines
2.4 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',
},
_capabilities: 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 = [];
if (!this._sections) {
this._sections = [];
}
promises.push(this.$.restAPI.getProjectAccessRights(project).then(res => {
this._inheritsFrom = res.inherits_from;
this._local = res.local;
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;
}));
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]));
});
},
_computeParentHref(projectName) {
return this.getBaseUrl() +
`/admin/projects/${this.encodeURL(projectName, true)},access`;
},
});
})();