diff --git a/packages/component-helper-service/src/services/Fragment.js b/packages/component-helper-service/src/services/Fragment.js index a0e8494bb014ebe42a81ee538f68351d5cfa53ca..bf7013772455b040774f5eb3eab97f3a468f8e22 100644 --- a/packages/component-helper-service/src/services/Fragment.js +++ b/packages/component-helper-service/src/services/Fragment.js @@ -76,7 +76,9 @@ class Fragment { ) const userHelper = new User({ UserModel }) - const activeAuthors = await userHelper.getActiveAuthors(authors) + const activeAuthors = await userHelper.getActiveAuthors({ + fragmentAuthors: authors, + }) return { activeAuthors, diff --git a/packages/component-helper-service/src/services/User.js b/packages/component-helper-service/src/services/User.js index e37a835dce2cc83b7541bae9f22a808bf86eb908..83c8809d2f4076bc5992731557f97cf49fb21499 100644 --- a/packages/component-helper-service/src/services/User.js +++ b/packages/component-helper-service/src/services/User.js @@ -62,15 +62,25 @@ class User { user.save() } - async getActiveAuthors(authors) { - const activeUsers = (await Promise.all( - authors.map(author => this.UserModel.find(author.id)), + async getActiveAuthors({ fragmentAuthors }) { + const userData = (await Promise.all( + fragmentAuthors.map(author => this.UserModel.find(author.id)), )) - .filter(user => user.isActive) - .filter(user => get(user, 'notifications.email.user')) - .map(user => user.id) + .filter(user => user.isActive && get(user, 'notifications.email.user')) + .map(user => ({ id: user.id, accessTokens: user.accessTokens })) - return authors.filter(author => activeUsers.includes(author.id)) + return fragmentAuthors + .map(fAuthor => { + const matchingAuthor = userData.find(user => user.id === fAuthor.id) + if (matchingAuthor) { + return { + ...fAuthor, + accessTokens: matchingAuthor.accessTokens, + } + } + return false + }) + .filter(Boolean) } async getEiCName() { diff --git a/packages/component-helper-service/src/services/email/Email.js b/packages/component-helper-service/src/services/email/Email.js index 0a7c2028bc6dde1ba7259459136a48a541eae620..5fdd6b42cb2f6705b092a6123e1270952561440f 100644 --- a/packages/component-helper-service/src/services/email/Email.js +++ b/packages/component-helper-service/src/services/email/Email.js @@ -85,9 +85,7 @@ class Email { logger.info( `EMAIL: Sent email from ${from} to ${to} with subject '${subject}'`, ) - logger.debug( - `EMAIL: Sent email from ${from} to ${to} with subject '${subject}'`, - ) + SendEmail.send(mailData) } } diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/emailCopy.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/emailCopy.js index c2f6338979e4940494b69798b30c2bbf1adce1c8..fbb64a10ee122ab134c26e6941a54c20eb381f63 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/emailCopy.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/emailCopy.js @@ -109,6 +109,12 @@ const getEmailCopy = ({ paragraph = `${titleText} has been accepted for publication by ${eicName}. <br/><br/> Please complete QA screening so that manuscript can be sent to production.` break + case 'authors-manuscript-rejected-before-review': + paragraph = `I regret to inform you that your manuscript has been rejected for publication in ${journalName} for the following reason:<br/><br/> + ${comments}<br/><br/> + Thank you for your submission, and please do consider submitting again in the future.` + hasLink = false + break default: throw new Error(`The ${emailType} email type is not defined.`) } diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/helpers.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/helpers.js index ffeb610de4b8dc4921ba7b0a89b4a186c89eddff..3dc8b8d7741c96ffa742617b424673b1a0b31e03 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/helpers.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/helpers.js @@ -378,14 +378,19 @@ module.exports = { return email }, - getEmailTypeByRecommendationForAuthors: ({ recommendation }) => { + getEmailTypeByRecommendationForAuthors: ({ + recommendation, + hasPeerReview, + }) => { let emailType switch (recommendation) { case 'publish': emailType = 'author-manuscript-published' break case 'reject': - emailType = 'author-manuscript-rejected' + emailType = hasPeerReview + ? 'author-manuscript-rejected' + : 'authors-manuscript-rejected-before-review' break default: throw new Error(`Undefined recommendation: ${recommendation}`) diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js index 9f6c43f5ea5f30885ad0fa99dc01e372abba8d00..c930744e70e8db6829fb9423a52f78066b133b71 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js @@ -68,8 +68,7 @@ module.exports = { }) } - const hasPeerReview = (collection = {}) => - !isEmpty(collection.handlingEditor) + const hasPeerReview = !isEmpty(collection.handlingEditor) const { customId } = collection const collHelper = new Collection({ collection }) @@ -77,7 +76,7 @@ module.exports = { // or when the EiC makes a recommendation after peer review if ( (isEditorInChief || recommendationType === 'review') && - hasPeerReview(collection) && + hasPeerReview && (recommendation !== 'publish' || hasEQA) ) { const handlingEditor = get(collection, 'handlingEditor', {}) @@ -118,10 +117,18 @@ module.exports = { // send all authors email const emailType = helpers.getEmailTypeByRecommendationForAuthors({ recommendation, + hasPeerReview, }) - const comments = helpers.getHEComments({ - heRecommendation: parsedFragment.heRecommendation, - }) + + let comments + if (hasPeerReview) { + comments = helpers.getHEComments({ + heRecommendation: parsedFragment.heRecommendation, + }) + } else { + comments = newRecommendation.comments[0].content + } + const authors = helpers.getAllAuthors({ comments, emailType, @@ -156,7 +163,7 @@ module.exports = { helpers.sendSubmittingAuthorEmail({ email, author, baseUrl }) } - if (!hasPeerReview(collection)) { + if (!hasPeerReview) { return } diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/get.js b/packages/component-user-manager/src/routes/fragmentsUsers/get.js index 6798a5f55d82666a88d4e1adc8bdc2c732e9114a..1931adfbe7245d082502f8a0cf545019817f2b27 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/get.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/get.js @@ -13,7 +13,9 @@ module.exports = models => async (req, res) => { const { authors = [] } = await models.Fragment.find(fragmentId) const userHelper = new User({ UserModel: models.User }) - const activeAuthors = await userHelper.getActiveAuthors(authors) + const activeAuthors = await userHelper.getActiveAuthors({ + fragmentAuthors: authors, + }) return res.status(200).json(activeAuthors) } catch (e) {