Skip to content
Snippets Groups Projects
Commit edd45dce authored by Andrei Cioromila's avatar Andrei Cioromila
Browse files

refactor(notifications): extract author notification when eic makes a decision

parent 99a49623
No related branches found
No related tags found
1 merge request!115Hin 1038
...@@ -107,14 +107,14 @@ module.exports = { ...@@ -107,14 +107,14 @@ module.exports = {
comments, comments,
emailType, emailType,
titleText, titleText,
reviewerLastName, targetUserName,
}) => { }) => {
const { html, text } = email.getNotificationBody({ const { html, text } = email.getNotificationBody({
emailBodyProps: getEmailCopy({ emailBodyProps: getEmailCopy({
emailType, emailType,
titleText, titleText,
comments, comments,
targetUserName: reviewerLastName, targetUserName,
}), }),
}) })
email.sendEmail({ html, text }) email.sendEmail({ html, text })
......
const config = require('config') const config = require('config')
const { get } = require('lodash') const { get, isEmpty } = require('lodash')
const Email = require('@pubsweet/component-email-templating') const Email = require('@pubsweet/component-email-templating')
const unsubscribeSlug = config.get('unsubscribe.url') const unsubscribeSlug = config.get('unsubscribe.url')
...@@ -66,7 +66,7 @@ class Notification { ...@@ -66,7 +66,7 @@ class Notification {
helpers.sendHandlingEditorEmail({ helpers.sendHandlingEditorEmail({
email, email,
titleText, titleText,
reviewerLastName, targetUserName: reviewerLastName,
emailType: 'he-review-submitted', emailType: 'he-review-submitted',
}) })
} }
...@@ -104,13 +104,13 @@ class Notification { ...@@ -104,13 +104,13 @@ class Notification {
helpers.sendHandlingEditorEmail({ helpers.sendHandlingEditorEmail({
email, email,
titleText, titleText,
reviewerLastName, targetUserName: eicName,
emailType: 'he-review-submitted', emailType: 'he-review-submitted',
}) })
} }
notifyEAWhenEiCMakesFinalDecision() { async notifyEAWhenEiCMakesFinalDecision() {
const { eicName, titleText } = this.props const { eicName, titleText } = await this.getNotificationProperties()
const subjectBaseText = `${this.collection.customId}: Manuscript` const subjectBaseText = `${this.collection.customId}: Manuscript`
const email = new Email({ const email = new Email({
...@@ -135,8 +135,8 @@ class Notification { ...@@ -135,8 +135,8 @@ class Notification {
email.sendEmail({ html, text }) email.sendEmail({ html, text })
} }
notifyEAWhenEiCRequestsEQAApproval() { async notifyEAWhenEiCRequestsEQAApproval() {
const { eicName } = this.props const { eicName } = await this.getNotificationProperties()
const subjectBaseText = `${this.collection.customId}: Manuscript` const subjectBaseText = `${this.collection.customId}: Manuscript`
const email = new Email({ const email = new Email({
...@@ -171,7 +171,75 @@ class Notification { ...@@ -171,7 +171,75 @@ class Notification {
email.sendEmail({ html, text }) email.sendEmail({ html, text })
} }
notifyAuthorsWhenEiCMakesDecision() {} async notifyAuthorsWhenEiCMakesDecision() {
const {
eicName,
titleText,
activeAuthors,
recommendation,
parsedFragment,
} = await this.getNotificationProperties()
activeAuthors.forEach(async author => {
const subjectOpts = {
publish: `${this.collection.customId}: Manuscript accepted`,
reject: `${this.collection.customId}: Manuscript rejected`,
}
const subject = subjectOpts[recommendation]
if (isEmpty(subject)) {
throw new Error(`Undefined recommendation: ${recommendation}`)
}
const email = new Email({
type: 'user',
toUser: {
email: author.email,
name: author.lastName,
},
fromEmail: `${eicName} <${staffEmail}>`,
content: {
signatureName: eicName,
ctaText: 'MANUSCRIPT DETAILS',
subject,
unsubscribeLink: services.createUrl(this.baseUrl, unsubscribeSlug, {
id: author.id,
token: author.accessTokens.unsubscribe,
}),
ctaLink: services.createUrl(
this.baseUrl,
`/projects/${this.collection.id}/versions/${
this.fragment.id
}/details`,
),
signatureJournal: journalName,
},
})
const hasPeerReview = !isEmpty(this.collection.handlingEditor)
const emailType = helpers.getEmailTypeByRecommendationForAuthors({
recommendation,
hasPeerReview,
})
let comments
if (hasPeerReview) {
comments = helpers.getHEComments({
heRecommendation: parsedFragment.heRecommendation,
})
} else {
comments = this.newRecommendation.comments[0].content
}
const { html, text } = email.getNotificationBody({
emailBodyProps: getEmailCopy({
titleText,
emailType,
comments,
}),
})
email.sendEmail({ html, text })
})
}
notifyReviewersWhenEiCMakesDecision() {} notifyReviewersWhenEiCMakesDecision() {}
...@@ -186,7 +254,10 @@ class Notification { ...@@ -186,7 +254,10 @@ class Notification {
const parsedFragment = await fragmentHelper.getFragmentData({ const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor: this.collection.handlingEditor, handlingEditor: this.collection.handlingEditor,
}) })
const { submittingAuthor } = await fragmentHelper.getAuthorData({ const {
submittingAuthor,
activeAuthors,
} = await fragmentHelper.getAuthorData({
UserModel: this.UserModel, UserModel: this.UserModel,
}) })
...@@ -199,7 +270,15 @@ class Notification { ...@@ -199,7 +270,15 @@ class Notification {
const { recommendation, recommendationType } = this.newRecommendation const { recommendation, recommendationType } = this.newRecommendation
return { recommendation, recommendationType, eicName, titleText } return {
recommendation,
recommendationType,
eicName,
titleText,
submittingAuthor,
activeAuthors,
parsedFragment,
}
} }
} }
......
...@@ -156,13 +156,15 @@ module.exports = models => async (req, res) => { ...@@ -156,13 +156,15 @@ module.exports = models => async (req, res) => {
if ( if (
recommendation === 'publish' && recommendation === 'publish' &&
collection.technicalChecks.token && collection.technicalChecks.token &&
['accepted', 'inQA'].includes(this.collection.status) ['accepted', 'inQA'].includes(collection.status)
) { ) {
if (this.collection.status === 'inQA') { if (collection.status === 'inQA') {
notification.notifyEAWhenEiCRequestsEQAApproval() notification.notifyEAWhenEiCRequestsEQAApproval()
} else { } else {
notification.notifyEAWhenEiCMakesFinalDecision() notification.notifyEAWhenEiCMakesFinalDecision()
} }
notification.notifyAuthorsWhenEiCMakesDecision()
} }
} else { } else {
// notifications.sendNotificationsWhenHEMakesRecommendation({ // notifications.sendNotificationsWhenHEMakesRecommendation({
......
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