diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index 71d31a00307d2c1f148a0d0aa23fb923aa2ea744..3dcdaa7a4cea7472a0d05a947f1a318fc9aee9a3 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -64,6 +64,13 @@ const canViewContextualBoxOnOldVersion = (collection, fragmentId) => { ) ) } + +const canHEViewContextualBoxOnOldVersion = (collection, fragmentId) => { + const fragments = get(collection, 'fragments', []) + const oldVersions = slice(fragments, 0, fragments.length - 1) + const isOldVersion = !!find(oldVersions, fragment => fragment === fragmentId) + return isOldVersion && get(collection, 'status', 'draft') === 'heInvited' +} const cannotViewReviewersDetails = [ 'draft', 'technicalChecks', @@ -193,8 +200,12 @@ export const canViewEditorialComments = ( state, fragmentId, ) + const isHE = currentUserIs(state, 'isHE') + const canViewEditorialCommentsOnOldVersion = isHE + ? !canHEViewContextualBoxOnOldVersion(collection, fragmentId) + : canViewContextualBoxOnOldVersion(collection, fragmentId) return ( - (canViewContextualBoxOnOldVersion(collection, fragmentId) || + (canViewEditorialCommentsOnOldVersion || canHeViewEditorialComments(state, collection) || canEICViewEditorialComments(state, collection) || canReviewerViewEditorialComments(state, collection, fragment) || @@ -203,7 +214,6 @@ export const canViewEditorialComments = ( ) } -const cannotViewResponseFromAuthorStatuses = ['reviewersInvited'] export const canViewResponseFromAuthor = (state, collection, fragmentId) => { const authorResponseToRevisonRequest = getFragmentAuthorResponse( state, @@ -212,12 +222,14 @@ export const canViewResponseFromAuthor = (state, collection, fragmentId) => { const canHEViewResponseFromAuthor = currentUserIs(state, 'isHE') && get(collection, 'status', 'draft') === 'heInvited' + + const canReviewerViewResponsefromAuthor = + currentUserIsReviewerInPending(state, fragmentId) && + get(collection, 'status', 'draft') === 'reviewersInvited' return ( !isEmpty(authorResponseToRevisonRequest) && !canHEViewResponseFromAuthor && - !cannotViewResponseFromAuthorStatuses.includes( - get(collection, 'status', 'draft'), - ) + !canReviewerViewResponsefromAuthor ) } @@ -348,6 +360,13 @@ export const pendingReviewerInvitation = (state, fragmentId) => ) .value() +export const currentUserIsReviewerInPending = (state, fragmentId) => { + const currentUser = selectCurrentUser(state) + const invitations = get(state, `fragments.${fragmentId}.invitations`, []) + return !!invitations.find( + i => i.userId === currentUser.id && i.role === 'reviewer' && !i.isAccepted, + ) +} export const currentUserIsReviewer = (state, fragmentId) => { const currentUser = selectCurrentUser(state) const invitations = get(state, `fragments.${fragmentId}.invitations`, [])