Skip to content
Snippets Groups Projects
Commit d9e575ad authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

Merge branch 'develop' of https://gitlab.coko.foundation/xpub/xpub-faraday into develop

parents ae76beb7 bb2534ce
No related branches found
No related tags found
1 merge request!10Sprint #12
......@@ -249,8 +249,17 @@ module.exports = {
}
return Email.send(mailData)
},
sendNotificationEmail: async ({ toEmail, user, emailType, meta = {} }) => {
sendNotificationEmail: async ({
toEmail,
user,
emailType,
meta = { privateNote: '' },
}) => {
let subject, textBody
const privateNoteText =
meta.privateNote !== undefined
? `Private note: "${meta.privateNote}"`
: ''
const emailTemplate = 'notification'
const replacements = {
detailsUrl: helpers.createUrl(
......@@ -259,6 +268,7 @@ module.exports = {
),
beforeAnchor: '',
afterAnchor: '',
hasLink: true,
}
switch (emailType) {
case 'unassign-reviewer':
......@@ -369,6 +379,7 @@ module.exports = {
subject = `${
meta.collection.customId
}: Manuscript Recommendation Submitted`
replacements.hasLink = false
replacements.previewText =
'a manuscript has received a recommendation based on reviews'
replacements.intro = `Dear Dr. ${user.firstName} ${user.lastName}`
......@@ -386,6 +397,27 @@ module.exports = {
replacements.signatureName
}`
break
case 'eic-recommendation':
subject = `${meta.collection.customId}: Manuscript Recommendation`
replacements.previewText =
'a handling editor has submitted a recommendation'
replacements.intro = `Dear Dr. ${meta.eicName}`
replacements.paragraph = `It is my recommendation, based on the reviews I have received for the manuscript titled "${
meta.fragment.title
}" by ${meta.fragment.authorName}, that ${
meta.heRecommendation
}. <br/><br/>
${privateNoteText}<br/><br/>`
replacements.beforeAnchor =
'For more information, and to see the full review, please visit the '
replacements.signatureName = meta.handlingEditorName
textBody = `${replacements.intro} ${replacements.paragraph} ${
replacements.beforeAnchor
} ${replacements.detailsUrl} ${replacements.afterAnchor} ${
replacements.signatureName
}`
break
default:
subject = 'Hindawi Notification!'
break
......
......@@ -43,6 +43,7 @@ const getNotificationBody = (emailType, replacements) => {
handlePartial('notificationBody', {
intro: replacements.intro,
paragraph: replacements.paragraph,
hasLink: replacements.hasLink,
})
return getMainTemplate(emailType, replacements)
......
......@@ -6,7 +6,7 @@
<p>&nbsp;</p>
<p>
{{{paragraph}}}
{{#if detailsUrl }}
{{#if hasLink }}
{{> manuscriptDetailsLink}}
{{/if}}
</p>
......
const collectionHelper = require('./Collection')
const get = require('lodash/get')
const last = require('lodash/last')
const getEditorInChief = async UserModel => {
const users = await UserModel.all()
......@@ -41,28 +43,30 @@ const setupReviewSubmittedEmailData = async ({
const setupAfterRecommendationEmailData = async ({
baseUrl,
UserModel,
FragmentModel,
fragment: { title, authorName },
collection,
mailService,
UserModel,
FragmentModel,
}) => {
const { title, authorName } = await collectionHelper.getFragmentAndAuthorData(
{
UserModel,
FragmentModel,
collection,
},
)
const toEmail = collection.handlingEditor.email
const agreedReviewerInvitations = collectionHelper.getAgreedReviewerInvitation(
collection.invitations,
)
const users = await Promise.all(
agreedReviewerInvitations.map(async inv => UserModel.find(inv.userId)),
)
const hasReview = invUserId => rec =>
rec.recommendationType === 'review' &&
rec.submittedOn &&
invUserId === rec.userId
const userPromises = await agreedReviewerInvitations.map(async inv => {
const fragmentId = last(collection.fragments)
const fragment = await FragmentModel.find(fragmentId)
const submittedReview = fragment.recommendations.find(hasReview(inv.userId))
if (submittedReview === undefined) return UserModel.find(inv.userId)
})
let users = await Promise.all(userPromises)
users = users.filter(Boolean)
users.forEach(user =>
mailService.sendNotificationEmail({
toEmail,
toEmail: user.email,
user,
emailType: 'after-he-recommendation',
meta: {
......@@ -75,8 +79,41 @@ const setupAfterRecommendationEmailData = async ({
)
}
const setupEiCRecommendationEmailData = async ({
baseUrl,
UserModel,
fragment: { id, title, authorName },
collection,
mailService,
publish,
comments,
}) => {
// to do: get private note from recommendation
const privateNote = comments.find(comm => comm.public === false)
const content = get(privateNote, 'content')
const heRecommendation = publish
? 'we should proceed to publication'
: 'we should reject it for publication'
const eic = await getEditorInChief(UserModel)
const toEmail = eic.email
await mailService.sendNotificationEmail({
toEmail,
emailType: 'eic-recommendation',
meta: {
collection: { customId: collection.customId, id: collection.id },
fragment: { id, title, authorName },
handlingEditorName: collection.handlingEditor.name,
baseUrl,
eicName: `${eic.firstName} ${eic.lastName}`,
heRecommendation,
privateNote: content,
},
})
}
module.exports = {
getEditorInChief,
setupReviewSubmittedEmailData,
setupAfterRecommendationEmailData,
setupEiCRecommendationEmailData,
}
......@@ -57,14 +57,34 @@ module.exports = models => async (req, res) => {
['reject', 'publish'].includes(recommendation) &&
recommendationType === 'editorRecommendation'
) {
const {
title,
authorName,
id,
} = await collectionHelper.getFragmentAndAuthorData({
UserModel: models.User,
FragmentModel: models.Fragment,
collection,
})
const baseUrl = helpers.getBaseUrl(req)
await userHelper.setupAfterRecommendationEmailData({
baseUrl: helpers.getBaseUrl(req),
baseUrl,
UserModel: models.User,
FragmentModel: models.Fragment,
collection,
mailService,
fragment: { title, authorName },
})
await collectionHelper.updateStatus(collection, 'pendingApproval')
await userHelper.setupEiCRecommendationEmailData({
baseUrl,
UserModel: models.User,
collection,
mailService,
publish: recommendation === 'publish',
fragment: { title, id, authorName },
comments: newRecommendation.comments,
})
}
if (
['minor', 'major'].includes(recommendation) &&
......
......@@ -64,6 +64,21 @@ const users = {
handlingEditor: true,
title: 'Mr',
},
editorInChief: {
type: 'user',
username: chance.word(),
email: chance.email(),
password: 'password',
admin: false,
id: chance.guid(),
firstName: chance.first(),
lastName: chance.last(),
affiliation: chance.company(),
title: 'Mr',
save: jest.fn(() => users.editorInChief),
isConfirmed: false,
editorInChief: true,
},
}
module.exports = users
......@@ -20,6 +20,7 @@ const build = fixtures => {
},
}
UserMock.find = jest.fn(id => findMock(id, 'users', fixtures))
UserMock.all = jest.fn(() => Object.values(fixtures.users))
models.User = UserMock
return models
}
......
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