Skip to content
Snippets Groups Projects
Commit 16c1005b authored by Mihail Hagiu's avatar Mihail Hagiu
Browse files

Merge branch 'HIN-1183-ReviewerEmailHERemoved' into 'develop'

feat(ReviewerEmailHERemoved): Created email template and implemented code for sending it

See merge request !173
parents 6e2d66fc 1af97f29
No related branches found
No related tags found
3 merge requests!196S25 - EiC submit revision,!189S25,!173feat(ReviewerEmailHERemoved): Created email template and implemented code for sending it
...@@ -2,6 +2,7 @@ const config = require('config') ...@@ -2,6 +2,7 @@ const config = require('config')
const { const {
Team, Team,
Fragment,
services, services,
authsome: authsomeHelper, authsome: authsomeHelper,
} = require('pubsweet-component-helper-service') } = require('pubsweet-component-helper-service')
...@@ -70,6 +71,7 @@ module.exports = models => async (req, res) => { ...@@ -70,6 +71,7 @@ module.exports = models => async (req, res) => {
const fragment = await FragmentModel.find( const fragment = await FragmentModel.find(
last(get(collection, 'fragments', [])), last(get(collection, 'fragments', [])),
) )
const fragmentHelper = new Fragment({ fragment })
const fragmentId = fragment.id const fragmentId = fragment.id
const teamHelperForFragment = new Team({ const teamHelperForFragment = new Team({
...@@ -119,6 +121,17 @@ module.exports = models => async (req, res) => { ...@@ -119,6 +121,17 @@ module.exports = models => async (req, res) => {
shouldAuthorBeNotified = true shouldAuthorBeNotified = true
} }
const reviewers = [
...(await fragmentHelper.getReviewers({
UserModel,
type: 'accepted',
})),
...(await fragmentHelper.getReviewers({
UserModel,
type: 'submitted',
})),
]
fragment.invitations = [] fragment.invitations = []
fragment.recommendations = [] fragment.recommendations = []
fragment.revision && delete fragment.revision fragment.revision && delete fragment.revision
...@@ -131,6 +144,13 @@ module.exports = models => async (req, res) => { ...@@ -131,6 +144,13 @@ module.exports = models => async (req, res) => {
baseUrl: services.getBaseUrl(req), baseUrl: services.getBaseUrl(req),
}) })
notifications.notifyReviewersWhenHERemoved({
models,
collection,
reviewers,
baseUrl: services.getBaseUrl(req),
})
if (shouldAuthorBeNotified) { if (shouldAuthorBeNotified) {
notifications.notifyAuthorWhenHERemoved({ notifications.notifyAuthorWhenHERemoved({
models, models,
......
...@@ -39,7 +39,7 @@ const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => { ...@@ -39,7 +39,7 @@ const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => {
hasIntro = true hasIntro = true
hasLink = false hasLink = false
hasSignature = true 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/> If you have questions please email them to ${staffEmail}.<br/><br/>
Thank you for your submission to ${journalName}.` Thank you for your submission to ${journalName}.`
break break
...@@ -47,10 +47,18 @@ const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => { ...@@ -47,10 +47,18 @@ const getEmailCopy = ({ emailType, titleText, targetUserName, comments }) => {
hasIntro = true hasIntro = true
hasLink = false hasLink = false
hasSignature = true 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/> If you have any questions regarding this action, please let us know at ${staffEmail}.<br/><br/>
Thank you for reviewing ${journalName}.` Thank you for reviewing ${journalName}.`
break 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: default:
throw new Error(`The ${emailType} email type is not defined.`) throw new Error(`The ${emailType} email type is not defined.`)
} }
......
...@@ -157,6 +157,50 @@ module.exports = { ...@@ -157,6 +157,50 @@ module.exports = {
return email.sendEmail() 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 ({ sendEiCEmail: async ({
reason, reason,
baseUrl, baseUrl,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment