diff --git a/packages/component-helper-service/src/services/Collection.js b/packages/component-helper-service/src/services/Collection.js index 40affb63b76e5970b505ea5300633084b931d141..d4a4310b2e39b974037596a603de4ecfac7e7354 100644 --- a/packages/component-helper-service/src/services/Collection.js +++ b/packages/component-helper-service/src/services/Collection.js @@ -68,9 +68,10 @@ class Collection { handlingEditor.hasAnswer = true handlingEditor.isAccepted = isAccepted handlingEditor.respondedOn = Date.now() - let status - isAccepted ? (status = 'heAssigned') : (status = 'submitted') - await this.updateStatus({ newStatus: status }) + + const newStatus = isAccepted ? 'heAssigned' : 'submitted' + + await this.updateStatus({ newStatus }) } async updateStatusByNumberOfReviewers({ invitations }) { 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 cd53b027ff0df7274526507ee92e9a8562426616..bb1302a2fb093c93316475c47e9532093ae9cde0 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/helpers.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/helpers.js @@ -1,322 +1,12 @@ -const config = require('config') -const { get, chain } = require('lodash') - -const { services } = require('pubsweet-component-helper-service') -const { getEmailCopy } = require('./emailCopy') - -const unsubscribeSlug = config.get('unsubscribe.url') -const { name: journalName, staffEmail } = config.get('journal') +const { get } = require('lodash') module.exports = { - sendReviewersEmail: async ({ email, baseUrl, reviewers }) => { - reviewers.forEach(reviewer => { - email.toUser = { - email: reviewer.email, - name: `${reviewer.lastName}`, - } - email.content.unsubscribeLink = services.createUrl( - baseUrl, - unsubscribeSlug, - { - id: reviewer.id, - token: reviewer.accessTokens.unsubscribe, - }, - ) - const emailBodyProps = { - paragraph: reviewer.paragraph, - hasLink: reviewer.hasLink, - hasIntro: reviewer.hasIntro, - hasSignature: reviewer.hasSignature, - } - - const { html, text } = email.getNotificationBody({ emailBodyProps }) - email.sendEmail({ html, text }) - }) - }, - getSubmittedReviewers: async ({ - UserModel, - titleText, - fragmentHelper, - recommendation, - }) => { - const emailType = - recommendation === 'publish' - ? 'submitted-reviewers-after-publish' - : 'submitted-reviewers-after-reject' - - const reviewers = (await fragmentHelper.getReviewers({ - UserModel, - type: 'submitted', - })).map(rev => ({ - ...rev, - emailType, - ...getEmailCopy({ - emailType, - titleText, - }), - })) - - return reviewers - }, - getNoResponseReviewers: async ({ fragmentHelper, UserModel, titleText }) => { - const acceptedReviewers = (await fragmentHelper.getReviewers({ - UserModel, - type: 'accepted', - })).map(rev => ({ - ...rev, - ...getEmailCopy({ - emailType: 'accepted-reviewers-after-recommendation', - titleText, - }), - })) - - const pendingReviewers = (await fragmentHelper.getReviewers({ - UserModel, - type: 'pending', - })).map(rev => ({ - ...rev, - ...getEmailCopy({ - emailType: 'pending-reviewers-after-recommendation', - titleText, - }), - })) - - const reviewers = [...acceptedReviewers, ...pendingReviewers] - - return reviewers - }, - updateEmailContentForReviewers: ({ - email, - customId, - signatureName, - recommendation, - }) => { - const subject = - recommendation === 'publish' - ? 'A manuscript you reviewed has been accepted' - : 'A manuscript you reviewed has been rejected' - - email.content.subject = `${customId}: ${subject}` - email.content.signatureName = signatureName - email.content.signatureJournal = journalName - email.fromEmail = `${signatureName} <$staffEmail>` - return email - }, - sendHandlingEditorEmail: ({ - email, - comments, - emailType, - titleText, - targetUserName, - }) => { - const { html, text } = email.getNotificationBody({ - emailBodyProps: getEmailCopy({ - emailType, - titleText, - comments, - targetUserName, - }), - }) - email.sendEmail({ html, text }) - }, - updateEmailContentForHE: ({ - email, - baseUrl, - eicName, - customId, - heLastName, - handlingEditor, - recommendation, - recommendationType, - }) => { - // TODO: this should probably be split in two functions, one for each type - email.fromEmail = `${eicName} <${staffEmail}>` - if (recommendationType === 'review') { - email.content.subject = `${customId}: A review has been submitted` - } else { - switch (recommendation) { - case 'return-to-handling-editor': - email.content.subject = `${customId}: Editorial decision returned with comments` - break - case 'publish': - case 'reject': - email.content.subject = `${customId}: Editorial decision confirmed` - break - default: - throw new Error(`Undefined recommendation: ${recommendation}`) - } - } - - email.toUser = { - email: handlingEditor.email, - name: heLastName, - } - email.content.unsubscribeLink = services.createUrl( - baseUrl, - unsubscribeSlug, - { - id: handlingEditor.id, - token: handlingEditor.accessTokens.unsubscribe, - }, - ) - - email.content.signatureName = eicName - delete email.content.signatureJournal - - return email - }, - getEmailTypeByRecommendationForHE: ({ - recommendation, - recommendationType, - }) => { - let emailType - if (recommendationType === 'review') { - emailType = 'he-review-submitted' - } else { - switch (recommendation) { - case 'return-to-handling-editor': - emailType = 'he-manuscript-return-with-comments' - break - case 'publish': - emailType = 'he-manuscript-published' - break - case 'reject': - emailType = 'he-manuscript-rejected' - break - default: - throw new Error(`undefined recommendation: ${recommendation} `) - } - } - - return emailType - }, - getEiCCommentsForHE: ({ newRecommendation }) => { - const eicComments = chain(newRecommendation) - .get('comments') - .find(comm => !comm.public) - .get('content') - .value() - - return eicComments - }, - sendEiCsEmail: async ({ - email, - customId, - titleText, - userHelper, - targetUserName, - recommendation: { recommendation, comments: recComments = [] }, - }) => { - let emailType - email.fromEmail = `${journalName} <${staffEmail}>` - switch (recommendation) { - case 'minor': - case 'major': - emailType = 'eic-request-revision-from-he' - email.content.subject = `${customId}: Revision requested` - break - case 'publish': - emailType = 'eic-recommend-to-publish-from-he' - email.content.subject = `${customId}: Recommendation to publish` - break - case 'reject': - emailType = 'eic-recommend-to-reject-from-he' - email.content.subject = `${customId}: Recommendation to reject` - break - default: - throw new Error(`undefined recommendation: ${recommendation} `) - } - delete email.content.signatureJournal - - const privateNote = recComments.find(comm => !comm.public) - const content = get(privateNote, 'content') - const comments = content - ? `The editor provided the following comments: "${content}"` - : '' - - const editors = (await userHelper.getEditorsInChief()).map(eic => ({ - ...eic, - ...getEmailCopy({ - comments, - emailType, - titleText, - targetUserName, - }), - })) - - 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 }) - }) - }, - sendAuthorsEmail: async ({ email, authors, baseUrl }) => { - authors.forEach(author => { - email.toUser = { - email: author.email, - name: `${author.lastName}`, - } - email.content.unsubscribeLink = services.createUrl( - baseUrl, - unsubscribeSlug, - { - id: author.id, - token: author.accessTokens.unsubscribe, - }, - ) - const { html, text } = email.getNotificationBody({ - emailBodyProps: { - paragraph: author.paragraph, - hasLink: author.hasLink, - hasIntro: author.hasIntro, - hasSignature: author.hasSignature, - }, - }) - email.sendEmail({ html, text }) - }) - }, - // getSubmittingAuthor: ({ - // title, - // journalName, - // authorNoteText, - // submittingAuthor, - // }) => { - // const author = { - // ...submittingAuthor, - // ...getEmailCopy({ - // emailType: 'author-request-to-revision', - // titleText: `your submission "${title}" to ${journalName}`, - // comments: authorNoteText, - // }), - // } - - // return author - // }, getPrivateNoteTextForAuthor: ({ newRecommendation }) => { const authorNote = newRecommendation.comments.find(comm => comm.public) const content = get(authorNote, 'content') - const authorNoteText = content ? `Reason & Details: "${content}"` : '' - return authorNoteText + return content ? `Reason & Details: "${content}"` : '' }, - // updateEmailContentForSA: ({ email, customId, signatureName }) => { - // email.fromEmail = `${signatureName} <${staffEmail}>` - // email.content.subject = `${customId}: Revision requested` - // email.content.signatureName = signatureName - // email.content.signatureJournal = journalName - - // return email - // }, getHEComments: ({ heRecommendation }) => { const heComments = get(heRecommendation, 'comments', []) @@ -328,65 +18,8 @@ module.exports = { if (!content) { throw new Error('a public comment cannot be without content') } - const comments = `Please find our editorial comments below.<br/> "${content}"` - - return comments - }, - getAllAuthors: ({ title, comments, emailType, fragmentAuthors }) => { - const authors = fragmentAuthors.map(author => ({ - ...author, - ...getEmailCopy({ - comments, - emailType, - titleText: `your manuscript titled "${title}"`, - }), - })) - return authors - }, - // sendSubmittingAuthorEmail: ({ email, author, baseUrl }) => { - // email.toUser = { - // email: author.email, - // name: `${author.lastName}`, - // } - // email.content.unsubscribeLink = services.createUrl( - // baseUrl, - // unsubscribeSlug, - // { - // id: author.id, - // token: author.accessTokens.unsubscribe, - // }, - // ) - // const { html, text } = email.getNotificationBody({ - // emailBodyProps: { - // paragraph: author.paragraph, - // hasLink: author.hasLink, - // hasIntro: author.hasIntro, - // hasSignature: author.hasSignature, - // }, - // }) - // email.sendEmail({ html, text }) - // }, - updateEmailContentForAllAuthors: ({ - email, - recommendation, - customId, - eicName, - }) => { - email.fromEmail = `${eicName} <${staffEmail}>` - switch (recommendation) { - case 'publish': - email.content.subject = `${customId}: Manuscript accepted` - break - case 'reject': - email.content.subject = `${customId}: Manuscript rejected` - break - default: - throw new Error(`Undefined recommendation: ${recommendation}`) - } - email.content.signatureJournal = journalName - - return email + return `Please find our editorial comments below.<br/> "${content}"` }, getEmailTypeByRecommendationForAuthors: ({ recommendation, @@ -408,58 +41,4 @@ module.exports = { return emailType }, - sendEQAEmail: ({ - email, - eicName, - baseUrl, - titleText, - collection, - subjectBaseText, - }) => { - let emailType - switch (collection.status) { - case 'accepted': - emailType = 'eqa-manuscript-published' - email.content.subject = `${subjectBaseText} decision finalized` - break - case 'inQA': - emailType = 'eqa-manuscript-request-for-approval' - email.content.subject = `${subjectBaseText} Request for EQA Approval` - email.content.ctaLink = services.createUrl( - baseUrl, - config.get('eqa-decision.url'), - { - collectionId: collection.id, - customId: collection.customId, - token: collection.technicalChecks.token, - }, - ) - email.content.ctaText = 'MAKE DECISION' - break - default: - throw new Error( - `Cannot send EQA email when collection status is ${ - collection.status - } `, - ) - } - - email.toUser = { - email: editorialAssistantEmail, - name: 'Editorial Assistant', - } - - email.content.unsubscribeLink = baseUrl - email.content.signatureName = eicName - - const { html, text } = email.getNotificationBody({ - emailBodyProps: getEmailCopy({ - eicName, - titleText, - emailType, - customId: collection.customId, - }), - }) - email.sendEmail({ html, text }) - }, } diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js index 039308228bfe2c1453c1e9ada3856ca86869d2b2..583764760db7716f8598f0dc5e52d8ba84b533ce 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js @@ -59,12 +59,14 @@ class Notification { }, }) - helpers.sendHandlingEditorEmail({ - email, + const emailBodyProps = getEmailCopy({ + emailType: 'he-review-submitted', titleText, targetUserName: reviewerLastName, - emailType: 'he-review-submitted', }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) + email.sendEmail({ html, text }) } // EiC decided to either publish or reject the manuscript @@ -99,10 +101,8 @@ class Notification { ), }, }) - delete email.content.signatureJournal - helpers.sendHandlingEditorEmail({ - email, + const emailBodyProps = getEmailCopy({ titleText, targetUserName: eicName, emailType: @@ -110,6 +110,9 @@ class Notification { ? 'he-manuscript-published' : 'he-manuscript-rejected', }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) + email.sendEmail({ html, text }) } async notifyHEWhenEiCReturnsToHE() { @@ -143,7 +146,6 @@ class Notification { ), }, }) - delete email.content.signatureJournal const eicComments = chain(this.newRecommendation) .get('comments') @@ -151,13 +153,15 @@ class Notification { .get('content') .value() - helpers.sendHandlingEditorEmail({ - email, + const emailBodyProps = getEmailCopy({ titleText, comments: eicComments, targetUserName: eicName, emailType: 'he-manuscript-return-with-comments', }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) + email.sendEmail({ html, text }) } async notifyEAWhenEiCMakesFinalDecision() { @@ -176,13 +180,12 @@ class Notification { }, }) - const { html, text } = email.getNotificationBody({ - emailBodyProps: getEmailCopy({ - eicName, - titleText, - emailType: 'eqa-manuscript-published', - }), + const emailBodyProps = getEmailCopy({ + eicName, + titleText, + emailType: 'eqa-manuscript-published', }) + const { html, text } = email.getNotificationBody({ emailBodyProps }) email.sendEmail({ html, text }) } @@ -212,13 +215,13 @@ class Notification { }, }) - const { html, text } = email.getNotificationBody({ - emailBodyProps: getEmailCopy({ - eicName, - customId: this.collection.customId, - emailType: 'eqa-manuscript-request-for-approval', - }), + const emailBodyProps = getEmailCopy({ + eicName, + customId: this.collection.customId, + emailType: 'eqa-manuscript-request-for-approval', }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) email.sendEmail({ html, text }) } @@ -278,14 +281,13 @@ class Notification { }, }) - const { html, text } = email.getNotificationBody({ - emailBodyProps: getEmailCopy({ - titleText, - emailType, - comments, - }), + const emailBodyProps = getEmailCopy({ + titleText, + emailType, + comments, }) + const { html, text } = email.getNotificationBody({ emailBodyProps }) email.sendEmail({ html, text }) }) } @@ -359,22 +361,14 @@ class Notification { const authorNoteText = helpers.getPrivateNoteTextForAuthor({ newRecommendation: this.newRecommendation, }) - const author = { - ...submittingAuthor, - ...getEmailCopy({ - emailType: 'author-request-to-revision', - titleText: `your submission "${title}" to ${journalName}`, - comments: authorNoteText, - }), - } const signatureName = get(this.collection, 'handlingEditor.name', eicName) const email = new Email({ type: 'user', toUser: { - email: author.email, - name: author.lastName, + email: submittingAuthor.email, + name: submittingAuthor.lastName, }, fromEmail: `${signatureName} <${staffEmail}>`, content: { @@ -383,8 +377,8 @@ class Notification { signatureJournal: journalName, subject: `${this.collection.customId}: Revision requested`, unsubscribeLink: services.createUrl(this.baseUrl, unsubscribeSlug, { - id: author.id, - token: author.accessTokens.unsubscribe, + id: submittingAuthor.id, + token: submittingAuthor.accessTokens.unsubscribe, }), ctaLink: services.createUrl( this.baseUrl, @@ -395,14 +389,13 @@ class Notification { }, }) - const { html, text } = email.getNotificationBody({ - emailBodyProps: { - paragraph: author.paragraph, - hasLink: author.hasLink, - hasIntro: author.hasIntro, - hasSignature: author.hasSignature, - }, + const emailBodyProps = getEmailCopy({ + emailType: 'author-request-to-revision', + titleText: `your submission "${title}" to ${journalName}`, + comments: authorNoteText, }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) email.sendEmail({ html, text }) } diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js deleted file mode 100644 index 10034e07b1eec5ea0740456c574a839f652335d0..0000000000000000000000000000000000000000 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js +++ /dev/null @@ -1,515 +0,0 @@ -const config = require('config') -const { get, isEmpty } = require('lodash') -const Email = require('@pubsweet/component-email-templating') - -const { - User, - services, - Fragment, - Collection, -} = require('pubsweet-component-helper-service') - -const { getEmailCopy } = require('./emailCopy') -const helpers = require('./helpers') - -const editorialAssistantEmail = config.get('journal.staffEmail') -const { name: journalName } = config.get('journal') - -module.exports = { - // async sendNotifications({ - // hasEQA, - // baseUrl, - // fragment, - // UserModel, - // collection, - // targetUserName, - // isEditorInChief, - // newRecommendation, - // }) { - // const fragmentHelper = new Fragment({ fragment }) - // const parsedFragment = await fragmentHelper.getFragmentData({ - // handlingEditor: collection.handlingEditor, - // }) - // const { - // activeAuthors, - // submittingAuthor, - // } = await fragmentHelper.getAuthorData({ UserModel }) - - // const subjectBaseText = `${collection.customId}: Manuscript` - // const titleText = `The manuscript titled "${parsedFragment.title}" by ${ - // submittingAuthor.firstName - // } ${submittingAuthor.lastName}` - - // const userHelper = new User({ UserModel }) - // const eicName = await userHelper.getEiCName() - - // let email = new Email({ - // type: 'user', - // content: { - // signatureName: eicName, - // unsubscribeLink: baseUrl, - // ctaText: 'MANUSCRIPT DETAILS', - // signatureJournal: journalName, - // ctaLink: services.createUrl( - // baseUrl, - // `/projects/${collection.id}/versions/${fragment.id}/details`, - // ), - // }, - // }) - - // const { recommendation, recommendationType } = newRecommendation - - // // the EiC recommends to publish so an email to the EQA needs to be sent, - // // one requesting approval or one informing them that the manuscript has been published - // if ( - // isEditorInChief && - // recommendation === 'publish' && - // collection.technicalChecks.token - // ) { - // sendEQAEmail({ - // email, - // eicName, - // baseUrl, - // titleText, - // collection, - // subjectBaseText, - // }) - // } - - // const hasPeerReview = !isEmpty(collection.handlingEditor) - // const { customId } = collection - // const collHelper = new Collection({ collection }) - - // // send HE emails when a review is submitted - // // or when the EiC makes a recommendation after peer review - // if ( - // recommendationType === 'review' || - // (isEditorInChief && - // hasPeerReview && - // (recommendation !== 'publish' || hasEQA)) - // ) { - // const handlingEditor = get(collection, 'handlingEditor', {}) - // const heUser = await UserModel.find(handlingEditor.id) - // email = helpers.updateEmailContentForHE({ - // email, - // baseUrl, - // eicName, - // customId, - // recommendation, - // recommendationType, - // heLastName: collHelper.getHELastName(), - // handlingEditor: heUser, - // }) - // const emailType = helpers.getEmailTypeByRecommendationForHE({ - // recommendation, - // recommendationType, - // }) - // const comments = helpers.getEiCCommentsForHE({ newRecommendation }) - // helpers.sendHandlingEditorEmail({ - // email, - // comments, - // emailType, - // titleText, - // targetUserName, - // }) - // } - - // if ( - // recommendationType === 'review' || - // recommendation === 'return-to-handling-editor' - // ) { - // return - // } - - // // when publishing, only send emails to authors if the manuscript has passed EQA - // if (isEditorInChief && (recommendation !== 'publish' || hasEQA)) { - // // send all authors email - // const emailType = helpers.getEmailTypeByRecommendationForAuthors({ - // recommendation, - // hasPeerReview, - // }) - - // let comments - // if (hasPeerReview) { - // comments = helpers.getHEComments({ - // heRecommendation: parsedFragment.heRecommendation, - // }) - // } else { - // comments = newRecommendation.comments[0].content - // } - - // const authors = helpers.getAllAuthors({ - // comments, - // emailType, - // title: parsedFragment.title, - // fragmentAuthors: activeAuthors, - // }) - // email = helpers.updateEmailContentForAllAuthors({ - // email, - // eicName, - // customId, - // recommendation, - // }) - // helpers.sendAuthorsEmail({ email, authors, baseUrl }) - // } - - // // send email to SA when the HE requests a revision - // if (collection.status === 'revisionRequested') { - // const authorNoteText = helpers.getPrivateNoteTextForAuthor({ - // newRecommendation, - // }) - // const author = helpers.getSubmittingAuthor({ - // journalName, - // authorNoteText, - // submittingAuthor, - // title: parsedFragment.title, - // }) - // email = helpers.updateEmailContentForSA({ - // email, - // customId, - // signatureName: get(collection, 'handlingEditor.name', eicName), - // }) - - // helpers.sendSubmittingAuthorEmail({ email, author, baseUrl }) - // } - - // if (!hasPeerReview) { - // return - // } - - // let reviewers = [] - // if (isEditorInChief) { - // if (recommendation !== 'publish' || hasEQA) { - // email = helpers.updateEmailContentForReviewers({ - // email, - // customId, - // recommendation, - // signatureName: eicName, - // }) - // reviewers = await helpers.getSubmittedReviewers({ - // UserModel, - // titleText, - // fragmentHelper, - // recommendation, - // }) - // } - // } else { - // email = helpers.updateEmailContentForReviewers({ - // email, - // customId, - // subject: `Review no longer required`, - // signatureName: get(collection, 'handlingEditor.name', eicName), - // }) - - // reviewers = await helpers.getNoResponseReviewers({ - // UserModel, - // titleText, - // fragmentHelper, - // }) - - // helpers.sendEiCsEmail({ - // email, - // baseUrl, - // customId, - // userHelper, - // recommendation: newRecommendation, - // targetUserName: collHelper.getHELastName(), - // titleText: `the submission "${parsedFragment.title}" by ${ - // submittingAuthor.firstName - // } ${submittingAuthor.lastName}`, - // }) - // } - - // helpers.sendReviewersEmail({ email, baseUrl, reviewers }) - // }, - async sendNotificationsWhenEiCMakesDecision({ - hasEQA, - baseUrl, - fragment, - UserModel, - collection, - targetUserName, - newRecommendation, - }) { - const fragmentHelper = new Fragment({ fragment }) - const parsedFragment = await fragmentHelper.getFragmentData({ - handlingEditor: collection.handlingEditor, - }) - const { - activeAuthors, - submittingAuthor, - } = await fragmentHelper.getAuthorData({ UserModel }) - - const subjectBaseText = `${collection.customId}: Manuscript` - const titleText = `The manuscript titled "${parsedFragment.title}" by ${ - submittingAuthor.firstName - } ${submittingAuthor.lastName}` - - const userHelper = new User({ UserModel }) - const eicName = await userHelper.getEiCName() - - let email = new Email({ - type: 'user', - content: { - signatureName: eicName, - unsubscribeLink: baseUrl, - ctaText: 'MANUSCRIPT DETAILS', - signatureJournal: journalName, - ctaLink: services.createUrl( - baseUrl, - `/projects/${collection.id}/versions/${fragment.id}/details`, - ), - }, - }) - - const { recommendation, recommendationType } = newRecommendation - // the EiC recommends to publish so an email to the EQA needs to be sent, - // one requesting approval or one informing them that the manuscript has been published - if (recommendation === 'publish' && collection.technicalChecks.token) { - helpers.sendEQAEmail({ - email, - eicName, - baseUrl, - titleText, - collection, - subjectBaseText, - }) - } - - const hasPeerReview = !isEmpty(collection.handlingEditor) - const { customId } = collection - const collHelper = new Collection({ collection }) - - // send email to HE when the EiC makes a recommendation after peer review - if (hasPeerReview && (recommendation !== 'publish' || hasEQA)) { - const handlingEditor = get(collection, 'handlingEditor', {}) - const heUser = await UserModel.find(handlingEditor.id) - email = helpers.updateEmailContentForHE({ - email, - baseUrl, - eicName, - customId, - recommendation, - recommendationType, - heLastName: collHelper.getHELastName(), - handlingEditor: heUser, - }) - const emailType = helpers.getEmailTypeByRecommendationForHE({ - recommendation, - recommendationType, - }) - const comments = helpers.getEiCCommentsForHE({ newRecommendation }) - helpers.sendHandlingEditorEmail({ - email, - comments, - emailType, - titleText, - targetUserName, - }) - } - - // when publishing, only send emails to authors and reviewer if the manuscript has passed EQA - if (recommendation !== 'publish' || hasEQA) { - // send all authors email - const emailType = helpers.getEmailTypeByRecommendationForAuthors({ - recommendation, - hasPeerReview, - }) - - let comments - if (hasPeerReview) { - comments = helpers.getHEComments({ - heRecommendation: parsedFragment.heRecommendation, - }) - } else { - comments = newRecommendation.comments[0].content - } - - const authors = helpers.getAllAuthors({ - comments, - emailType, - title: parsedFragment.title, - fragmentAuthors: activeAuthors, - }) - email = helpers.updateEmailContentForAllAuthors({ - email, - eicName, - customId, - recommendation, - }) - helpers.sendAuthorsEmail({ email, authors, baseUrl }) - - email = helpers.updateEmailContentForReviewers({ - email, - customId, - recommendation, - signatureName: eicName, - }) - const reviewers = await helpers.getSubmittedReviewers({ - UserModel, - titleText, - fragmentHelper, - recommendation, - }) - helpers.sendReviewersEmail({ email, baseUrl, reviewers }) - } - }, - async sendNotificationsWhenHEMakesRecommendation({ - baseUrl, - fragment, - UserModel, - collection, - newRecommendation, - }) { - const fragmentHelper = new Fragment({ fragment }) - const parsedFragment = await fragmentHelper.getFragmentData({ - handlingEditor: collection.handlingEditor, - }) - const { submittingAuthor } = await fragmentHelper.getAuthorData({ - UserModel, - }) - - const titleText = `The manuscript titled "${parsedFragment.title}" by ${ - submittingAuthor.firstName - } ${submittingAuthor.lastName}` - - const { customId } = collection - const collHelper = new Collection({ collection }) - const userHelper = new User({ UserModel }) - const eicName = await userHelper.getEiCName() - - let email = new Email({ - type: 'user', - content: { - signatureName: eicName, - unsubscribeLink: baseUrl, - ctaText: 'MANUSCRIPT DETAILS', - signatureJournal: journalName, - ctaLink: services.createUrl( - baseUrl, - `/projects/${collection.id}/versions/${fragment.id}/details`, - ), - }, - }) - - // send email to SA when the HE requests a revision - if (collection.status === 'revisionRequested') { - const authorNoteText = helpers.getPrivateNoteTextForAuthor({ - newRecommendation, - }) - const author = helpers.getSubmittingAuthor({ - journalName, - authorNoteText, - submittingAuthor, - title: parsedFragment.title, - }) - email = helpers.updateEmailContentForSA({ - email, - customId, - signatureName: get(collection, 'handlingEditor.name', eicName), - }) - - helpers.sendSubmittingAuthorEmail({ email, author, baseUrl }) - } - - const hasPeerReview = !isEmpty(collection.handlingEditor) - - if (!hasPeerReview) { - return - } - - email = helpers.updateEmailContentForReviewers({ - email, - customId, - subject: `Review no longer required`, - signatureName: get(collection, 'handlingEditor.name', eicName), - }) - - const reviewers = await helpers.getNoResponseReviewers({ - UserModel, - titleText, - fragmentHelper, - }) - helpers.sendReviewersEmail({ email, baseUrl, reviewers }) - - helpers.sendEiCsEmail({ - email, - baseUrl, - customId, - userHelper, - recommendation: newRecommendation, - targetUserName: collHelper.getHELastName(), - titleText: `the submission "${parsedFragment.title}" by ${ - submittingAuthor.firstName - } ${submittingAuthor.lastName}`, - }) - }, - async sendNotificationsWhenReviewerSubmitsReport({ - UserModel, - collection, - newRecommendation, - baseUrl, - fragment, - targetUserName, - }) { - const fragmentHelper = new Fragment({ fragment }) - const parsedFragment = await fragmentHelper.getFragmentData({ - handlingEditor: collection.handlingEditor, - }) - const { submittingAuthor } = await fragmentHelper.getAuthorData({ - UserModel, - }) - - const titleText = `The manuscript titled "${parsedFragment.title}" by ${ - submittingAuthor.firstName - } ${submittingAuthor.lastName}` - - const userHelper = new User({ UserModel }) - const eicName = await userHelper.getEiCName() - - let email = new Email({ - type: 'user', - content: { - signatureName: eicName, - unsubscribeLink: baseUrl, - ctaText: 'MANUSCRIPT DETAILS', - signatureJournal: journalName, - ctaLink: services.createUrl( - baseUrl, - `/projects/${collection.id}/versions/${fragment.id}/details`, - ), - }, - }) - - const { recommendation, recommendationType } = newRecommendation - - const handlingEditor = get(collection, 'handlingEditor', {}) - const heUser = await UserModel.find(handlingEditor.id) - - const { customId } = collection - const collHelper = new Collection({ collection }) - - email = helpers.updateEmailContentForHE({ - email, - baseUrl, - eicName, - customId, - recommendation, - recommendationType, - heLastName: collHelper.getHELastName(), - handlingEditor: heUser, - }) - const emailType = helpers.getEmailTypeByRecommendationForHE({ - recommendation, - recommendationType, - }) - const comments = helpers.getEiCCommentsForHE({ newRecommendation }) - helpers.sendHandlingEditorEmail({ - email, - comments, - emailType, - titleText, - targetUserName, - }) - }, -}