From 89cabd31dae71c1805ceb7c03f4d9f39bd1d9e68 Mon Sep 17 00:00:00 2001 From: Sebastian Mihalache <sebastian.mihalache@gmail.con> Date: Thu, 9 Aug 2018 14:06:06 +0300 Subject: [PATCH] refactor(email-helper): send email to existing authors --- .../routes/fragmentsUsers/emails/emailCopy.js | 4 +-- .../fragmentsUsers/emails/notifications.js | 36 ++++++++----------- .../src/routes/fragmentsUsers/post.js | 2 -- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/emails/emailCopy.js b/packages/component-user-manager/src/routes/fragmentsUsers/emails/emailCopy.js index d6e87cc86..68132122b 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/emails/emailCopy.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/emails/emailCopy.js @@ -1,8 +1,8 @@ const getEmailCopy = ({ emailType, titleText }) => { let paragraph switch (emailType) { - case 'co-author-added-to-manuscript': - paragraph = `You have been added as co-author to ${titleText}. The manuscript will become visible on your dashboard once it's submitted. Please click on the link below to access your dashboard.` + case 'author-added-to-manuscript': + paragraph = `You have been added as an author to ${titleText}. The manuscript will become visible on your dashboard once it's submitted. Please click on the link below to access your dashboard.` break case 'new-author-added-to-manuscript': paragraph = `You have been added as an author to ${titleText}. In order to gain access to the manuscript, please confirm your account and set your account details by clicking on the link below.` diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js index 413ea4967..9a7af8dbc 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js @@ -9,17 +9,11 @@ const { services, Fragment, } = require('pubsweet-component-helper-service') + const { getEmailCopy } = require('./emailCopy') module.exports = { - async sendNotifications({ - user, - baseUrl, - isSubmitting, - fragment, - UserModel, - collection, - }) { + async sendNotifications({ user, baseUrl, fragment, UserModel, collection }) { const fragmentHelper = new Fragment({ fragment }) const { title } = await fragmentHelper.getFragmentData({ handlingEditor: collection.handlingEditor, @@ -44,21 +38,27 @@ module.exports = { }, }) - if (!isSubmitting) { - sendCoAuthorEmail({ email, baseUrl, user, titleText, subjectBaseText }) + if (!user.isConfirmed) { + sendNewAuthorEmail({ + email, + user, + baseUrl, + titleText, + subjectBaseText, + }) } - sendNewAuthorEmail({ + sendAddedToManuscriptEmail({ email, - user, baseUrl, + user, titleText, subjectBaseText, }) }, } -const sendCoAuthorEmail = ({ +const sendAddedToManuscriptEmail = ({ email, baseUrl, user, @@ -77,7 +77,7 @@ const sendCoAuthorEmail = ({ const { html, text } = email.getBody({ body: getEmailCopy({ - emailType: 'co-author-added-to-manuscript', + emailType: 'author-added-to-manuscript', titleText, }), }) @@ -85,13 +85,7 @@ const sendCoAuthorEmail = ({ email.sendEmail({ html, text }) } -const sendNewAuthorEmail = ({ - email, - baseUrl, - user, - titleText, - subjectBaseText, -}) => { +const sendNewAuthorEmail = ({ email, baseUrl, user, titleText }) => { email.toUser = { email: user.email, name: `${user.firstName} ${user.lastName}`, diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/post.js b/packages/component-user-manager/src/routes/fragmentsUsers/post.js index acc7fe702..6a7546e6f 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/post.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/post.js @@ -98,7 +98,6 @@ module.exports = models => async (req, res) => { fragment, collection, UserModel: models.User, - isSubmitting, }) return res.status(200).json({ @@ -137,7 +136,6 @@ module.exports = models => async (req, res) => { collection, user: newUser, UserModel: models.User, - isSubmitting, }) if (!collection.owners.includes(newUser.id)) { -- GitLab