0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

🐛 fix guard for inviting owner in setup/three (#786)

refs https://github.com/TryGhost/Ghost/issues/8692

- fixes the guard on setup/three against inviting the owner user set up
on setup/two (we were sending invites for every e-mail in the list
rather than only valid e-mails)
- adds a check to see if we get any invalid errors from the server and
will show those separately to the `x emails failed to send` alert
This commit is contained in:
Kevin Ansfield 2017-07-20 11:08:34 +01:00 committed by Katharina Irrgang
parent 7e595d4be7
commit a99ecf4818

View file

@ -7,6 +7,7 @@ import injectService from 'ember-service/inject';
import run from 'ember-runloop'; import run from 'ember-runloop';
import {A as emberA} from 'ember-array/utils'; import {A as emberA} from 'ember-array/utils';
import {htmlSafe} from 'ember-string'; import {htmlSafe} from 'ember-string';
import {isInvalidError} from 'ember-ajax/errors';
import {task, timeout} from 'ember-concurrency'; import {task, timeout} from 'ember-concurrency';
const {Errors} = DS; const {Errors} = DS;
@ -143,7 +144,7 @@ export default Controller.extend({
}, },
invite: task(function* () { invite: task(function* () {
let users = this.get('usersArray'); let users = this.get('validUsersArray');
if (this.validate() && users.length > 0) { if (this.validate() && users.length > 0) {
this._hasTransitioned = false; this._hasTransitioned = false;
@ -173,7 +174,7 @@ export default Controller.extend({
}).drop(), }).drop(),
_saveInvites(authorRole) { _saveInvites(authorRole) {
let users = this.get('usersArray'); let users = this.get('validUsersArray');
return RSVP.Promise.all( return RSVP.Promise.all(
users.map((user) => { users.map((user) => {
@ -187,8 +188,9 @@ export default Controller.extend({
email: user, email: user,
success: invite.get('status') === 'sent' success: invite.get('status') === 'sent'
}; };
}).catch(() => { }).catch((error) => {
return { return {
error,
email: user, email: user,
success: false success: false
}; };
@ -206,6 +208,9 @@ export default Controller.extend({
invites.forEach((invite) => { invites.forEach((invite) => {
if (invite.success) { if (invite.success) {
successCount++; successCount++;
} else if (isInvalidError(invite.error)) {
message = `${invite.email} was invalid: ${invite.error.errors[0].message}`;
notifications.showAlert(message, {type: 'error', delayed: true, key: `signup.send-invitations.${invite.email}`});
} else { } else {
erroredEmails.push(invite.email); erroredEmails.push(invite.email);
} }