diff --git a/packages/component-invite/src/routes/collectionsInvitations/delete.js b/packages/component-invite/src/routes/collectionsInvitations/delete.js index 3119458018dec661b6da2c2e20e3b9433aa7e3c1..1f4fae26b919dc1a238d387cbf86765860c1030d 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/delete.js +++ b/packages/component-invite/src/routes/collectionsInvitations/delete.js @@ -114,19 +114,32 @@ module.exports = models => async (req, res) => { await deleteFilesS3({ fileKeys, s3Config }) } + let shouldAuthorBeNotified + if (fragment.invitations.length > 0) { + shouldAuthorBeNotified = true + } + fragment.invitations = [] fragment.recommendations = [] fragment.revision && delete fragment.revision - fragment.save() - } + await fragment.save() - notifications.sendInvitedHEEmail({ - models, - collection, - invitedHE: user, - isCanceled: true, - baseUrl: services.getBaseUrl(req), - }) + if (shouldAuthorBeNotified) { + notifications.notifyAuthorWhenHERemoved({ + models, + collection, + baseUrl: services.getBaseUrl(req), + }) + } + } else { + notifications.sendInvitedHEEmail({ + models, + collection, + invitedHE: user, + isCanceled: true, + baseUrl: services.getBaseUrl(req), + }) + } return res.status(200).json({}) } catch (e) { diff --git a/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js b/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js index c7c665749f3f3bb53a1743c6843753186201620d..b7d6efdea3d2adf90e8182d09698f2e877017124 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js +++ b/packages/component-invite/src/routes/collectionsInvitations/emails/emailCopy.js @@ -1,6 +1,7 @@ const config = require('config') const staffEmail = config.get('journal.staffEmail') +const journalName = config.get('journal.name') const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => { let paragraph @@ -34,6 +35,14 @@ const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => { paragraph = `${targetUserName} has removed you from the role of Handling Editor for ${titleText}.<br/><br/> The manuscript will no longer appear in your dashboard. Please contact ${staffEmail} if you have any questions about this change.` break + case 'author-he-removed': + 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/> + If you have questions please email them to ${staffEmail}<br/><br/>. + Thank you for your submission to ${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 2b85380e873f1a686ed362c33c0b991eabac3aef..e17d13c12cf2301effd03495d76a2456e389a91a 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js +++ b/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js @@ -73,6 +73,56 @@ module.exports = { return email.sendEmail() }, + notifyAuthorWhenHERemoved: async ({ + baseUrl, + collection, + 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 { submittingAuthor } = await fragmentHelper.getAuthorData({ + UserModel, + }) + const submittingAuthorName = `${submittingAuthor.firstName} ${ + submittingAuthor.lastName + }` + + const userHelper = new User({ UserModel }) + const eics = await userHelper.getEditorsInChief() + const eic = eics[0] + const eicName = `${eic.firstName} ${eic.lastName}` + const { customId } = collection + + const { paragraph, ...bodyProps } = getEmailCopy({ + titleText, + targetUserName: submittingAuthorName, + emailType: 'author-he-removed', + }) + + const email = new Email({ + type: 'user', + fromEmail: `${eicName} <${staffEmail}>`, + toUser: { + email: submittingAuthor.email, + name: submittingAuthorName, + }, + content: { + subject: `${customId}: Your manuscript's editor was changed`, + paragraph, + signatureName: eicName, + signatureJournal: journalName, + unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, { + id: submittingAuthor.id, + token: submittingAuthor.accessTokens.unsubscribe, + }), + }, + bodyProps, + }) + + return email.sendEmail() + }, sendEiCEmail: async ({ reason, baseUrl,