From b54657f9b1ce3ec02347dc631e356314b4760369 Mon Sep 17 00:00:00 2001 From: Sebastian Mihalache <sebastian.mihalache@gmail.con> Date: Mon, 7 May 2018 17:17:51 +0300 Subject: [PATCH] fix reviewer files filter --- .../xpub-faraday/config/authsome-helpers.js | 6 ++++- packages/xpub-faraday/config/authsome-mode.js | 27 ++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index 4a57da8b6..a46c4be90 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 ce1b73c53..f79daa16f 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 {} -- GitLab