summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js')
-rw-r--r--polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js148
1 files changed, 124 insertions, 24 deletions
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 2ba1eedb44..c45ffd56a6 100644
--- a/polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js
+++ b/polygerrit-ui/app/elements/admin/gr-permission/gr-permission.js
@@ -1,21 +1,40 @@
-// 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.
+/**
+ * @license
+ * 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';
const MAX_AUTOCOMPLETE_RESULTS = 20;
+ const RANGE_NAMES = [
+ 'QUERY LIMIT',
+ 'BATCH CHANGES LIMIT',
+ ];
+
+ /**
+ * Fired when the permission has been modified or removed.
+ *
+ * @event access-modified
+ */
+
+ /**
+ * Fired when a permission that was previously added was removed.
+ * @event added-permission-removed
+ */
+
Polymer({
is: 'gr-permission',
@@ -33,6 +52,7 @@
editing: {
type: Boolean,
value: false,
+ observer: '_handleEditingChanged',
},
_label: {
type: Object,
@@ -51,6 +71,7 @@
type: Boolean,
value: false,
},
+ _originalExclusiveValue: Boolean,
},
behaviors: [
@@ -61,6 +82,73 @@
'_handleRulesChanged(_rules.splices)',
],
+ listeners: {
+ 'access-saved': '_handleAccessSaved',
+ },
+
+ ready() {
+ this._setupValues();
+ },
+
+ _setupValues() {
+ if (!this.permission) { return; }
+ this._originalExclusiveValue = !!this.permission.value.exclusive;
+ Polymer.dom.flush();
+ },
+
+ _handleAccessSaved() {
+ // Set a new 'original' value to keep track of after the value has been
+ // saved.
+ this._setupValues();
+ },
+
+ _permissionIsOwnerOrGlobal(permissionId, section) {
+ return permissionId === 'owner' || section === 'GLOBAL_CAPABILITIES';
+ },
+
+ _handleEditingChanged(editing, editingOld) {
+ // Ignore when editing gets set initially.
+ if (!editingOld) { return; }
+ // Restore original values if no longer editing.
+ if (!editing) {
+ this._deleted = false;
+ delete this.permission.value.deleted;
+ this._groupFilter = '';
+ this._rules = this._rules.filter(rule => !rule.value.added);
+ for (const key of Object.keys(this.permission.value.rules)) {
+ if (this.permission.value.rules[key].added) {
+ delete this.permission.value.rules[key];
+ }
+ }
+
+ // Restore exclusive bit to original.
+ this.set(['permission', 'value', 'exclusive'],
+ this._originalExclusiveValue);
+ }
+ },
+
+ _handleAddedRuleRemoved(e) {
+ const index = e.model.index;
+ this._rules = this._rules.slice(0, index)
+ .concat(this._rules.slice(index + 1, this._rules.length));
+ },
+
+ _handleValueChange() {
+ this.permission.value.modified = true;
+ // Allows overall access page to know a change has been made.
+ this.dispatchEvent(new CustomEvent('access-modified', {bubbles: true}));
+ },
+
+ _handleRemovePermission() {
+ if (this.permission.value.added) {
+ this.dispatchEvent(new CustomEvent('added-permission-removed',
+ {bubbles: true}));
+ }
+ this._deleted = true;
+ this.permission.value.deleted = true;
+ this.dispatchEvent(new CustomEvent('access-modified', {bubbles: true}));
+ },
+
_handleRulesChanged(changeRecord) {
// Update the groups to exclude in the autocomplete.
this._groupsWithRules = this._computeGroupsWithRules(this._rules);
@@ -70,11 +158,6 @@
this._rules = this.toSortedArray(permission.value.rules);
},
- _handleRemovePermission() {
- this._deleted = true;
- this.set('permission.value.deleted', true);
- },
-
_computeSectionClass(editing, deleted) {
const classList = [];
if (editing) {
@@ -164,21 +247,38 @@
* gr-rule-editor handles setting the default values.
*/
_handleAddRuleItem(e) {
- this.set(['permission', 'value', 'rules', e.detail.value.id], {});
+ // The group id is encoded, but have to decode in order for the access
+ // API to work as expected.
+ const groupId = decodeURIComponent(e.detail.value.id).replace(/\+/g, ' ');
+ this.set(['permission', 'value', 'rules', groupId], {});
// Purposely don't recompute sorted array so that the newly added rule
// is the last item of the array.
this.push('_rules', {
- id: e.detail.value.id,
+ id: groupId,
});
- // Wait for new rule to get value populated via gr-rule editor, and then
+ // Add the new group name to the groups object so the name renders
+ // correctly.
+ if (this.groups && !this.groups[groupId]) {
+ this.groups[groupId] = {name: this.$.groupAutocomplete.text};
+ }
+
+ // Wait for new rule to get value populated via gr-rule-editor, and then
// add to permission values as well, so that the change gets propogated
// back to the section. Since the rule is inside a dom-repeat, a flush
// is needed.
Polymer.dom.flush();
- this.set(['permission', 'value', 'rules', e.detail.value.id],
- this._rules[this._rules.length - 1].value);
+ const value = this._rules[this._rules.length - 1].value;
+ value.added = true;
+ this.set(['permission', 'value', 'rules', groupId], value);
+ this.dispatchEvent(new CustomEvent('access-modified', {bubbles: true}));
+ },
+
+ _computeHasRange(name) {
+ if (!name) { return false; }
+
+ return RANGE_NAMES.includes(name.toUpperCase());
},
});
-})(); \ No newline at end of file
+})();