Add Group names and links to gr-rule-editor

Instead of just printing the group Id, display the name as a link to
the group page.

Change-Id: Id7abe3b82aed0962fdd1ac137ebd962a2e722ced
This commit is contained in:
Becky Siegel
2017-09-07 08:35:35 -07:00
parent 2efaca87dd
commit d9cc72bcb5
10 changed files with 46 additions and 6 deletions

View File

@@ -109,7 +109,8 @@ limitations under the License.
permission="{{permission}}" permission="{{permission}}"
labels="[[labels]]" labels="[[labels]]"
section="[[section.id]]" section="[[section.id]]"
editing="[[editing]]"> editing="[[editing]]"
groups="[[groups]]">
</gr-permission> </gr-permission>
</template> </template>
<div id="addPermission"> <div id="addPermission">

View File

@@ -33,6 +33,7 @@
notify: true, notify: true,
observer: '_sectionChanged', observer: '_sectionChanged',
}, },
groups: Object,
labels: Object, labels: Object,
editing: { editing: {
type: Boolean, type: Boolean,

View File

@@ -92,7 +92,8 @@ limitations under the License.
<gr-rule-editor <gr-rule-editor
label="[[_label]]" label="[[_label]]"
editing="[[editing]]" editing="[[editing]]"
group="[[rule.id]]" group-id="[[rule.id]]"
group-name="[[_computeGroupName(groups, rule.id)]]"
permission="[[permission.id]]" permission="[[permission.id]]"
rule="{{rule}}" rule="{{rule}}"
section="[[section]]"></gr-rule-editor> section="[[section]]"></gr-rule-editor>

View File

@@ -28,6 +28,7 @@
observer: '_sortPermission', observer: '_sortPermission',
notify: true, notify: true,
}, },
groups: Object,
section: String, section: String,
editing: { editing: {
type: Boolean, type: Boolean,
@@ -129,6 +130,11 @@
return groups; return groups;
}, },
_computeGroupName(groups, groupId) {
return groups && groups[groupId] && groups[groupId].name ?
groups[groupId].name : groupId;
},
_getGroupSuggestions() { _getGroupSuggestions() {
return this.$.restAPI.getSuggestedGroups( return this.$.restAPI.getSuggestedGroups(
this._groupFilter, this._groupFilter,

View File

@@ -158,6 +158,14 @@ limitations under the License.
'editing deleted'); 'editing deleted');
}); });
test('_computeGroupName', () => {
const groups = {
abc123: {name: 'test group'},
bcd234: {},
};
assert.equal(element._computeGroupName(groups, 'abc123'), 'test group');
assert.equal(element._computeGroupName(groups, 'bcd234'), 'bcd234');
});
test('_computeGroupsWithRules', () => { test('_computeGroupsWithRules', () => {
const rules = [ const rules = [

View File

@@ -40,7 +40,8 @@ limitations under the License.
capabilities="[[_capabilities]]" capabilities="[[_capabilities]]"
section="{{section}}" section="{{section}}"
labels="[[_labels]]" labels="[[_labels]]"
editing="[[_editing]]"></gr-access-section> editing="[[_editing]]"
groups="[[_groups]]"></gr-access-section>
</template> </template>
<template is="dom-if" if="[[_inheritsFrom]]"> <template is="dom-if" if="[[_inheritsFrom]]">
<h3 id="inheritsFrom">Rights Inherit From <h3 id="inheritsFrom">Rights Inherit From

View File

@@ -24,6 +24,7 @@
}, },
_capabilities: Object, _capabilities: Object,
_groups: Object,
/** @type {?} */ /** @type {?} */
_inheritsFrom: Object, _inheritsFrom: Object,
_labels: Object, _labels: Object,
@@ -54,6 +55,7 @@
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;
this._groups = res.groups;
return this.toSortedArray(this._local); return this.toSortedArray(this._local);
})); }));

View File

@@ -16,7 +16,9 @@ limitations under the License.
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
<link rel="import" href="../../../behaviors/gr-access-behavior/gr-access-behavior.html"> <link rel="import" href="../../../behaviors/gr-access-behavior/gr-access-behavior.html">
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
<link rel="import" href="../../../styles/gr-form-styles.html"> <link rel="import" href="../../../styles/gr-form-styles.html">
<link rel="import" href="../../../styles/shared-styles.html"> <link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../shared/gr-button/gr-button.html"> <link rel="import" href="../../shared/gr-button/gr-button.html">
@@ -64,6 +66,9 @@ limitations under the License.
#deletedContainer.deleted { #deletedContainer.deleted {
display: block; display: block;
} }
.groupPath {
color: #666;
}
</style> </style>
<style include="gr-form-styles"></style> <style include="gr-form-styles"></style>
<div id="mainContainer" <div id="mainContainer"
@@ -100,7 +105,9 @@ limitations under the License.
</select> </select>
</gr-select> </gr-select>
</template> </template>
<span>[[group]]</span> <a class="groupPath" href$="[[_computeGroupPath(groupId)]]">
[[groupName]]
</a>
<gr-select <gr-select
id="force" id="force"
class$="[[_computeForceClass(permission)]]" class$="[[_computeForceClass(permission)]]"
@@ -126,7 +133,7 @@ limitations under the License.
<div <div
id="deletedContainer" id="deletedContainer"
class$="gr-form-styles [[_computeSectionClass(editing, _deleted)]]"> class$="gr-form-styles [[_computeSectionClass(editing, _deleted)]]">
[[group]] was deleted [[groupName]] was deleted
<gr-button id="undoRemoveBtn" on-tap="_handleUndoRemove">Undo</gr-button> <gr-button id="undoRemoveBtn" on-tap="_handleUndoRemove">Undo</gr-button>
</div> </div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface> <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>

View File

@@ -57,7 +57,8 @@
type: Boolean, type: Boolean,
value: false, value: false,
}, },
group: String, groupId: String,
groupName: String,
permission: String, permission: String,
/** @type {?} */ /** @type {?} */
rule: { rule: {
@@ -78,6 +79,8 @@
behaviors: [ behaviors: [
Gerrit.AccessBehavior, Gerrit.AccessBehavior,
Gerrit.BaseUrlBehavior,
Gerrit.URLEncodingBehavior,
], ],
observers: [ observers: [
@@ -107,6 +110,10 @@
return this._computeForce(permission) ? 'force' : ''; return this._computeForce(permission) ? 'force' : '';
}, },
_computeGroupPath(group) {
return `${this.getBaseUrl()}/admin/groups/${this.encodeURL(group, true)}`;
},
_computeSectionClass(editing, deleted) { _computeSectionClass(editing, deleted) {
const classList = []; const classList = [];
if (editing) { if (editing) {

View File

@@ -240,6 +240,12 @@ limitations under the License.
MockInteractions.tap(element.$.undoRemoveBtn); MockInteractions.tap(element.$.undoRemoveBtn);
assert.isNotOk(element.rule.value.deleted); assert.isNotOk(element.rule.value.deleted);
}); });
test('_computeGroupPath', () => {
const group = '123';
assert.equal(element._computeGroupPath(group),
`/admin/groups/123`);
});
}); });
suite('new edit rule', () => { suite('new edit rule', () => {