From fecf90ff38ce6aec6098f59705526129986ced7f Mon Sep 17 00:00:00 2001 From: Tania Fecheta <tania.fecheta@thinslices.com> Date: Thu, 8 Nov 2018 10:34:51 +0200 Subject: [PATCH] refactor(currentUserIsAuthor): refactor currectUserIsAuthor to get authors from fragment --- packages/component-faraday-selectors/src/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index d2f185a9f..8076ed60d 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -80,7 +80,7 @@ export const authorCanViewReportsDetails = ( collection = {}, fragmentId, ) => { - const isAuthor = currentUserIsAuthor(state) + const isAuthor = currentUserIsAuthor(state, fragmentId) return ( authorCanViewReportsDetailsStatuses.includes( get(collection, 'status', 'draft'), @@ -153,7 +153,7 @@ export const canAuthorViewEditorialComments = ( collection = {}, fragmentId, ) => { - const isAuthor = currentUserIsAuthor(state) + const isAuthor = currentUserIsAuthor(state, fragmentId) return ( isAuthor && !cannotAuthorViewEditorialCommentsStatuses.includes( @@ -251,10 +251,10 @@ export const canMakeRevision = (state, collection = {}, fragment = {}) => { ) } -export const currentUserIsAuthor = state => { - const authors = state.collections[0].owners.map(e => e.id) - const user = state.currentUser.user.id - return authors.includes(user) +export const currentUserIsAuthor = (state, fragmentId) => { + const { id: userId } = selectCurrentUser(state) + const authors = get(state, `fragments.${fragmentId}.authors`, []) + return !!authors.find(a => a.id === userId) } export const getUserPermissions = ({ teams = [] }) => -- GitLab