diff --git a/packages/component-invite/src/helpers/authsome.js b/packages/component-invite/src/helpers/authsome.js new file mode 100644 index 0000000000000000000000000000000000000000..7ae32a08c8916d1388051a88a7fae7bef78a746d --- /dev/null +++ b/packages/component-invite/src/helpers/authsome.js @@ -0,0 +1,8 @@ +const config = require('config') +const Authsome = require('authsome') + +const mode = require(config.get('authsome.mode')) + +const authsome = new Authsome({ ...config.authsome, mode }, {}) + +module.exports = authsome diff --git a/packages/component-invite/src/routes/collectionsInvitations/post.js b/packages/component-invite/src/routes/collectionsInvitations/post.js index 28660b529aae8cbfda8f4ac9c962d966466f22ac..73a588a3be1b40554dd9d6d9bebc11a042e6ff16 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/post.js +++ b/packages/component-invite/src/routes/collectionsInvitations/post.js @@ -40,6 +40,7 @@ module.exports = models => async (req, res) => { error: notFoundError.message, }) } + const baseUrl = `${req.protocol}://${req.get('host')}` const params = { baseUrl, diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index e9eb600cbef1cb248ebf518e146e891f2e91afb3..5b6633a6150b55db19f733b1ef65351640ae6ccb 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -19,7 +19,7 @@ module.exports = { coll.visibleStatus = statuses[coll.status].private } }, - filterRefusedReviewers: (coll, user) => { + filterRefusedInvitations: (coll, user) => { const matchingInv = coll.invitations.find(inv => inv.userId === user.id) if (matchingInv === undefined) return null if (matchingInv.hasAnswer === true && !matchingInv.isAccepted) return null diff --git a/packages/xpub-faraday/config/authsome.js b/packages/xpub-faraday/config/authsome-mode.js similarity index 94% rename from packages/xpub-faraday/config/authsome.js rename to packages/xpub-faraday/config/authsome-mode.js index cd7bed1d09f72d09798f6b8cc4e0d03cb9c0dc75..ac3198fe9a0a7f7ad6101fd96e3325ad5422a78f 100644 --- a/packages/xpub-faraday/config/authsome.js +++ b/packages/xpub-faraday/config/authsome-mode.js @@ -35,8 +35,12 @@ async function teamPermissions(user, operation, object, context) { } helpers.setPublicStatuses(coll, matchingCollPerm) helpers.parseReviewerAuthors(coll, matchingCollPerm) - if (['reviewer'].includes(matchingCollPerm.permission)) { - return helpers.filterRefusedReviewers(coll, user) + if ( + ['reviewer', 'handlingEditor'].includes( + matchingCollPerm.permission, + ) + ) { + return helpers.filterRefusedInvitations(coll, user) } return coll }) @@ -97,11 +101,11 @@ function unauthenticatedUser(operation, object) { async function authenticatedUser(user, operation, object, context) { // Allow the authenticated user to POST a collection (but not with a 'filtered' property) - // if (operation === 'POST' && object.path === '/collections') { - // return { - // filter: collection => omit(collection, 'filtered'), - // } - // } + if (operation === 'POST' && object.path === '/collections') { + return { + filter: collection => omit(collection, 'filtered'), + } + } // Allow the authenticated user to GET collections they own if (operation === 'GET' && object === '/collections/') { diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js index be3a905e9e638fd76db16d4f0f8f31c6b9886bdf..a773b41f2bd0746604c0ca261d1b0aa01fe5267d 100644 --- a/packages/xpub-faraday/config/default.js +++ b/packages/xpub-faraday/config/default.js @@ -21,9 +21,14 @@ const getDbConfig = () => { module.exports = { authsome: { - mode: path.resolve(__dirname, 'authsome.js'), + mode: path.resolve(__dirname, 'authsome-mode.js'), teams: { - // TODO + handlingEditor: { + name: 'Handling Editors', + }, + reviewer: { + name: 'Reviewer', + }, }, }, validations: path.resolve(__dirname, 'validations.js'),