diff --git a/packages/component-invite/src/CollectionsInvitations.js b/packages/component-invite/src/CollectionsInvitations.js index ef41fa660b00bbe69249187b88d8d6fce26595c8..3dcd2cd585db246d444a949bae33c0c55dc793f1 100644 --- a/packages/component-invite/src/CollectionsInvitations.js +++ b/packages/component-invite/src/CollectionsInvitations.js @@ -14,7 +14,7 @@ const CollectionsInvitations = app => { * @apiParamExample {json} Body * { * "email": "email@example.com", - * "role": "handlingEditor", [acceptedValues: handlingEditor] + * "role": "handlingEditor", [acceptedValues: handlingEditor, reviewer] * } * @apiSuccessExample {json} Success * HTTP/1.1 200 OK diff --git a/packages/component-invite/src/routes/collectionsInvitations/delete.js b/packages/component-invite/src/routes/collectionsInvitations/delete.js index 0eb3ca07b1f9ecc2ba3ff95d68c3d05bfcdbe06f..6b319396253621b75544526661dd8ae3f5e6e8ca 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/delete.js +++ b/packages/component-invite/src/routes/collectionsInvitations/delete.js @@ -4,13 +4,8 @@ const mailService = require('pubsweet-component-mail-service') const logger = require('@pubsweet/logger') module.exports = models => async (req, res) => { - const reqUser = await models.User.find(req.user) - if (!reqUser.editorInChief && !reqUser.admin) { - res.status(403).json({ - error: 'The request user must be Editor in Chief or Admin', - }) - return - } + // const reqUser = await models.User.find(req.user) + // TO DO: authsome const { collectionId, invitationId } = req.params try { const collection = await models.Collection.find(collectionId) @@ -41,10 +36,20 @@ module.exports = models => async (req, res) => { user.teams = user.teams.filter(userTeamId => team.id !== userTeamId) await user.save() try { - await mailService.setupRevokeInvitationEmail( - user.email, - 'revoke-handling-editor', - ) + let emailType + switch (invitation.role) { + case 'handlingEditor': + emailType = 'revoke-handling-editor' + break + case 'reviewer': + emailType = 'unassign-reviewer' + break + default: + return res.status(500).json({ + error: 'Something went wrong', + }) + } + await mailService.setupRevokeInvitationEmail(user.email, emailType) return res.status(200).json({}) } catch (e) { diff --git a/packages/component-invite/src/routes/collectionsInvitations/get.js b/packages/component-invite/src/routes/collectionsInvitations/get.js index cd233002e0076d06f1e7038477b4888ff2ff9751..5650c6ef10817d2c74d30cff316396383478c2bd 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/get.js +++ b/packages/component-invite/src/routes/collectionsInvitations/get.js @@ -6,13 +6,7 @@ const inviteHelper = require('../../helpers/Invitation') const configRoles = config.get('roles') module.exports = models => async (req, res) => { const { userId, role } = req.query - const reqUser = await models.User.find(req.user) - if (!reqUser.editorInChief && !reqUser.admin) { - res.status(403).json({ - error: 'The request user must be Editor in Chief or Admin', - }) - return - } + // TO DO: authsome if (!helpers.checkForUndefinedParams(userId, role)) { res.status(400).json({ error: 'User ID and Role are required' }) return diff --git a/packages/component-invite/src/routes/collectionsInvitations/post.js b/packages/component-invite/src/routes/collectionsInvitations/post.js index 36fe00bdd198becb7d80f31a62f2fe8d64248e95..170277a769ec1610cb041938bb89dd3e00dddb54 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/post.js +++ b/packages/component-invite/src/routes/collectionsInvitations/post.js @@ -5,6 +5,7 @@ const collectionHelper = require('../../helpers/Collection') const teamHelper = require('../../helpers/Team') const config = require('config') const mailService = require('pubsweet-component-mail-service') +const userHelper = require('../../helpers/User') const configRoles = config.get('roles') @@ -55,11 +56,20 @@ module.exports = models => async (req, res) => { await collectionHelper.addHandlingEditor(collection, user, invitation) } try { - await mailService.setupAssignEmail( - user.email, - 'assign-handling-editor', - url, - ) + let emailType + switch (role) { + case 'handlingEditor': + emailType = 'assign-handling-editor' + break + case 'reviewer': + emailType = 'invite-reviewer' + break + default: + return res.status(500).json({ + error: 'Something went wrong', + }) + } + await mailService.setupAssignEmail(user.email, emailType, url) return res.status(200).json(user) } catch (e) { @@ -67,6 +77,25 @@ module.exports = models => async (req, res) => { return res.status(500).json({ error: 'Email could not be sent.' }) } } catch (e) { + if (role === 'reviewer') { + const newUser = await userHelper.setupNewUser( + req.body, + url, + res, + email, + role, + models.User, + 'invite', + ) + if (newUser.error !== undefined) { + return res.status(newUser.status).json({ + error: newUser.message, + }) + } + await teamHelper.setupManuscriptTeam(models, newUser, collectionId, role) + await collectionHelper.addInvitation(collection, newUser.id, role) + return res.status(200).json(newUser) + } const notFoundError = await helpers.handleNotFoundError(e, 'user') return res.status(notFoundError.status).json({ error: notFoundError.message, diff --git a/packages/component-mail-service/src/Mail.js b/packages/component-mail-service/src/Mail.js index d1f177969be06cc0f5e5fd508a9d97055fd6c053..8ad93613f510483eceee3cd40d35506e832decd8 100644 --- a/packages/component-mail-service/src/Mail.js +++ b/packages/component-mail-service/src/Mail.js @@ -42,6 +42,12 @@ module.exports = { url: dashBoardUrl, } break + case 'invite-reviewer': + subject = 'Review Request' + replacements = { + url: dashBoardUrl, + } + break default: subject = 'Welcome to Hindawi!' break @@ -64,9 +70,11 @@ module.exports = { case 'revoke-handling-editor': subject = 'Invitation has been Cancelled' break - default: - subject = 'Welcome to Hindawi!' + case 'unassign-reviewer': + subject = 'Reviewer Unassigned' break + default: + throw new Error('Invalid emailType') } const { htmlBody, textBody } = getEmailBody(emailType, replacements) diff --git a/packages/component-mail-service/src/templates/invite-reviewer.html b/packages/component-mail-service/src/templates/invite-reviewer.html new file mode 100644 index 0000000000000000000000000000000000000000..90ad9a6b12304d999df41179eeb5702e3c3ac282 --- /dev/null +++ b/packages/component-mail-service/src/templates/invite-reviewer.html @@ -0,0 +1,231 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html data-editor-version="2" class="sg-campaigns" xmlns="http://www.w3.org/1999/xhtml"> + +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" /> + <!--[if !mso]><!--> + <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> + <!--<![endif]--> + <!--[if (gte mso 9)|(IE)]> + <xml> + <o:OfficeDocumentSettings> + <o:AllowPNG/> + <o:PixelsPerInch>96</o:PixelsPerInch> + </o:OfficeDocumentSettings> + </xml> + <![endif]--> + <!--[if (gte mso 9)|(IE)]> + <style type="text/css"> + body {width: 600px;margin: 0 auto;} + table {border-collapse: collapse;} + table, td {mso-table-lspace: 0pt;mso-table-rspace: 0pt;} + img {-ms-interpolation-mode: bicubic;} + </style> + <![endif]--> + + <style type="text/css"> + body, + p, + div { + font-family: helvetica, arial, sans-serif; + font-size: 14px; + } + + body { + color: #626262; + } + + body a { + color: #0D78F2; + text-decoration: none; + } + + p { + margin: 0; + padding: 0; + } + + table.wrapper { + width: 100% !important; + table-layout: fixed; + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: 100%; + -moz-text-size-adjust: 100%; + -ms-text-size-adjust: 100%; + } + + img.max-width { + max-width: 100% !important; + } + + .column.of-2 { + width: 50%; + } + + .column.of-3 { + width: 33.333%; + } + + .column.of-4 { + width: 25%; + } + + @media screen and (max-width:480px) { + .preheader .rightColumnContent, + .footer .rightColumnContent { + text-align: left !important; + } + .preheader .rightColumnContent div, + .preheader .rightColumnContent span, + .footer .rightColumnContent div, + .footer .rightColumnContent span { + text-align: left !important; + } + .preheader .rightColumnContent, + .preheader .leftColumnContent { + font-size: 80% !important; + padding: 5px 0; + } + table.wrapper-mobile { + width: 100% !important; + table-layout: fixed; + } + img.max-width { + height: auto !important; + max-width: 480px !important; + } + a.bulletproof-button { + display: block !important; + width: auto !important; + font-size: 80%; + padding-left: 0 !important; + padding-right: 0 !important; + } + .columns { + width: 100% !important; + } + .column { + display: block !important; + width: 100% !important; + padding-left: 0 !important; + padding-right: 0 !important; + margin-left: 0 !important; + margin-right: 0 !important; + } + } + </style> + <!--user entered Head Start--> + + <!--End Head user entered--> +</head> + +<body> + <center class="wrapper" data-link-color="#0D78F2" data-body-style="font-size: 14px; font-family: helvetica,arial,sans-serif; color: #626262; background-color: #F4F4F4;"> + <div class="webkit"> + <table cellpadding="0" cellspacing="0" border="0" width="100%" class="wrapper" bgcolor="#F4F4F4"> + <tr> + <td valign="top" bgcolor="#F4F4F4" width="100%"> + <table width="100%" role="content-container" class="outer" align="center" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td width="100%"> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td> + <!--[if mso]> + <center> + <table><tr><td width="600"> + <![endif]--> + <table width="100%" cellpadding="0" cellspacing="0" border="0" style="width: 100%; max-width:600px;" align="center"> + <tr> + <td role="modules-container" style="padding: 0px 0px 0px 0px; color: #626262; text-align: left;" bgcolor="#F4F4F4" width="100%" + align="left"> + + <table class="module preheader preheader-hide" role="module" data-type="preheader" border="0" cellpadding="0" cellspacing="0" + 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>invite reviewer</p> + </td> + </tr> + </table> + + <table class="wrapper" role="module" data-type="image" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;"> + <tr> + <td style="font-size:6px;line-height:10px;padding:20px 0px 20px 0px;" valign="top" align="center"> + <img class="max-width" border="0" style="display:block;color:#000000;text-decoration:none;font-family:Helvetica, arial, sans-serif;font-size:16px;max-width:10% !important;width:10%;height:auto !important;" + src="https://marketing-image-production.s3.amazonaws.com/uploads/bb39b20cf15e52c1c0933676e25f2b2402737c6560b8098c204ad6932b84eb2058804376dbc4db138c7a21dcaed9325bde36185648afac5bc97e3d73d4e12718.png" + alt="" width="60"> + </td> + </tr> + </table> + + <table class="module" role="module" data-type="text" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;"> + <tr> + <td style="padding:30px 23px 0px 23px;background-color:#ffffff;" height="100%" valign="top" bgcolor="#ffffff"> + <h1 style="text-align: center;">You have been requested to review a manuscript.</h1> + <div style="text-align: center;">Please click on the link below to access your dashboard.</div> + + <div style="text-align: center;"> </div> + + <div style="text-align: center;"> </div> + + </td> + </tr> + </table> + <table border="0" cellPadding="0" cellSpacing="0" class="module" data-role="module-button" data-type="button" role="module" + style="table-layout:fixed" width="100%"> + <tbody> + <tr> + <td align="center" bgcolor="#FFFFFF" class="outer-td" style="padding:0px 0px 30px 0px;background-color:#FFFFFF"> + <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="{{ url }}" 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">VIEW DASHBOARD</a> + </td> + </tr> + </tbody> + </table> + </td> + </tr> + </tbody> + </table> + <div data-role="module-unsubscribe" class="module unsubscribe-css__unsubscribe___2CDlR" role="module" + data-type="unsubscribe" style="color:#444444;font-size:12px;line-height:20px;padding:16px 16px 16px 16px;text-align:center"> + <div class="Unsubscribe--addressLine"> + <p class="Unsubscribe--senderName" style="font-family:Arial, Helvetica, sans-serif;font-size:12px;line-height:20px">Hindawi Publishing Corporation</p> + <p style="font-family:Arial, Helvetica, sans-serif;font-size:12px;line-height:20px"> + <span class="Unsubscribe--senderAddress">315 Madison Ave, Third Floor, Suite 3070</span>, + <span class="Unsubscribe--senderCity">NEW YORK</span>, + <span class="Unsubscribe--senderState">NY</span> + <span class="Unsubscribe--senderZip">10017</span> + </p> + </div> + <p style="font-family:Arial, Helvetica, sans-serif;font-size:12px;line-height:20px"> + <a class="Unsubscribe--unsubscribeLink" href="[Unsubscribe]">Unsubscribe</a> + </p> + </div> + </td> + </tr> + </table> + <!--[if mso]> + </td></tr></table> + </center> + <![endif]--> + </td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + </table> + </div> + </center> +</body> + +</html> \ No newline at end of file diff --git a/packages/component-mail-service/src/templates/invite-reviewer.txt b/packages/component-mail-service/src/templates/invite-reviewer.txt new file mode 100644 index 0000000000000000000000000000000000000000..90d999018f7fa366d4d23b80288aa2e6f0ab39f5 --- /dev/null +++ b/packages/component-mail-service/src/templates/invite-reviewer.txt @@ -0,0 +1,6 @@ +You have been requested to review a manuscript. +Please click on the link below to access your dashboard +{{ url }} VIEW DASHBOARD +Hindawi Publishing Corporation +315 Madison Ave, Third Floor, Suite 307 +New York, NY 10017 \ No newline at end of file diff --git a/packages/component-mail-service/src/templates/invite.html b/packages/component-mail-service/src/templates/invite.html index 605a978325d85db3e76430f1bfb88b8b4020c65d..f4482f49528547779f1947527c181f135dcd9d7f 100644 --- a/packages/component-mail-service/src/templates/invite.html +++ b/packages/component-mail-service/src/templates/invite.html @@ -150,19 +150,6 @@ </tr> </table> - <table class="module" role="module" data-type="text" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;"> - <tr> - <td style="padding:0px 0px 0px 0px;" height="100%" valign="top" bgcolor=""> - <div style="text-align: right;"> - <span style="font-family:verdana,geneva,sans-serif;"> - <span style="font-size:10px;">Email not displaying correctly? - <a href="[weblink]">View it</a> in your browser.</span> - </span> - </div> - </td> - </tr> - </table> - <table class="wrapper" role="module" data-type="image" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;"> <tr> <td style="font-size:6px;line-height:10px;padding:20px 0px 20px 0px;" valign="top" align="center"> diff --git a/packages/component-mail-service/src/templates/unassign-reviewer.html b/packages/component-mail-service/src/templates/unassign-reviewer.html new file mode 100644 index 0000000000000000000000000000000000000000..d733dcab134c6302db5f282d8cc65c3ffdeefb0a --- /dev/null +++ b/packages/component-mail-service/src/templates/unassign-reviewer.html @@ -0,0 +1,211 @@ + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html data-editor-version="2" class="sg-campaigns" xmlns="http://www.w3.org/1999/xhtml"> + +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" /> + <!--[if !mso]><!--> + <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> + <!--<![endif]--> + <!--[if (gte mso 9)|(IE)]> + <xml> + <o:OfficeDocumentSettings> + <o:AllowPNG/> + <o:PixelsPerInch>96</o:PixelsPerInch> + </o:OfficeDocumentSettings> + </xml> + <![endif]--> + <!--[if (gte mso 9)|(IE)]> + <style type="text/css"> + body {width: 600px;margin: 0 auto;} + table {border-collapse: collapse;} + table, td {mso-table-lspace: 0pt;mso-table-rspace: 0pt;} + img {-ms-interpolation-mode: bicubic;} + </style> + <![endif]--> + + <style type="text/css"> + body, + p, + div { + font-family: helvetica, arial, sans-serif; + font-size: 14px; + } + + body { + color: #626262; + } + + body a { + color: #0D78F2; + text-decoration: none; + } + + p { + margin: 0; + padding: 0; + } + + table.wrapper { + width: 100% !important; + table-layout: fixed; + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: 100%; + -moz-text-size-adjust: 100%; + -ms-text-size-adjust: 100%; + } + + img.max-width { + max-width: 100% !important; + } + + .column.of-2 { + width: 50%; + } + + .column.of-3 { + width: 33.333%; + } + + .column.of-4 { + width: 25%; + } + + @media screen and (max-width:480px) { + .preheader .rightColumnContent, + .footer .rightColumnContent { + text-align: left !important; + } + .preheader .rightColumnContent div, + .preheader .rightColumnContent span, + .footer .rightColumnContent div, + .footer .rightColumnContent span { + text-align: left !important; + } + .preheader .rightColumnContent, + .preheader .leftColumnContent { + font-size: 80% !important; + padding: 5px 0; + } + table.wrapper-mobile { + width: 100% !important; + table-layout: fixed; + } + img.max-width { + height: auto !important; + max-width: 480px !important; + } + a.bulletproof-button { + display: block !important; + width: auto !important; + font-size: 80%; + padding-left: 0 !important; + padding-right: 0 !important; + } + .columns { + width: 100% !important; + } + .column { + display: block !important; + width: 100% !important; + padding-left: 0 !important; + padding-right: 0 !important; + margin-left: 0 !important; + margin-right: 0 !important; + } + } + </style> + <!--user entered Head Start--> + + <!--End Head user entered--> +</head> + +<body> + <center class="wrapper" data-link-color="#0D78F2" data-body-style="font-size: 14px; font-family: helvetica,arial,sans-serif; color: #626262; background-color: #F4F4F4;"> + <div class="webkit"> + <table cellpadding="0" cellspacing="0" border="0" width="100%" class="wrapper" bgcolor="#F4F4F4"> + <tr> + <td valign="top" bgcolor="#F4F4F4" width="100%"> + <table width="100%" role="content-container" class="outer" align="center" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td width="100%"> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td> + <!--[if mso]> + <center> + <table><tr><td width="600"> + <![endif]--> + <table width="100%" cellpadding="0" cellspacing="0" border="0" style="width: 100%; max-width:600px;" align="center"> + <tr> + <td role="modules-container" style="padding: 0px 0px 0px 0px; color: #626262; text-align: left;" bgcolor="#F4F4F4" width="100%" + align="left"> + + <table class="module preheader preheader-hide" role="module" data-type="preheader" border="0" cellpadding="0" cellspacing="0" + 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>unassign reviewer</p> + </td> + </tr> + </table> + + <table class="wrapper" role="module" data-type="image" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;"> + <tr> + <td style="font-size:6px;line-height:10px;padding:20px 0px 20px 0px;" valign="top" align="center"> + <img class="max-width" border="0" style="display:block;color:#000000;text-decoration:none;font-family:Helvetica, arial, sans-serif;font-size:16px;max-width:10% !important;width:10%;height:auto !important;" + src="https://marketing-image-production.s3.amazonaws.com/uploads/bb39b20cf15e52c1c0933676e25f2b2402737c6560b8098c204ad6932b84eb2058804376dbc4db138c7a21dcaed9325bde36185648afac5bc97e3d73d4e12718.png" + alt="" width="60"> + </td> + </tr> + </table> + + <table class="module" role="module" data-type="text" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;"> + <tr> + <td style="padding:30px 23px 0px 23px;background-color:#ffffff;" height="100%" valign="top" bgcolor="#ffffff"> + <h1 style="text-align: center;">Your Reviewer invitation to a manuscript has been revoked.</h1> + + <div style="text-align: center;"> </div> + + <div style="text-align: center;"> </div> + + </td> + </tr> + </table> + <div data-role="module-unsubscribe" class="module unsubscribe-css__unsubscribe___2CDlR" role="module" + data-type="unsubscribe" style="color:#444444;font-size:12px;line-height:20px;padding:16px 16px 16px 16px;text-align:center"> + <div class="Unsubscribe--addressLine"> + <p class="Unsubscribe--senderName" style="font-family:Arial, Helvetica, sans-serif;font-size:12px;line-height:20px">Hindawi Publishing Corporation</p> + <p style="font-family:Arial, Helvetica, sans-serif;font-size:12px;line-height:20px"> + <span class="Unsubscribe--senderAddress">315 Madison Ave, Third Floor, Suite 3070</span>, + <span class="Unsubscribe--senderCity">NEW YORK</span>, + <span class="Unsubscribe--senderState">NY</span> + <span class="Unsubscribe--senderZip">10017</span> + </p> + </div> + <p style="font-family:Arial, Helvetica, sans-serif;font-size:12px;line-height:20px"> + <a class="Unsubscribe--unsubscribeLink" href="[Unsubscribe]">Unsubscribe</a> + </p> + </div> + </td> + </tr> + </table> + <!--[if mso]> + </td></tr></table> + </center> + <![endif]--> + </td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + </table> + </div> + </center> +</body> + +</html> \ No newline at end of file diff --git a/packages/component-mail-service/src/templates/unassign-reviewer.txt b/packages/component-mail-service/src/templates/unassign-reviewer.txt new file mode 100644 index 0000000000000000000000000000000000000000..dfbe893355266a1c048663134d1ce3fd01b59167 --- /dev/null +++ b/packages/component-mail-service/src/templates/unassign-reviewer.txt @@ -0,0 +1,4 @@ +Your Reviewer invitation to a manuscript has been revoked. +Hindawi Publishing Corporation +315 Madison Ave, Third Floor, Suite 307 +New York, NY 10017 \ No newline at end of file