diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index 9ef0a71f7c9260af9ef5f3fb5483189952e28a5c..4f258fa4436f16ae850c98ba02d1b201cd61e634 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -53,6 +53,7 @@ const cannotViewReviewersDetails = [ 'submitted', 'heInvited', ] + export const canViewReviewersDetails = (state, collection = {}) => { if (cannotViewReviewersDetails.includes(get(collection, 'status', 'draft'))) { return false @@ -60,9 +61,39 @@ export const canViewReviewersDetails = (state, collection = {}) => { return canViewReports(state, collection.id) } +const canHeViewEditorialCommentsStatuses = [ + 'revisionRequested', + 'rejected', + 'accepted', + 'inQA', +] export const canHeViewEditorialComments = (state, collection = {}) => { const isHE = isHEToManuscript(state, collection.id) - return isHE && collection.status === 'revisionRequested' + const status = get(collection, 'status', 'draft') + return isHE && canHeViewEditorialCommentsStatuses.includes(status) +} + +const canEICViewEditorialCommentsStatuses = ['rejected', 'accepted', 'inQA'] +export const canEICViewEditorialComments = (state, collection = {}) => { + const isEIC = currentUserIs(state, 'adminEiC') + const status = get(collection, 'status', 'draft') + return isEIC && canEICViewEditorialCommentsStatuses.includes(status) +} + +export const canViewEditorialComments = ( + state, + collection = {}, + fragmentId, +) => { + const editorialRecommentations = getFragmentEditorialComments( + state, + fragmentId, + ) + return ( + (canHeViewEditorialComments(state, collection) || + canEICViewEditorialComments(state, collection)) && + editorialRecommentations.length > 0 + ) } export const getUserToken = ({ currentUser }) => @@ -259,6 +290,10 @@ export const getFragmentReviewerRecommendations = (state, fragmentId) => getFragmentRecommendations(state, fragmentId).filter( r => r.recommendationType === 'review', ) +const getFragmentEditorialComments = (state, fragmentId) => + getFragmentRecommendations(state, fragmentId).filter( + r => r.recommendationType === 'editorRecommendation', + ) const getOwnRecommendations = (state, fragmentId) => chain(state) diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index 6309e8fd725aecad6e93ac0102aecd125511b2a7..b054b71e438ae82970fbfbfe8680a231e5e8782e 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -102,13 +102,12 @@ const ManuscriptLayout = ({ getSignedUrl={getSignedUrl} /> - {get(currentUser, 'permissions.canHeViewEditorialComments', true) && - !!editorialRecommendations.length && ( - <EditorialCommentCard - journal={journal} - reports={editorialRecommendations} - /> - )} + {get(currentUser, 'permissions.canViewEditorialComments', true) && ( + <EditorialCommentCard + journal={journal} + reports={editorialRecommendations} + /> + )} {submittedOwnRecommendation && ( <ReviewerReportCard diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js index 68a7ac40140a2b4dcf2a357597f3bf1feca29c2b..2189c963df0fb5bd1ffc90093689816d2fa68b86 100644 --- a/packages/component-manuscript/src/components/ManuscriptPage.js +++ b/packages/component-manuscript/src/components/ManuscriptPage.js @@ -48,10 +48,10 @@ import { currentUserIsReviewer, parseCollectionDetails, canMakeHERecommendation, + canViewEditorialComments, canViewReviewersDetails, pendingReviewerInvitation, canOverrideTechnicalChecks, - canHeViewEditorialComments, getOwnPendingRecommendation, getOwnSubmittedRecommendation, getFragmentReviewerRecommendations, @@ -167,9 +167,10 @@ export default compose( }), canAssignHE: canAssignHE(state, match.params.project), canViewReports: canViewReports(state, match.params.project), - canHeViewEditorialComments: canHeViewEditorialComments( + canViewEditorialComments: canViewEditorialComments( state, collection, + match.params.version, ), canInviteReviewers: canInviteReviewers(state, collection), canMakeRecommendation: !isUndefined(pendingOwnRecommendation),