Merge "Show helpful message when adding group member 404s"
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const SUGGESTIONS_LIMIT = 15;
|
const SUGGESTIONS_LIMIT = 15;
|
||||||
|
const SAVING_ERROR_TEXT = 'Group may not exist, or you may not have '+
|
||||||
|
'permission to add it';
|
||||||
|
|
||||||
const URL_REGEX = '^(?:[a-z]+:)?//';
|
const URL_REGEX = '^(?:[a-z]+:)?//';
|
||||||
|
|
||||||
@@ -186,7 +188,16 @@
|
|||||||
|
|
||||||
_handleSavingIncludedGroups() {
|
_handleSavingIncludedGroups() {
|
||||||
return this.$.restAPI.saveIncludedGroup(this._groupName,
|
return this.$.restAPI.saveIncludedGroup(this._groupName,
|
||||||
this._includedGroupSearch)
|
this._includedGroupSearch, err => {
|
||||||
|
if (err.status === 404) {
|
||||||
|
this.dispatchEvent(new CustomEvent('show-alert', {
|
||||||
|
detail: {message: SAVING_ERROR_TEXT},
|
||||||
|
bubbles: true,
|
||||||
|
}));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
throw Error(err.statusText);
|
||||||
|
})
|
||||||
.then(config => {
|
.then(config => {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return;
|
return;
|
||||||
|
@@ -183,6 +183,24 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('add included group 404 shows helpful error text', () => {
|
||||||
|
element._groupOwner = true;
|
||||||
|
|
||||||
|
const memberName = 'bad-name';
|
||||||
|
const alertStub = sandbox.stub();
|
||||||
|
element.addEventListener('show-alert', alertStub);
|
||||||
|
|
||||||
|
sandbox.stub(element.$.restAPI, 'saveGroupMembers',
|
||||||
|
() => Promise.reject({status: 404}));
|
||||||
|
|
||||||
|
element.$.groupMemberSearchInput.text = memberName;
|
||||||
|
element.$.groupMemberSearchInput.value = 1234;
|
||||||
|
|
||||||
|
return element._handleSavingIncludedGroups().then(() => {
|
||||||
|
assert.isTrue(alertStub.called);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('_getAccountSuggestions empty', () => {
|
test('_getAccountSuggestions empty', () => {
|
||||||
return element._getAccountSuggestions('nonexistent').then(accounts => {
|
return element._getAccountSuggestions('nonexistent').then(accounts => {
|
||||||
assert.equal(accounts.length, 0);
|
assert.equal(accounts.length, 0);
|
||||||
|
@@ -437,12 +437,16 @@
|
|||||||
.then(response => this.getResponseObject(response));
|
.then(response => this.getResponseObject(response));
|
||||||
},
|
},
|
||||||
|
|
||||||
saveIncludedGroup(groupName, includedGroup) {
|
saveIncludedGroup(groupName, includedGroup, opt_errFn) {
|
||||||
const encodeName = encodeURIComponent(groupName);
|
const encodeName = encodeURIComponent(groupName);
|
||||||
const encodeIncludedGroup = encodeURIComponent(includedGroup);
|
const encodeIncludedGroup = encodeURIComponent(includedGroup);
|
||||||
return this.send('PUT',
|
return this.send('PUT',
|
||||||
`/groups/${encodeName}/groups/${encodeIncludedGroup}`)
|
`/groups/${encodeName}/groups/${encodeIncludedGroup}`, null,
|
||||||
.then(response => this.getResponseObject(response));
|
opt_errFn).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return this.getResponseObject(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteGroupMembers(groupName, groupMembers) {
|
deleteGroupMembers(groupName, groupMembers) {
|
||||||
|
Reference in New Issue
Block a user