0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Fix Invitations

no issue
- added `invited-pending` when resending invitation
- promise chain was missing a return statement
- email error was masked and front end showed success notification
This commit is contained in:
Sebastian Gierlinger 2014-07-29 15:35:48 +02:00
parent 2724abf462
commit 83e1ffca1d
4 changed files with 54 additions and 45 deletions

View file

@ -56,8 +56,7 @@ var InviteNewUserController = Ember.Controller.extend({
// but the user's status in the response object will be 'invited-pending'. // but the user's status in the response object will be 'invited-pending'.
if (newUser.get('status') === 'invited-pending') { if (newUser.get('status') === 'invited-pending') {
self.notifications.showWarn('Invitation email was not sent. Please try resending.'); self.notifications.showWarn('Invitation email was not sent. Please try resending.');
} } else {
else {
self.notifications.showSuccess(notificationText, false); self.notifications.showSuccess(notificationText, false);
} }
}).catch(function (errors) { }).catch(function (errors) {

View file

@ -66,10 +66,16 @@ var SettingsUserController = Ember.ObjectController.extend({
resend: function () { resend: function () {
var self = this; var self = this;
this.get('model').resendInvite().then(function () { this.get('model').resendInvite().then(function (result) {
self.get('model').set('status', 'invited');
var notificationText = 'Invitation resent! (' + self.get('email') + ')'; var notificationText = 'Invitation resent! (' + self.get('email') + ')';
self.notifications.showSuccess(notificationText, false); // 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 (result.users[0].status === 'invited-pending') {
self.notifications.showWarn('Invitation email was not sent. Please try resending.');
} else {
self.get('model').set('status', result.users[0].status);
self.notifications.showSuccess(notificationText, false);
}
}).catch(function (error) { }).catch(function (error) {
self.notifications.closePassive(); self.notifications.closePassive();
self.notifications.showAPIError(error); self.notifications.showAPIError(error);

View file

@ -1,14 +1,14 @@
// # Mail API // # Mail API
// API for sending Mail // API for sending Mail
var when = require('when'), var _ = require('lodash'),
_ = require('lodash'), when = require('when'),
config = require('../config'), config = require('../config'),
canThis = require('../permissions').canThis, canThis = require('../permissions').canThis,
errors = require('../errors'), errors = require('../errors'),
path = require('path'), path = require('path'),
fs = require('fs'), fs = require('fs'),
templatesDir = path.resolve(__dirname, '..', 'email-templates'), templatesDir = path.resolve(__dirname, '..', 'email-templates'),
htmlToText = require('html-to-text'), htmlToText = require('html-to-text'),
mail; mail;
/** /**
@ -105,9 +105,10 @@ mail = {
//generate a plain-text version of the same email //generate a plain-text version of the same email
textContent = htmlToText.fromString(htmlContent); textContent = htmlToText.fromString(htmlContent);
resolve({ html: htmlContent, resolve({
text: textContent html: htmlContent,
}); text: textContent
});
}); });
}); });

View file

@ -132,7 +132,8 @@ users = {
add: function add(object, options) { add: function add(object, options) {
var newUser, var newUser,
user, user,
roleId; roleId,
emailData;
return canThis(options.context).add.user(object).then(function () { return canThis(options.context).add.user(object).then(function () {
return utils.checkObject(object, docName).then(function (checkedUserData) { return utils.checkObject(object, docName).then(function (checkedUserData) {
@ -182,39 +183,41 @@ users = {
dbHash = response.settings[0].value; dbHash = response.settings[0].value;
return dataProvider.User.generateResetToken(user.email, expires, dbHash); return dataProvider.User.generateResetToken(user.email, expires, dbHash);
}).then(function (resetToken) { }).then(function (resetToken) {
when.join(users.read({'id': user.created_by}), settings.read({'key': 'title'})).then(function (values) { return when.join(users.read({'id': user.created_by}), settings.read({'key': 'title'})).then(function (values) {
var invitedBy = values[0].users[0], var invitedBy = values[0].users[0],
blogTitle = values[1].settings[0].value, blogTitle = values[1].settings[0].value,
baseUrl = config.forceAdminSSL ? (config.urlSSL || config.url) : config.url, baseUrl = config.forceAdminSSL ? (config.urlSSL || config.url) : config.url,
resetUrl = baseUrl.replace(/\/$/, '') + '/ghost/signup/' + resetToken + '/', resetUrl = baseUrl.replace(/\/$/, '') + '/ghost/signup/' + resetToken + '/';
emailData = {
blogName: blogTitle,
invitedByName: invitedBy.name,
invitedByEmail: invitedBy.email,
resetLink: resetUrl
};
mail.generateContent({data: emailData, template: 'invite-user'}).then(function (emailContent) { emailData = {
blogName: blogTitle,
invitedByName: invitedBy.name,
invitedByEmail: invitedBy.email,
resetLink: resetUrl
};
var payload = { return mail.generateContent({data: emailData, template: 'invite-user'});
mail: [ }).then(function (emailContent) {
{ var payload = {
message: { mail: [
to: user.email, {
subject: emailData.invitedByName + ' has invited you to join ' + emailData.blogName, message: {
html: emailContent.html, to: user.email,
text: emailContent.text subject: emailData.invitedByName + ' has invited you to join ' + emailData.blogName,
}, html: emailContent.html,
options: {} text: emailContent.text
} },
] options: {}
};
return mail.send(payload, {context: {internal: true}}).then(function () {
// If status was invited-pending and sending the invitation succeeded, set status to invited.
if (user.status === 'invited-pending') {
return dataProvider.User.edit({status: 'invited'}, {id: user.id});
} }
}); ]
};
return mail.send(payload, {context: {internal: true}}).then(function () {
// If status was invited-pending and sending the invitation succeeded, set status to invited.
if (user.status === 'invited-pending') {
return dataProvider.User.edit({status: 'invited'}, {id: user.id}).then(function (editedUser) {
user = editedUser.toJSON();
});
}
}); });
}); });
}).then(function () { }).then(function () {