diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index 4a57da8b656dd7992c438c82307ade57e2bd2e8e..a46c4be9058a0731fdd53a7cfb07d5bee2cdf917 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -27,7 +27,11 @@ const filterRefusedInvitations = (coll, user) => { return coll } -const filterObjectData = (collectionsPermissions, object, user) => { +const filterObjectData = ( + collectionsPermissions = [], + object = {}, + user = {}, +) => { if (object.type === 'fragment') { const matchingCollPerm = collectionsPermissions.find( collPerm => object.id === collPerm.fragmentId, diff --git a/packages/xpub-faraday/config/authsome-mode.js b/packages/xpub-faraday/config/authsome-mode.js index ce1b73c53f6254bed8ef76d1ad662ed21623936d..f79daa16f5a93c43782f08247c7afe0f1f686a3a 100644 --- a/packages/xpub-faraday/config/authsome-mode.js +++ b/packages/xpub-faraday/config/authsome-mode.js @@ -16,18 +16,21 @@ async function teamPermissions(user, operation, object, context) { return null }), ) - const objectType = get(object, 'type') - let fragmentId = null - if (objectType !== undefined) { - if (objectType === 'fragment') { - fragmentId = object.id - } - } - const collectionsPermissions = teams.filter(Boolean).map(team => ({ - id: team.object.id, - permission: team.teamType.permissions, - fragmentId, - })) + + const collectionsPermissions = Promise.all( + teams.filter(Boolean).map(async team => { + const collection = await context.models.Collection.find(team.object.id) + const collPerm = { + id: collection.id, + permission: team.teamType.permissions, + } + const objectType = get(object, 'type') + if (objectType === 'fragment' && collection.fragments.includes(object.id)) + collPerm.fragmentId = object.id + + return collPerm + }), + ) if (collectionsPermissions.length === 0) return {}