diff --git a/packages/component-invite/src/helpers/Invitation.js b/packages/component-invite/src/helpers/Invitation.js index 5d6897ebf372f6ce8fa44cc97508b5bed3d4327d..d073162a17d19eab5ae88f1d47f39185f781bb55 100644 --- a/packages/component-invite/src/helpers/Invitation.js +++ b/packages/component-invite/src/helpers/Invitation.js @@ -1,4 +1,5 @@ const uuid = require('uuid') +const mailService = require('pubsweet-component-mail-service') const getInvitationData = (invitations, userId, role) => { const matchingInvitation = invitations.find( @@ -30,7 +31,34 @@ const setupInvitation = async (userId, role, collection) => { return invitation } +const setupReviewerInvitation = async (req, models, collection, user) => { + const baseUrl = `${req.protocol}://${req.get('host')}` + const fragment = await models.Fragment.find(collection.fragments[0]) + const submittingAuthorData = collection.authors.find( + author => author.isSubmitting === true, + ) + const submittingAuthor = await models.User.find(submittingAuthorData.userId) + const authorsPromises = collection.authors.map(async author => { + const user = await models.User.find(author.userId) + return `${user.firstName} ${user.lastName}` + }) + const authors = await Promise.all(authorsPromises) + let { abstract, title } = fragment.metadata + title = title.replace(/<(.|\n)*?>/g, '') + abstract = abstract.replace(/<(.|\n)*?>/g, '') + await mailService.setupReviewerInvitationEmail( + user, + baseUrl, + collection, + abstract, + title, + submittingAuthor, + authors, + ) +} + module.exports = { getInvitationData, setupInvitation, + setupReviewerInvitation, } diff --git a/packages/component-invite/src/helpers/User.js b/packages/component-invite/src/helpers/User.js index 6df526ef7be58681e68ca54850198b8c8b796475..5ccba0e94832c0a7820331b825c509c76e44d332 100644 --- a/packages/component-invite/src/helpers/User.js +++ b/packages/component-invite/src/helpers/User.js @@ -24,12 +24,14 @@ module.exports = { ) try { - await mailService.setupInviteEmail( - newUser.email, - invitationType, - newUser.passwordResetToken, - url, - ) + if (role !== 'reviewer') { + await mailService.setupInviteEmail( + newUser.email, + invitationType, + newUser.passwordResetToken, + url, + ) + } return newUser } catch (e) { diff --git a/packages/component-invite/src/routes/collectionsInvitations/patch.js b/packages/component-invite/src/routes/collectionsInvitations/patch.js index b2a40b34f05ec5e7538a95edb3e40e32a5c183e3..c9b0e535194f3e62a14dd32f4b09c7cad14a946e 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/patch.js +++ b/packages/component-invite/src/routes/collectionsInvitations/patch.js @@ -33,6 +33,7 @@ module.exports = models => async (req, res) => { const eic = await userHelper.getEditorInChief(models.User) if (isAccepted === true) { invitation.isAccepted = true + await collection.save() try { await mailService.setupHandlingEditorAgreedEmail( eic.email, diff --git a/packages/component-invite/src/routes/collectionsInvitations/post.js b/packages/component-invite/src/routes/collectionsInvitations/post.js index 932212103fd4a76707cf1498e0fbbb6ec4b9ed97..ac55058784569078ce3b2c20c6ccaae9f1e98e25 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/post.js +++ b/packages/component-invite/src/routes/collectionsInvitations/post.js @@ -6,6 +6,7 @@ const teamHelper = require('../../helpers/Team') const config = require('config') const mailService = require('pubsweet-component-mail-service') const userHelper = require('../../helpers/User') +const invitationHelper = require('../../helpers/Invitation') const configRoles = config.get('roles') @@ -68,30 +69,11 @@ module.exports = models => async (req, res) => { url, ) } else if (role === 'reviewer') { - const dashboardUrl = `${req.protocol}://${req.get('host')}` - const fragment = await models.Fragment.find(collection.fragments[0]) - const submittingAuthorData = collection.authors.find( - author => author.isSubmitting === true, - ) - const submittingAuthor = await models.User.find( - submittingAuthorData.userId, - ) - const authorsPromises = collection.authors.map(async author => { - const user = await models.User.find(author.userId) - return `${user.firstName} ${user.lastName}` - }) - const authors = await Promise.all(authorsPromises) - let { abstract, title } = fragment.metadata - title = title.replace(/<(.|\n)*?>/g, '') - abstract = abstract.replace(/<(.|\n)*?>/g, '') - await mailService.setupReviewerInvitationEmail( - user, - dashboardUrl, + await invitationHelper.setupReviewerInvitation( + req, + models, collection, - abstract, - title, - submittingAuthor, - authors, + user, ) } else { return res.status(500).json({ @@ -122,6 +104,12 @@ module.exports = models => async (req, res) => { } await teamHelper.setupManuscriptTeam(models, newUser, collectionId, role) await collectionHelper.addInvitation(collection, newUser.id, role) + await invitationHelper.setupReviewerInvitation( + req, + models, + collection, + newUser, + ) return res.status(200).json(newUser) } const notFoundError = await helpers.handleNotFoundError(e, 'user') diff --git a/packages/component-mail-service/src/Mail.js b/packages/component-mail-service/src/Mail.js index 8d46d198ba6b4272d7d3551e25cd5c36d6a658f2..f07fd48dfab032ea3ee314cadc139b2c606341c7 100644 --- a/packages/component-mail-service/src/Mail.js +++ b/packages/component-mail-service/src/Mail.js @@ -132,14 +132,12 @@ module.exports = { }, setupReviewerInvitationEmail: async ( invitedUser, - dashBoardUrl, + baseUrl, collection, abstract, title, submittingAuthor, authors, - token, - inviteUrl, ) => { const subject = `${collection.customId}: Review Requested` let agreeUrl @@ -147,9 +145,9 @@ module.exports = { if (invitedUser.isConfirmed) { agreeUrl = '' } else { - agreeUrl = `${inviteUrl}${resetPath}?${querystring.encode({ + agreeUrl = `${baseUrl}${resetPath}?${querystring.encode({ email: invitedUser.email, - token, + token: invitedUser.passwordResetToken, })}` } @@ -157,7 +155,7 @@ module.exports = { name: `${invitedUser.firstName} ${invitedUser.lastName}`, agreeUrl, declineUrl, - dashBoardUrl, + baseUrl, title, abstract, editorName: collection.handlingEditor.name, diff --git a/packages/component-mail-service/src/templates/invite-reviewer.html b/packages/component-mail-service/src/templates/invite-reviewer.html index 17402018dd7b3a4f7333bd9e76b43d4dfca99a2c..b038768e09b71476e020f567491700df7a1a893d 100644 --- a/packages/component-mail-service/src/templates/invite-reviewer.html +++ b/packages/component-mail-service/src/templates/invite-reviewer.html @@ -145,7 +145,7 @@ width="100%" style="display: none !important; mso-hide: all; visibility: hidden; opacity: 0; color: transparent; height: 0; width: 0;"> <tr> <td role="module-content"> - <p>manuscript review request</p> + <p>review request</p> </td> </tr> </table> @@ -164,7 +164,7 @@ <tr> <td style="padding:30px 23px 20px 23px;background-color:#ffffff;" height="100%" valign="top" bgcolor="#ffffff"> <div> - <p data-pm-slice="1 1 []">Dear Dr. {{name}},</p> + <p data-pm-slice="1 1 []">Dear {{name}},</p> <p> </p> @@ -179,7 +179,7 @@ </table> <table border="0" cellpadding="0" cellspacing="0" align="center" width="100%" role="module" data-type="columns" data-version="2" - style="background-color:#ffffff;padding:20px 0px 20px 0px;" bgcolor="#ffffff"> + style="padding:20px 0px 20px 0px;background-color:#ffffff;box-sizing:border-box;" bgcolor="#ffffff"> <tr role='module-content'> <td height="100%" valign="top"> <!--[if (gte mso 9)|(IE)]> @@ -201,14 +201,14 @@ style="table-layout:fixed" width="100%"> <tbody> <tr> - <td align="center" bgcolor="" class="outer-td" style="padding:0px 0px 0px 0px"> + <td align="center" class="outer-td" style="padding:0px 0px 0px 0px"> <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="{{agreeUrl}}" 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" - target="_blank">AGREE</a> + <a 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" + href="{{agreeUrl}}" target="_blank">AGREE</a> </td> </tr> </tbody> @@ -237,14 +237,14 @@ style="table-layout:fixed" width="100%"> <tbody> <tr> - <td align="center" bgcolor="" class="outer-td" style="padding:0px 0px 0px 0px"> + <td align="center" class="outer-td" style="padding:0px 0px 0px 0px"> <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="#e4dfdf" class="inner-td" style="border-radius:6px;font-size:16px;text-align:center;background-color:inherit"> - <a href="{{declineUrl}}" style="background-color:#e4dfdf;border:1px solid #333333;border-color:#E4DFDF;border-radius:0px;border-width:1px;color:#302e2e;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">DECLINE</a> + <a style="background-color:#e4dfdf;border:1px solid #333333;border-color:#E4DFDF;border-radius:0px;border-width:1px;color:#302e2e;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" + href="{{declineUrl}}" target="_blank">DECLINE</a> </td> </tr> </tbody> @@ -273,7 +273,7 @@ <tr> <td style="padding:30px 23px 0px 23px;background-color:#ffffff;" height="100%" valign="top" bgcolor="#ffffff"> <p data-pm-slice="1 1 []"> - <a href="{{dashboardUrl}}">See more information</a> + <a href="{{baseUrl}}">See more information</a> </p> <p data-pm-slice="1 1 []"> </p> @@ -283,12 +283,19 @@ <p> </p> - <p>{{title}} - <br /> {{authors}} - </p> + <h2>{{title}}</h2> + + <p> </p> + + <h4> + <span style="font-family:arial,helvetica,sans-serif;">{{authors}}</span> + </h4> <p> - <br /> {{abstract}} + <br /> + <em> + <span style="font-family:arial,helvetica,sans-serif;">{{abstract}}</span> + </em> </p> <p> </p> @@ -326,7 +333,6 @@ </div> <p style="font-family:Arial,Helvetica, sans-serif;font-size:12px;line-height:20px"> <a class="Unsubscribe--unsubscribeLink" href="[Unsubscribe]">Unsubscribe</a> - - <a class="Unsubscribe--unsubscribePreferences" href="[Unsubscribe_Preferences]">Unsubscribe Preferences</a> </p> </div> </td> diff --git a/packages/xpub-faraday/config/authsome.js b/packages/xpub-faraday/config/authsome.js index b7c53182f33f615b851913ea0a0bc76a34571efc..147ad39978a4ac634324f79bcf07aebd4868bbbf 100644 --- a/packages/xpub-faraday/config/authsome.js +++ b/packages/xpub-faraday/config/authsome.js @@ -5,18 +5,16 @@ const omit = require('lodash/omit') async function teamPermissions(user, operation, object, context) { const permissions = ['handlingEditor', 'author'] const teams = await Promise.all( - user.teams - .map(async teamId => { - const team = await context.models.Team.find(teamId) - if (permissions.includes(team.teamType.permissions)) { - return team - } - return null - }) - .filter(Boolean), + user.teams.map(async teamId => { + const team = await context.models.Team.find(teamId) + if (permissions.includes(team.teamType.permissions)) { + return team + } + return null + }), ) - const collIDs = teams.map(team => team.object.id) + const collIDs = teams.filter(Boolean).map(team => team.object.id) if (collIDs.length > 0) { return {