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

Merge branch 'develop' into hindawi-theme

parents 919cad77 6a1f488d
No related branches found
No related tags found
1 merge request!43Sprint #19
......@@ -11,8 +11,7 @@ const { getEmailCopy } = require('./emailCopy')
module.exports = {
async sendNotifications({ user, baseUrl, role, UserModel }) {
const userHelper = new User({ UserModel })
const { firstName, lastName } = await userHelper.getEditorsInChief()
const eicName = `${firstName} ${lastName}`
const eicName = await userHelper.getEiCName()
const email = new Email({
type: 'user',
......
......@@ -6,8 +6,8 @@
<table border="0" cellPadding="0" cellSpacing="0" class="button-css__deep-table___2OZyb wrapper-mobile" style="text-align:center">
<tbody>
<tr>
<td align="center" bgcolor="#0d78f2" 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"
<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:#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>
</td>
</tr>
......
const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => {
let paragraph
const hasLink = true
switch (emailType) {
case 'he-new-version-submitted':
paragraph = `A new version of ${titleText} has been submitted.
......@@ -14,11 +15,25 @@ const getEmailCopy = ({ emailType, titleText, expectedDate, customId }) => {
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:`
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:
throw new Error(`The ${emailType} email type is not defined.`)
}
return { paragraph, hasLink: true }
return { paragraph, hasLink }
}
module.exports = {
......
......@@ -8,6 +8,7 @@ const {
Fragment,
} = require('pubsweet-component-helper-service')
const resetPath = config.get('invite-reset-password.url')
const { getEmailCopy } = require('./emailCopy')
const unsubscribeSlug = config.get('unsubscribe.url')
......@@ -27,7 +28,10 @@ module.exports = {
const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor: collection.handlingEditor,
})
const { submittingAuthor } = await fragmentHelper.getAuthorData({
const {
submittingAuthor,
activeAuthors: authors,
} = await fragmentHelper.getAuthorData({
UserModel,
})
......@@ -80,6 +84,16 @@ module.exports = {
collection,
subjectBaseText,
})
sendAuthorsEmail({
email,
baseUrl,
titleText,
UserModel,
subjectBaseText,
fragmentId: fragment.id,
fragmentAuthors: authors,
collectionId: collection.id,
})
}
},
}
......@@ -191,3 +205,78 @@ const sendEQSEmail = ({
})
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 = {
},
})
if (isEQA && agree) {
const eicName = await userHelper.getEiCName()
email.content.signatureName = eicName
if (agree && isEQA) {
email.content.signatureName = await userHelper.getEiCName()
sendAuthorsEmail({
email,
baseUrl,
titleText,
subjectBaseText,
fragmentAuthors: authors,
})
sendHandlingEditorEmail({
email,
baseUrl,
......@@ -84,6 +76,14 @@ module.exports = {
fragmentHelper,
subjectBaseText,
})
sendAuthorsEmail({
email,
baseUrl,
titleText,
subjectBaseText,
fragmentAuthors: authors,
})
} else {
sendEditorsEmail({ email, agree, comments, userHelper, titleText })
}
......
const { pick } = require('lodash')
const notifications = require('./emails/notifications')
const {
User,
......@@ -47,7 +46,7 @@ module.exports = models => async (req, res) => {
error: notFoundError.message,
})
}
const baseUrl = services.getBaseUrl(req)
const UserModel = models.User
const teamHelper = new Team({ TeamModel: models.Team, fragmentId })
const fragmentHelper = new Fragment({ fragment })
......@@ -92,14 +91,9 @@ module.exports = models => async (req, res) => {
collection.save()
}
notifications.sendNotifications({
user,
baseUrl,
fragment,
collection,
reqUserId: req.user,
UserModel: models.User,
})
/*
TO DO: send email to SA when an Admin submits a manuscript on his behalf
*/
return res.status(200).json({
...pick(user, authorKeys),
......@@ -131,14 +125,9 @@ module.exports = models => async (req, res) => {
isCorresponding,
})
notifications.sendNotifications({
baseUrl,
fragment,
collection,
user: newUser,
reqUserId: req.user,
UserModel: models.User,
})
/*
TO DO: send email to SA when an Admin submits a manuscript on his behalf
*/
if (!collection.owners.includes(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