Add new group to permission's group object when added

In the event that a group does not already appear in the access editor,
the group id/name pair may not be included in the groups mapping. In the
event that it's not, manually add upon selection so that the proper name
can be displayed.

Bug: Issue 8196
Change-Id: Ie1d8ce50ddeea2b24e877ac996fa5ea21adc5135
This commit is contained in:
Becky Siegel
2018-02-28 16:16:43 -08:00
parent d14334fe2d
commit 74117d6952
3 changed files with 11 additions and 1 deletions

View File

@@ -118,6 +118,7 @@ limitations under the License.
</template>
<div id="addRule">
<gr-autocomplete
id="groupAutocomplete"
text="{{_groupFilter}}"
query="[[_query]]"
placeholder="Add group"

View File

@@ -235,6 +235,12 @@
id: groupId,
});
// 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

View File

@@ -300,6 +300,8 @@ limitations under the License.
test('adding a rule', () => {
element.name = 'Priority';
element.section = 'refs/*';
element.groups = {};
element.$.groupAutocomplete.text = 'new group name';
const e = {
detail: {
value: {
@@ -312,11 +314,12 @@ limitations under the License.
assert.equal(Object.keys(element._groupsWithRules).length, 2);
element._handleAddRuleItem(e);
flushAsynchronousOperations();
assert.deepEqual(element.groups, {newUserGroupId: {
name: 'new group name'}});
assert.equal(element._rules.length, 3);
assert.equal(Object.keys(element._groupsWithRules).length, 3);
assert.deepEqual(element.permission.value.rules['newUserGroupId'],
{action: 'ALLOW', min: -2, max: 2, added: true});
// New rule should be removed if cancel from editing.
element.editing = false;
assert.equal(element._rules.length, 2);