Skip to content
Snippets Groups Projects
Commit 6a1f488d authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

Merge branch 'hin-853-send-email-to-all-authors-after-eqs-approves' into 'develop'

feat(component-manuscript-manager): send emails to all authors after submit

See merge request !36
parents 8712f9b2 39999e77
No related branches found
No related tags found
2 merge requests!43Sprint #19,!36feat(component-manuscript-manager): send emails to all authors after submit
...@@ -11,8 +11,7 @@ const { getEmailCopy } = require('./emailCopy') ...@@ -11,8 +11,7 @@ const { getEmailCopy } = require('./emailCopy')
module.exports = { module.exports = {
async sendNotifications({ user, baseUrl, role, UserModel }) { async sendNotifications({ user, baseUrl, role, UserModel }) {
const userHelper = new User({ UserModel }) const userHelper = new User({ UserModel })
const { firstName, lastName } = await userHelper.getEditorsInChief() const eicName = await userHelper.getEiCName()
const eicName = `${firstName} ${lastName}`
const email = new Email({ const email = new Email({
type: 'user', type: 'user',
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<table border="0" cellPadding="0" cellSpacing="0" class="button-css__deep-table___2OZyb wrapper-mobile" style="text-align:center"> <table border="0" cellPadding="0" cellSpacing="0" class="button-css__deep-table___2OZyb wrapper-mobile" style="text-align:center">
<tbody> <tbody>
<tr> <tr>
<td align="center" bgcolor="#0d78f2" class="inner-td" style="border-radius:6px;font-size:16px;text-align:center;background-color:inherit"> <td align="center" bgcolor="#63a945" class="inner-td" style="border-radius:6px;font-size:16px;text-align:center;background-color:inherit">
<a href="{{ ctaLink }}" style="background-color:#0d78f2;border:1px solid #333333;border-color:#0d78f2;border-radius:0px;border-width:1px;color:#ffffff;display:inline-block;font-family:arial,helvetica,sans-serif;font-size:16px;font-weight:normal;letter-spacing:0px;line-height:16px;padding:12px 18px 12px 18px;text-align:center;text-decoration:none" <a href="{{ ctaLink }}" style="background-color:#63a945;border:1px solid #333333;border-color:#63a945;border-radius:0px;border-width:1px;color:#ffffff;display:inline-block;font-family:arial,helvetica,sans-serif;font-size:16px;font-weight:normal;letter-spacing:0px;line-height:16px;padding:12px 18px 12px 18px;text-align:center;text-decoration:none"
target="_blank">{{ ctaText }}</a> target="_blank">{{ ctaText }}</a>
</td> </td>
</tr> </tr>
......
const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => { const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => {
let paragraph let paragraph
const hasLink = true
switch (emailType) { switch (emailType) {
case 'he-new-version-submitted': case 'he-new-version-submitted':
paragraph = `A new version of ${titleText} has been submitted. paragraph = `A new version of ${titleText} has been submitted.
...@@ -14,11 +15,25 @@ const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => { ...@@ -14,11 +15,25 @@ const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => {
case 'eqs-manuscript-submitted': case 'eqs-manuscript-submitted':
paragraph = `Manuscript ID ${customId} has been submitted and a package has been sent. Please click on the link below to either approve or reject the manuscript:` paragraph = `Manuscript ID ${customId} has been submitted and a package has been sent. Please click on the link below to either approve or reject the manuscript:`
break break
case 'coauthors-manuscript-submitted':
paragraph = `${titleText} has been received.<br/>
Please verify your details by clicking the link below.<br/>
Once confirmed, you will also be able to view the status and progress of the manuscript.<br/>
Thank you for submitting your work to Hindawi. <br/>
`
break
case 'submitting-author-manuscript-submitted':
paragraph = `Congratulations, ${titleText} has been successfully submitted.<br/>
All authors will receive correspondence regarding this manuscript, though only you will be able to make updates.<br/>
In order to view the status of the manuscript, please click the link below.<br/>
Thank you for submitting your work to Hindawi. <br/>
`
break
default: default:
throw new Error(`The ${emailType} email type is not defined.`) throw new Error(`The ${emailType} email type is not defined.`)
} }
return { paragraph, hasLink: true } return { paragraph, hasLink }
} }
module.exports = { module.exports = {
......
...@@ -8,6 +8,7 @@ const { ...@@ -8,6 +8,7 @@ const {
Fragment, Fragment,
} = require('pubsweet-component-helper-service') } = require('pubsweet-component-helper-service')
const resetPath = config.get('invite-reset-password.url')
const { getEmailCopy } = require('./emailCopy') const { getEmailCopy } = require('./emailCopy')
const unsubscribeSlug = config.get('unsubscribe.url') const unsubscribeSlug = config.get('unsubscribe.url')
...@@ -27,7 +28,10 @@ module.exports = { ...@@ -27,7 +28,10 @@ module.exports = {
const parsedFragment = await fragmentHelper.getFragmentData({ const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor: collection.handlingEditor, handlingEditor: collection.handlingEditor,
}) })
const { submittingAuthor } = await fragmentHelper.getAuthorData({ const {
submittingAuthor,
activeAuthors: authors,
} = await fragmentHelper.getAuthorData({
UserModel, UserModel,
}) })
...@@ -80,6 +84,16 @@ module.exports = { ...@@ -80,6 +84,16 @@ module.exports = {
collection, collection,
subjectBaseText, subjectBaseText,
}) })
sendAuthorsEmail({
email,
baseUrl,
titleText,
UserModel,
subjectBaseText,
fragmentId: fragment.id,
fragmentAuthors: authors,
collectionId: collection.id,
})
} }
}, },
} }
...@@ -191,3 +205,78 @@ const sendEQSEmail = ({ ...@@ -191,3 +205,78 @@ const sendEQSEmail = ({
}) })
email.sendEmail({ html, text }) email.sendEmail({ html, text })
} }
const sendAuthorsEmail = async ({
email,
baseUrl,
customId,
UserModel,
titleText,
fragmentId,
collectionId,
fragmentAuthors,
}) => {
email.content.subject = 'Manuscript Sumbmitted'
const userEmailData = await Promise.all(
fragmentAuthors.map(async author => {
const user = await UserModel.find(author.id)
return {
...author,
isConfirmed: user.isConfirmed,
...getEmailCopy({
customId,
emailType: author.isSubmitting
? 'submitting-author-manuscript-submitted'
: 'coauthors-manuscript-submitted',
titleText: author.isSubmitting
? titleText
: titleText.replace(/^\w/, firstChar => firstChar.toUpperCase()),
}),
}
}),
)
userEmailData.forEach(author => {
email.toUser = {
email: author.email,
name: `${author.firstName} ${author.lastName}`,
}
email.content.unsubscribeLink = services.createUrl(
baseUrl,
unsubscribeSlug,
{
id: author.id,
},
)
if (author.isSubmitting) {
email.content.ctaLink = services.createUrl(
baseUrl,
`/projects/${collectionId}/versions/${fragmentId}/details`,
)
email.content.ctaText = 'MANUSCRIPT DETAILS'
} else if (author.isConfirmed) {
email.content.ctaLink = services.createUrl(baseUrl, '')
email.content.ctaText = 'LOGIN'
} else {
email.content.ctaLink = services.createUrl(baseUrl, resetPath, {
email: author.email,
token: author.passwordResetToken,
firstName: author.firstName,
lastName: author.lastName,
affiliation: author.affiliation,
title: author.title,
})
email.content.ctaText = 'CONFIRM ACCOUNT'
}
const { html, text } = email.getBody({
body: {
paragraph: author.paragraph,
hasLink: author.hasLink,
},
})
email.sendEmail({ html, text })
})
}
...@@ -58,17 +58,9 @@ module.exports = { ...@@ -58,17 +58,9 @@ module.exports = {
}, },
}) })
if (isEQA && agree) { if (agree && isEQA) {
const eicName = await userHelper.getEiCName() email.content.signatureName = await userHelper.getEiCName()
email.content.signatureName = eicName
sendAuthorsEmail({
email,
baseUrl,
titleText,
subjectBaseText,
fragmentAuthors: authors,
})
sendHandlingEditorEmail({ sendHandlingEditorEmail({
email, email,
baseUrl, baseUrl,
...@@ -84,6 +76,14 @@ module.exports = { ...@@ -84,6 +76,14 @@ module.exports = {
fragmentHelper, fragmentHelper,
subjectBaseText, subjectBaseText,
}) })
sendAuthorsEmail({
email,
baseUrl,
titleText,
subjectBaseText,
fragmentAuthors: authors,
})
} else { } else {
sendEditorsEmail({ email, agree, comments, userHelper, titleText }) sendEditorsEmail({ email, agree, comments, userHelper, titleText })
} }
......
const { pick } = require('lodash') const { pick } = require('lodash')
const notifications = require('./emails/notifications')
const { const {
User, User,
...@@ -47,7 +46,7 @@ module.exports = models => async (req, res) => { ...@@ -47,7 +46,7 @@ module.exports = models => async (req, res) => {
error: notFoundError.message, error: notFoundError.message,
}) })
} }
const baseUrl = services.getBaseUrl(req)
const UserModel = models.User const UserModel = models.User
const teamHelper = new Team({ TeamModel: models.Team, fragmentId }) const teamHelper = new Team({ TeamModel: models.Team, fragmentId })
const fragmentHelper = new Fragment({ fragment }) const fragmentHelper = new Fragment({ fragment })
...@@ -92,14 +91,9 @@ module.exports = models => async (req, res) => { ...@@ -92,14 +91,9 @@ module.exports = models => async (req, res) => {
collection.save() collection.save()
} }
notifications.sendNotifications({ /*
user, TO DO: send email to SA when an Admin submits a manuscript on his behalf
baseUrl, */
fragment,
collection,
reqUserId: req.user,
UserModel: models.User,
})
return res.status(200).json({ return res.status(200).json({
...pick(user, authorKeys), ...pick(user, authorKeys),
...@@ -131,14 +125,9 @@ module.exports = models => async (req, res) => { ...@@ -131,14 +125,9 @@ module.exports = models => async (req, res) => {
isCorresponding, isCorresponding,
}) })
notifications.sendNotifications({ /*
baseUrl, TO DO: send email to SA when an Admin submits a manuscript on his behalf
fragment, */
collection,
user: newUser,
reqUserId: req.user,
UserModel: models.User,
})
if (!collection.owners.includes(newUser.id)) { if (!collection.owners.includes(newUser.id)) {
collection.owners.push(newUser.id) collection.owners.push(newUser.id)
......
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