diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/emailCopy.js b/packages/component-manuscript-manager/src/notifications/emailCopy.js similarity index 92% rename from packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/emailCopy.js rename to packages/component-manuscript-manager/src/notifications/emailCopy.js index c38f59096849888b35876cebf97481b28f856ac7..3aa154fcdd356c251d191cf3d38b02778e1379cf 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/emailCopy.js +++ b/packages/component-manuscript-manager/src/notifications/emailCopy.js @@ -119,6 +119,18 @@ const getEmailCopy = ({ Thank you for your submission, and please do consider submitting again in the future.` hasLink = false break + case 'eic-manuscript-accepted-by-eqs': + hasIntro = false + hasSignature = false + paragraph = `A new ${titleText} has been submitted to ${journalName}.<br/><br/> + To begin the review process, please visit the manuscript details page.` + break + case 'eic-manuscript-returned-by-eqa': + hasIntro = false + hasSignature = false + paragraph = `We regret to inform you that ${titleText} has been returned with comments. Please click the link below to access the manuscript.<br/><br/> + Comments: ${comments}<br/><br/>` + 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/notifications/helpers.js similarity index 100% rename from packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/helpers.js rename to packages/component-manuscript-manager/src/notifications/helpers.js diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js b/packages/component-manuscript-manager/src/notifications/notification.js similarity index 87% rename from packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js rename to packages/component-manuscript-manager/src/notifications/notification.js index 583764760db7716f8598f0dc5e52d8ba84b533ce..dfb831c3585207a0aacbb7b0f20f4e8f5a20e4eb 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js +++ b/packages/component-manuscript-manager/src/notifications/notification.js @@ -568,6 +568,85 @@ class Notification { fragmentHelper, } } + + async notifyEiCWhenEQSAcceptsManuscript() { + const { submittingAuthor } = await this.getNotificationProperties() + + const userHelper = new User({ UserModel: this.UserModel }) + const editors = await userHelper.getEditorsInChief() + const fragmentHelper = new Fragment({ fragment: this.fragment }) + const parsedFragment = await fragmentHelper.getFragmentData({}) + + const emailBodyProps = getEmailCopy({ + emailType: 'eic-manuscript-accepted-by-eqs', + titleText: `manuscript titled "${parsedFragment.title}" by ${ + submittingAuthor.firstName + } ${submittingAuthor.lastName}`, + }) + + editors.forEach(eic => { + const email = new Email({ + type: 'system', + toUser: { + email: eic.email, + }, + fromEmail: `${journalName} <${staffEmail}>`, + content: { + subject: `${this.collection.customId}: New manuscript submitted`, + ctaText: 'MANUSCRIPT DETAILS', + unsubscribeLink: this.baseUrl, + ctaLink: services.createUrl( + this.baseUrl, + `/projects/${this.collection.id}/versions/${ + this.fragment.id + }/details`, + ), + }, + }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) + email.sendEmail({ html, text }) + }) + } + + async notifyEiCWhenEQARejectsManuscript(comments) { + const { titleText } = await this.getNotificationProperties() + + const userHelper = new User({ UserModel: this.UserModel }) + const editors = await userHelper.getEditorsInChief() + + const emailBodyProps = getEmailCopy({ + comments, + titleText, + emailType: 'eic-manuscript-returned-by-eqa', + }) + + editors.forEach(eic => { + const email = new Email({ + type: 'system', + toUser: { + email: eic.email, + }, + fromEmail: `${journalName} <${staffEmail}>`, + content: { + subject: `${ + this.collection.customId + }: Manuscript returned with comments`, + ctaText: 'MANUSCRIPT DETAILS', + unsubscribeLink: this.baseUrl, + ctaLink: services.createUrl( + this.baseUrl, + `/projects/${this.collection.id}/versions/${ + this.fragment.id + }/details`, + ), + }, + }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) + email.sendEmail({ html, text }) + }) + } } module.exports = Notification diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js index d45d8d6349cd03a6c1e0bb0d2418c7529462020e..7846722ed2f83db255a59ff80f95c142ccf2d3ec 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js @@ -4,7 +4,7 @@ const { Collection, } = require('pubsweet-component-helper-service') -const Notification = require('./notifications/notification') +const Notification = require('../../notifications/notification') module.exports = models => async (req, res) => { const { collectionId, fragmentId, recommendationId } = req.params diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index deca64d012c8853d4e36a39b8714e35c2013107f..32ea418b7386c22618561d70dc972cd405f78ccc 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -30,8 +30,7 @@ const sendMTSPackage = async (collection, fragment) => { await MTS.sendPackage({ fragment: packageFragment }) } -// const notifications = require('./notifications/notifications') -const Notification = require('./notifications/notification') +const Notification = require('../../notifications/notification') module.exports = models => async (req, res) => { const { recommendation, comments, recommendationType } = req.body @@ -167,7 +166,10 @@ module.exports = models => async (req, res) => { } } - if (recommendation !== 'publish' || hasEQA) { + if ( + recommendation !== 'return-to-handling-editor' && + (recommendation !== 'publish' || hasEQA) + ) { notification.notifyAuthorsWhenEiCMakesDecision() } } else { diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js deleted file mode 100644 index d454047c92f9d937a234ee0eb60baf89e0ed50b1..0000000000000000000000000000000000000000 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js +++ /dev/null @@ -1,46 +0,0 @@ -const config = require('config') - -// const staffEmail = config.get('journal.staffEmail') -const journalName = config.get('journal.name') - -const getEmailCopy = ({ emailType, titleText, comments }) => { - let paragraph - let hasLink = true - let hasIntro = true - let hasSignature = true - switch (emailType) { - case 'eqs-manuscript-accepted': - hasIntro = false - hasSignature = false - paragraph = `A new ${titleText} has been submitted to ${journalName}.<br/><br/> - To begin the review process, please visit the manuscript details page.` - break - case 'he-manuscript-published': - hasLink = false - paragraph = `Thank you for your recommendation to publish ${titleText} based on the reviews you received.<br/><br/> - I can confirm this article will now go through to publication.` - break - case 'author-manuscript-published': - paragraph = `I am delighted to inform you that ${titleText} has passed through the review process and will be published in Hindawi.<br/><br/> - Thanks again for choosing to publish with us.` - hasLink = false - break - case 'submitted-reviewers-after-publish': - hasLink = false - paragraph = `Thank you for your review on ${titleText}. After taking into account the reviews and the recommendation of the Handling Editor, I can confirm this article will now be published.<br/><br/> - If you have any queries about this decision, then please email them to Hindawi as soon as possible.` - break - case 'eqa-manuscript-returned-to-eic': - paragraph = `We regret to inform you that ${titleText} has been returned with comments. Please click the link below to access the manuscript.<br/><br/> - Comments: ${comments}<br/><br/>` - break - default: - throw new Error(`The ${emailType} email type is not defined.`) - } - - return { paragraph, hasLink, hasIntro, hasSignature } -} - -module.exports = { - getEmailCopy, -} diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js deleted file mode 100644 index 8380da030638ce5c7d66293fd7531ac01841a237..0000000000000000000000000000000000000000 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js +++ /dev/null @@ -1,105 +0,0 @@ -const config = require('config') -const Email = require('@pubsweet/component-email-templating') - -const { - User, - services, - Fragment, -} = require('pubsweet-component-helper-service') -const { getEmailCopy } = require('./emailCopy') - -const { name: journalName, staffEmail } = config.get('journal') - -module.exports = { - async sendNotifications({ - agree, - baseUrl, - collection, - comments = '', - User: UserModel, - Fragment: FragmentModel, - }) { - const fragment = await FragmentModel.find(collection.fragments[0]) - const fragmentHelper = new Fragment({ fragment }) - const parsedFragment = await fragmentHelper.getFragmentData({ - handlingEditor: collection.handlingEditor, - }) - - const { submittingAuthor } = await fragmentHelper.getAuthorData({ - UserModel, - }) - - const titleText = `manuscript titled "${parsedFragment.title}" by ${ - submittingAuthor.firstName - } ${submittingAuthor.lastName}` - const subjectBaseText = `${collection.customId}: Manuscript` - const { customId } = collection - const userHelper = new User({ UserModel }) - const subject = `${subjectBaseText} ${ - agree ? '' : 'Not ' - }Passed Technical Checks` - - const email = new Email({ - type: 'user', - fromEmail: `${journalName} <${staffEmail}>`, - content: { - subject, - signatureName: 'EQA Team', - ctaLink: services.createUrl( - baseUrl, - `/projects/${collection.id}/versions/${fragment.id}/details`, - ), - ctaText: 'MANUSCRIPT DETAILS', - unsubscribeLink: baseUrl, - }, - }) - - sendEditorsEmail({ - email, - agree, - customId, - comments, - titleText, - userHelper, - }) - }, -} - -const sendEditorsEmail = async ({ - email, - agree, - titleText, - customId, - userHelper, - comments = '', -}) => { - email.content.subject = `${customId}: New manuscript submitted` - const emailType = agree - ? 'eqs-manuscript-accepted' - : 'eqa-manuscript-returned-to-eic' - - const editors = (await userHelper.getEditorsInChief()).map(eic => ({ - ...eic, - ...getEmailCopy({ - emailType, - titleText, - comments, - }), - })) - - editors.forEach(eic => { - email.toUser = { - email: eic.email, - name: `${eic.firstName} ${eic.lastName}`, - } - const { html, text } = email.getNotificationBody({ - emailBodyProps: { - paragraph: eic.paragraph, - hasLink: eic.hasLink, - hasIntro: eic.hasIntro, - hasSignature: eic.hasSignature, - }, - }) - email.sendEmail({ html, text }) - }) -} diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js index 9ae555625409f687373606fd0c409d801bf14092..04154a845eb6be4ea77388c4ec501749c0b3b90e 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js @@ -1,11 +1,7 @@ const { get, find, isEmpty, last } = require('lodash') const { services } = require('pubsweet-component-helper-service') -const { - sendNotifications: sendEQSNotifications, -} = require('./notifications/notifications') - -const Notification = require('../fragmentsRecommendations/notifications/notification') +const Notification = require('../../notifications/notification') const TECHNICAL_STEPS = { EQS: 'eqs', @@ -68,36 +64,33 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => { collection.status = setNewStatus(step, agree) await collection.save() - const isEQA = get(collection, 'technicalChecks.eqa', false) - const baseUrl = services.getBaseUrl(req) - if (isEQA) { - // the EA accepted the manuscript so we need to notify users of the final publication - const fragment = await Fragment.find(last(collection.fragments)) - const notification = new Notification({ - fragment, - collection, - UserModel: User, - baseUrl: services.getBaseUrl(req), - newRecommendation: { - recommendation: 'publish', - recommendationType: 'editorRecommendation', - }, - }) - notification.notifyAuthorsWhenEiCMakesDecision() - const hasPeerReview = !isEmpty(collection.handlingEditor) - if (hasPeerReview) { - notification.notifyHEWhenEiCMakesDecision() - notification.notifyReviewersWhenEiCMakesDecision() + const fragment = await Fragment.find(last(collection.fragments)) + const notification = new Notification({ + fragment, + collection, + UserModel: User, + baseUrl: services.getBaseUrl(req), + newRecommendation: { + recommendation: 'publish', + recommendationType: 'editorRecommendation', + }, + }) + + if (step === TECHNICAL_STEPS.EQA) { + const hasPassedEQA = get(collection, 'technicalChecks.eqa') + if (hasPassedEQA) { + // the EA accepted the manuscript so we need to notify users of the final publication decision + notification.notifyAuthorsWhenEiCMakesDecision() + const hasPeerReview = !isEmpty(collection.handlingEditor) + if (hasPeerReview) { + notification.notifyHEWhenEiCMakesDecision() + notification.notifyReviewersWhenEiCMakesDecision() + } + } else { + notification.notifyEiCWhenEQARejectsManuscript(comments) } - } else { - sendEQSNotifications({ - User, - agree, - comments, - Fragment, - collection, - baseUrl, - }) + } else if (agree) { + notification.notifyEiCWhenEQSAcceptsManuscript() } return res.status(200).json(collection) diff --git a/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js b/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js index e86097c9abb9defbad77862f1826360d5edef8fa..b090a9cb6fc1ae464488560f7032b0ff97388dea 100644 --- a/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js +++ b/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js @@ -306,8 +306,6 @@ describe('Post fragments recommendations route handler', () => { delete fragment.recommendations delete fragment.revision delete fragment.invitations - delete collection.invitations - delete collection.handlingEditor collection.technicalChecks.eqa = false const res = await requests.sendRequest({