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

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

parents dd2c0097 d4dd91c6
No related branches found
No related tags found
1 merge request!58Sprint #20 - Goal - Reviewers submit report
......@@ -76,7 +76,9 @@ class Fragment {
)
const userHelper = new User({ UserModel })
const activeAuthors = await userHelper.getActiveAuthors(authors)
const activeAuthors = await userHelper.getActiveAuthors({
fragmentAuthors: authors,
})
return {
activeAuthors,
......
......@@ -62,15 +62,25 @@ class User {
user.save()
}
async getActiveAuthors(authors) {
const activeUsers = (await Promise.all(
authors.map(author => this.UserModel.find(author.id)),
async getActiveAuthors({ fragmentAuthors }) {
const userData = (await Promise.all(
fragmentAuthors.map(author => this.UserModel.find(author.id)),
))
.filter(user => user.isActive)
.filter(user => get(user, 'notifications.email.user'))
.map(user => user.id)
.filter(user => user.isActive && get(user, 'notifications.email.user'))
.map(user => ({ id: user.id, accessTokens: user.accessTokens }))
return authors.filter(author => activeUsers.includes(author.id))
return fragmentAuthors
.map(fAuthor => {
const matchingAuthor = userData.find(user => user.id === fAuthor.id)
if (matchingAuthor) {
return {
...fAuthor,
accessTokens: matchingAuthor.accessTokens,
}
}
return false
})
.filter(Boolean)
}
async getEiCName() {
......
......@@ -85,9 +85,7 @@ class Email {
logger.info(
`EMAIL: Sent email from ${from} to ${to} with subject '${subject}'`,
)
logger.debug(
`EMAIL: Sent email from ${from} to ${to} with subject '${subject}'`,
)
SendEmail.send(mailData)
}
}
......
......@@ -109,6 +109,12 @@ const getEmailCopy = ({
paragraph = `${titleText} has been accepted for publication by ${eicName}. <br/><br/>
Please complete QA screening so that manuscript can be sent to production.`
break
case 'authors-manuscript-rejected-before-review':
paragraph = `I regret to inform you that your manuscript has been rejected for publication in ${journalName} for the following reason:<br/><br/>
${comments}<br/><br/>
Thank you for your submission, and please do consider submitting again in the future.`
hasLink = false
break
default:
throw new Error(`The ${emailType} email type is not defined.`)
}
......
......@@ -378,14 +378,19 @@ module.exports = {
return email
},
getEmailTypeByRecommendationForAuthors: ({ recommendation }) => {
getEmailTypeByRecommendationForAuthors: ({
recommendation,
hasPeerReview,
}) => {
let emailType
switch (recommendation) {
case 'publish':
emailType = 'author-manuscript-published'
break
case 'reject':
emailType = 'author-manuscript-rejected'
emailType = hasPeerReview
? 'author-manuscript-rejected'
: 'authors-manuscript-rejected-before-review'
break
default:
throw new Error(`Undefined recommendation: ${recommendation}`)
......
......@@ -68,8 +68,7 @@ module.exports = {
})
}
const hasPeerReview = (collection = {}) =>
!isEmpty(collection.handlingEditor)
const hasPeerReview = !isEmpty(collection.handlingEditor)
const { customId } = collection
const collHelper = new Collection({ collection })
......@@ -77,7 +76,7 @@ module.exports = {
// or when the EiC makes a recommendation after peer review
if (
(isEditorInChief || recommendationType === 'review') &&
hasPeerReview(collection) &&
hasPeerReview &&
(recommendation !== 'publish' || hasEQA)
) {
const handlingEditor = get(collection, 'handlingEditor', {})
......@@ -118,10 +117,18 @@ module.exports = {
// send all authors email
const emailType = helpers.getEmailTypeByRecommendationForAuthors({
recommendation,
hasPeerReview,
})
const comments = helpers.getHEComments({
heRecommendation: parsedFragment.heRecommendation,
})
let comments
if (hasPeerReview) {
comments = helpers.getHEComments({
heRecommendation: parsedFragment.heRecommendation,
})
} else {
comments = newRecommendation.comments[0].content
}
const authors = helpers.getAllAuthors({
comments,
emailType,
......@@ -156,7 +163,7 @@ module.exports = {
helpers.sendSubmittingAuthorEmail({ email, author, baseUrl })
}
if (!hasPeerReview(collection)) {
if (!hasPeerReview) {
return
}
......
......@@ -13,7 +13,9 @@ module.exports = models => async (req, res) => {
const { authors = [] } = await models.Fragment.find(fragmentId)
const userHelper = new User({ UserModel: models.User })
const activeAuthors = await userHelper.getActiveAuthors(authors)
const activeAuthors = await userHelper.getActiveAuthors({
fragmentAuthors: authors,
})
return res.status(200).json(activeAuthors)
} catch (e) {
......
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