mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #3708 from felixrieseberg/iss3681-2
Error if user has already been invited
This commit is contained in:
commit
dae40bffec
1 changed files with 29 additions and 17 deletions
|
@ -36,25 +36,37 @@ var InviteNewUserController = Ember.Controller.extend({
|
||||||
self.set('role', self.get('authorRole'));
|
self.set('role', self.get('authorRole'));
|
||||||
self.send('closeModal');
|
self.send('closeModal');
|
||||||
|
|
||||||
newUser = self.store.createRecord('user', {
|
this.store.find('user').then(function (result) {
|
||||||
email: email,
|
var invitedUser = result.findBy('email', email);
|
||||||
status: 'invited',
|
if (invitedUser) {
|
||||||
role: role
|
if (invitedUser.get('status') === 'invited' || invitedUser.get('status') === 'invited-pending') {
|
||||||
});
|
self.notifications.showWarn('A user with that email address was already invited.');
|
||||||
|
} else {
|
||||||
|
self.notifications.showWarn('A user with that email address already exists.');
|
||||||
|
}
|
||||||
|
|
||||||
newUser.save().then(function () {
|
|
||||||
var notificationText = 'Invitation sent! (' + email + ')';
|
|
||||||
|
|
||||||
// If sending the invitation email fails, the API will still return a status of 201
|
|
||||||
// but the user's status in the response object will be 'invited-pending'.
|
|
||||||
if (newUser.get('status') === 'invited-pending') {
|
|
||||||
self.notifications.showWarn('Invitation email was not sent. Please try resending.');
|
|
||||||
} else {
|
} else {
|
||||||
self.notifications.showSuccess(notificationText);
|
newUser = self.store.createRecord('user', {
|
||||||
|
email: email,
|
||||||
|
status: 'invited',
|
||||||
|
role: role
|
||||||
|
});
|
||||||
|
|
||||||
|
newUser.save().then(function () {
|
||||||
|
var notificationText = 'Invitation sent! (' + email + ')';
|
||||||
|
|
||||||
|
// If sending the invitation email fails, the API will still return a status of 201
|
||||||
|
// but the user's status in the response object will be 'invited-pending'.
|
||||||
|
if (newUser.get('status') === 'invited-pending') {
|
||||||
|
self.notifications.showWarn('Invitation email was not sent. Please try resending.');
|
||||||
|
} else {
|
||||||
|
self.notifications.showSuccess(notificationText);
|
||||||
|
}
|
||||||
|
}).catch(function (errors) {
|
||||||
|
newUser.deleteRecord();
|
||||||
|
self.notifications.showErrors(errors);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).catch(function (errors) {
|
|
||||||
newUser.deleteRecord();
|
|
||||||
self.notifications.showErrors(errors);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue