diff --git a/packages/component-invite/src/routes/collectionsInvitations/delete.js b/packages/component-invite/src/routes/collectionsInvitations/delete.js index 8442dea8cc79be967061c9846127f4d2d34846d9..c93402add18d6180d6f47bb688bd2b77fb7a1f4f 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/delete.js +++ b/packages/component-invite/src/routes/collectionsInvitations/delete.js @@ -2,6 +2,7 @@ const config = require('config') const { Team, + Fragment, services, authsome: authsomeHelper, } = require('pubsweet-component-helper-service') @@ -70,6 +71,7 @@ module.exports = models => async (req, res) => { const fragment = await FragmentModel.find( last(get(collection, 'fragments', [])), ) + const fragmentHelper = new Fragment({ fragment }) const fragmentId = fragment.id const teamHelperForFragment = new Team({ @@ -119,6 +121,17 @@ module.exports = models => async (req, res) => { shouldAuthorBeNotified = true } + const reviewers = [ + ...(await fragmentHelper.getReviewers({ + UserModel, + type: 'accepted', + })), + ...(await fragmentHelper.getReviewers({ + UserModel, + type: 'submitted', + })), + ] + fragment.invitations = [] fragment.recommendations = [] fragment.revision && delete fragment.revision @@ -131,6 +144,13 @@ module.exports = models => async (req, res) => { baseUrl: services.getBaseUrl(req), }) + notifications.notifyReviewersWhenHERemoved({ + models, + collection, + reviewers, + baseUrl: services.getBaseUrl(req), + }) + if (shouldAuthorBeNotified) { notifications.notifyAuthorWhenHERemoved({ models, diff --git a/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js b/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js index 54db6a8357ffc883df3a8c9c2123bd6ab8452003..66a72b51a80df466da1511014dc702a0132b035b 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js +++ b/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js @@ -39,7 +39,7 @@ const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => { hasIntro = true hasLink = false hasSignature = true - paragraph = `The handling editor of your manuscript "${titleText}" had to be replaced. This may cause some delays in the peer review process.<br/><br/> + paragraph = `We had to replace the handling editor of your manuscript ${titleText}. We apologise for any inconvenience, but it was necessary in order to move your manuscript forward.<br/><br/> If you have questions please email them to ${staffEmail}.<br/><br/> Thank you for your submission to ${journalName}.` break @@ -47,10 +47,18 @@ const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => { hasIntro = true hasLink = false hasSignature = true - paragraph = `The Editor in Chief removed you from the manuscript "${titleText}".<br/><br/> + paragraph = `The editor in chief removed you from the manuscript "${titleText}".<br/><br/> If you have any questions regarding this action, please let us know at ${staffEmail}.<br/><br/> Thank you for reviewing ${journalName}.` break + case 'reviewer-he-removed': + hasIntro = true + hasLink = false + hasSignature = true + paragraph = `We had to replace the handling editor of the manuscript "${titleText}". We apologise for any inconvenience this may cause.<br/><br/> + If you have started the review process please email the content to ${staffEmail}.<br/><br/> + Thank you for reviewing ${journalName}.` + break default: throw new Error(`The ${emailType} email type is not defined.`) } diff --git a/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js b/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js index 10de02e83f68a525e6cf39f1702290dae90c316b..d1378dca273dcb3be93426c1841c71f4685e085d 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js +++ b/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js @@ -157,6 +157,50 @@ module.exports = { return email.sendEmail() }, + notifyReviewersWhenHERemoved: async ({ + baseUrl, + collection, + reviewers, + models: { User: UserModel, Fragment: FragmentModel }, + }) => { + const fragmentId = last(collection.fragments) + const fragment = await FragmentModel.find(fragmentId) + const fragmentHelper = new Fragment({ fragment }) + const { title: titleText } = await fragmentHelper.getFragmentData() + + const userHelper = new User({ UserModel }) + const eicName = await userHelper.getEiCName() + const { customId } = collection + + const { paragraph, ...bodyProps } = getEmailCopy({ + titleText, + emailType: 'reviewer-he-removed', + }) + + reviewers.forEach(reviewer => { + const email = new Email({ + type: 'user', + toUser: { + email: reviewer.email, + name: reviewer.lastName, + }, + fromEmail: `${eicName} <${staffEmail}>`, + content: { + subject: `${customId}: The handling editor of a manuscript that you were reviewing was changed`, + paragraph, + signatureName: eicName, + signatureJournal: journalName, + unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, { + id: reviewer.id, + token: reviewer.accessTokens.unsubscribe, + }), + }, + bodyProps, + }) + + return email.sendEmail() + }) + }, sendEiCEmail: async ({ reason, baseUrl,