From d5a82f04c282ed6e9e566c4a4942e8b78372c091 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 6 Jan 2017 15:35:32 -0500 Subject: [PATCH] Fixing issues with e-mail and status update. --- client/coral-admin/src/actions/users.js | 4 ++-- client/coral-admin/src/translations.json | 2 +- models/user.js | 5 +++-- routes/api/users/index.js | 7 +++---- services/mailer.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/coral-admin/src/actions/users.js b/client/coral-admin/src/actions/users.js index b8b403761..7b05cd0cd 100644 --- a/client/coral-admin/src/actions/users.js +++ b/client/coral-admin/src/actions/users.js @@ -16,10 +16,10 @@ export const userStatusUpdate = (status, userId, commentId) => { }; // change status of a user -export const sendNotificationEmail = (userId, subject, text) => { +export const sendNotificationEmail = (userId, subject, body) => { return (dispatch, getState) => { const _csrf = getState().auth.get('_csrf'); - return coralApi(`/users/${userId}/email`, {method: 'POST', body: {subject, text}, _csrf}) + return coralApi(`/users/${userId}/email`, {method: 'POST', body: {subject, body}, _csrf}) .catch(error => dispatch({type: userTypes.USER_EMAIL_FAILURE, error})); }; }; diff --git a/client/coral-admin/src/translations.json b/client/coral-admin/src/translations.json index 870b84582..30aef200c 100644 --- a/client/coral-admin/src/translations.json +++ b/client/coral-admin/src/translations.json @@ -94,7 +94,7 @@ "send": "Send", "bio": "bio", "username": "username", - "subject": "Your account has been suspended", + "email_subject": "Your account has been suspended", "email": "Another member of the community recently flagged your {0} for review. Because of its content your {0} was rejected. This means you can no longer comment, like, or flag content until you rewrite your {0}. Please e-mail moderator@newsorg.com if you have any questions or concerns.", "write_message": "Write a message" }, diff --git a/models/user.js b/models/user.js index 5c0268483..6816b2050 100644 --- a/models/user.js +++ b/models/user.js @@ -437,7 +437,7 @@ UserService.setStatus = (id, status, comment_id) => { } // If ban then reject the comment and update status - if (status === 'banned') { + if (status === 'banned' || status === 'suspended') { return UserModel.update({ id: id }, { @@ -446,7 +446,8 @@ UserService.setStatus = (id, status, comment_id) => { } }) .then(() => { - return Comment.pushStatus(comment_id, 'rejected', id); + return comment_id ? Comment.pushStatus(comment_id, 'rejected', id) : + Promise.resolve(); }); } diff --git a/routes/api/users/index.js b/routes/api/users/index.js index 1e0203f07..eef00459b 100644 --- a/routes/api/users/index.js +++ b/routes/api/users/index.js @@ -67,17 +67,16 @@ router.post('/:user_id/status', parseForm, csrfProtection, (req, res, next) => { }); router.post('/:user_id/email', authorization.needed('admin'), parseForm, csrfProtection, (req, res, next) => { - User.find(req.user_id) + User.findById(req.params.user_id) .then(user => { const options = { - subject: req.subject, + subject: req.body.subject, from: process.env.TALK_SMTP_FROM_ADDRESS, to: user.email, html: notificationEmailTemplate({ - body: req.body + body: req.body.body }) }; - return mailer.sendSimple(options); }) .then(() => { diff --git a/services/mailer.js b/services/mailer.js index 9ff7291d4..931cbecc2 100644 --- a/services/mailer.js +++ b/services/mailer.js @@ -48,7 +48,7 @@ const mailer = { if (!subject) { reject('sendSimple requires a subject for the email'); } - + return resolve(transporter.sendMail({from, to, subject, text, html})); }); }