Skip to content
Snippets Groups Projects
Commit bd011508 authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into hin-736-update-email-copy

parents 24d4ce60 c0acc7a8
No related branches found
No related tags found
2 merge requests!43Sprint #19,!39update emails content and format
const getEmailCopy = ({ emailType, titleText }) => { const getEmailCopy = ({ emailType, titleText }) => {
let paragraph let paragraph
switch (emailType) { switch (emailType) {
case 'author-added-to-manuscript': case 'submitting-author-added-by-admin':
paragraph = `You have been added as an author to ${titleText}. The manuscript will become visible on your dashboard once it's submitted. Please click on the link below to access your dashboard.` paragraph = `${titleText}<br/>
break Please verify your details by clicking the link below.<br/>
case 'new-author-added-to-manuscript': To confirm the submission and view the status of the manuscript, please verify your details by clicking the link below. <br/>`
paragraph = `You have been added as an author to ${titleText}. In order to gain access to the manuscript, please confirm your account and set your account details by clicking on the link below.`
break break
default: default:
throw new Error(`The ${emailType} email type is not defined.`) throw new Error(`The ${emailType} email type is not defined.`)
......
...@@ -14,113 +14,58 @@ const { getEmailCopy } = require('./emailCopy') ...@@ -14,113 +14,58 @@ const { getEmailCopy } = require('./emailCopy')
module.exports = { module.exports = {
async sendNotifications({ async sendNotifications({
user,
baseUrl, baseUrl,
fragment, fragment,
reqUserId,
UserModel, UserModel,
collection, collection,
submittingAuthor,
}) { }) {
const fragmentHelper = new Fragment({ fragment }) const fragmentHelper = new Fragment({ fragment })
const { title } = await fragmentHelper.getFragmentData({ const { title } = await fragmentHelper.getFragmentData({
handlingEditor: collection.handlingEditor, handlingEditor: collection.handlingEditor,
}) })
const { submittingAuthor } = await fragmentHelper.getAuthorData({
UserModel,
})
const titleText = `the manuscript titled "${title}" by ${
submittingAuthor.firstName
} ${submittingAuthor.lastName}`
const userHelper = new User({ UserModel }) const userHelper = new User({ UserModel })
const subjectBaseText = `${collection.customId}: Manuscript` const eicName = await userHelper.getEiCName()
const titleText = `The manuscript titled "${title}" has been submitted to Hindawi by ${eicName}.`
const email = new Email({ const email = new Email({
type: 'user', type: 'user',
toUser: {
email: submittingAuthor.email,
name: `${submittingAuthor.firstName} ${submittingAuthor.lastName}`,
},
content: { content: {
ctaLink: baseUrl, ctaText: 'LOGIN',
ctaText: 'VIEW DASHBOARD', signatureName: eicName,
signatureName: await userHelper.getEiCName(), subject: `Manuscript Submitted`,
ctaLink: services.createUrl(baseUrl, ''),
unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, {
id: submittingAuthor.id,
}),
}, },
}) })
if (!user.isConfirmed) { if (!submittingAuthor.isConfirmed) {
sendNewAuthorEmail({ email.content.ctaLink = services.createUrl(baseUrl, resetPath, {
email, email: submittingAuthor.email,
user, token: submittingAuthor.passwordResetToken,
baseUrl, firstName: submittingAuthor.firstName,
titleText, lastName: submittingAuthor.lastName,
subjectBaseText, affiliation: submittingAuthor.affiliation,
title: submittingAuthor.title,
}) })
email.content.ctaText = 'CONFIRM ACCOUNT'
} }
const requestUser = await UserModel.find(reqUserId) const { html, text } = email.getBody({
if (requestUser.id !== user.id) { body: getEmailCopy({
sendAddedToManuscriptEmail({ emailType: 'submitting-author-added-by-admin',
email,
baseUrl,
user,
titleText, titleText,
subjectBaseText, }),
}) })
}
},
}
const sendAddedToManuscriptEmail = ({
email,
baseUrl,
user,
titleText,
subjectBaseText,
}) => {
email.toUser = {
email: user.email,
name: `${user.firstName} ${user.lastName}`,
}
email.content.subject = `${subjectBaseText} Created`
email.content.unsubscribeLink = services.createUrl(baseUrl, unsubscribeSlug, {
id: user.id,
})
const { html, text } = email.getBody({
body: getEmailCopy({
emailType: 'author-added-to-manuscript',
titleText,
}),
})
email.sendEmail({ html, text })
}
const sendNewAuthorEmail = ({ email, baseUrl, user, titleText }) => {
email.toUser = {
email: user.email,
name: `${user.firstName} ${user.lastName}`,
}
email.content.subject = `Confirm Your Account`
email.content.unsubscribeLink = services.createUrl(baseUrl, unsubscribeSlug, {
id: user.id,
})
email.content.ctaLink = services.createUrl(baseUrl, resetPath, {
email: user.email,
token: user.passwordResetToken,
firstName: user.firstName,
lastName: user.lastName,
affiliation: user.affiliation,
title: user.title,
})
email.content.ctaText = 'CONFIRM ACCOUNT'
const { html, text } = email.getBody({
body: getEmailCopy({
emailType: 'new-author-added-to-manuscript',
titleText,
}),
})
email.sendEmail({ html, text }) email.sendEmail({ html, text })
},
} }
...@@ -8,6 +8,8 @@ const { ...@@ -8,6 +8,8 @@ const {
authsome: authsomeHelper, authsome: authsomeHelper,
} = require('pubsweet-component-helper-service') } = require('pubsweet-component-helper-service')
const notifications = require('./emails/notifications')
const authorKeys = [ const authorKeys = [
'id', 'id',
'email', 'email',
...@@ -17,7 +19,6 @@ const authorKeys = [ ...@@ -17,7 +19,6 @@ const authorKeys = [
'affiliation', 'affiliation',
] ]
// TODO: add authsome
module.exports = models => async (req, res) => { module.exports = models => async (req, res) => {
const { email, role, isSubmitting, isCorresponding } = req.body const { email, role, isSubmitting, isCorresponding } = req.body
...@@ -50,6 +51,7 @@ module.exports = models => async (req, res) => { ...@@ -50,6 +51,7 @@ module.exports = models => async (req, res) => {
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 })
const reqUser = await UserModel.find(req.user)
try { try {
let user = await UserModel.findByEmail(email) let user = await UserModel.findByEmail(email)
...@@ -91,9 +93,16 @@ module.exports = models => async (req, res) => { ...@@ -91,9 +93,16 @@ module.exports = models => async (req, res) => {
collection.save() collection.save()
} }
/* // send email to SA when an Admin submits a manuscript on his behalf
TO DO: send email to SA when an Admin submits a manuscript on his behalf if ((reqUser.admin || reqUser.editorInChief) && isSubmitting) {
*/ notifications.sendNotifications({
fragment,
UserModel,
collection,
submittingAuthor: user,
baseUrl: services.getBaseUrl(req),
})
}
return res.status(200).json({ return res.status(200).json({
...pick(user, authorKeys), ...pick(user, authorKeys),
...@@ -125,9 +134,16 @@ module.exports = models => async (req, res) => { ...@@ -125,9 +134,16 @@ module.exports = models => async (req, res) => {
isCorresponding, isCorresponding,
}) })
/* // send email to SA when an Admin submits a manuscript on his behalf
TO DO: send email to SA when an Admin submits a manuscript on his behalf if ((reqUser.admin || reqUser.editorInChief) && isSubmitting) {
*/ notifications.sendNotifications({
fragment,
UserModel,
collection,
submittingAuthor: newUser,
baseUrl: services.getBaseUrl(req),
})
}
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