diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index fab299296f67b3f089781024a0c9a37c4dd7ed81..8969b158dc356e794a2ed50e061e320cb69a8a0c 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -61,6 +61,29 @@ export const canViewReviewersDetails = (state, collection = {}) => { return canViewReports(state, collection.id) } +const cannotAuthorViewEditorialCommentsStatuses = [ + 'draft', + 'technicalChecks', + 'submitted', + 'heInvited', + 'heAssigned', + 'reviewersInvited', +] + +export const canAuthorViewEditorialComments = ( + state, + collection = {}, + fragmentId, +) => { + const isAuthor = currentUserIsAuthor(state, fragmentId) + return ( + isAuthor && + !cannotAuthorViewEditorialCommentsStatuses.includes( + get(collection, 'status', 'draft'), + ) + ) +} + const canHeViewEditorialCommentsStatuses = [ 'revisionRequested', 'rejected', @@ -92,7 +115,8 @@ export const canViewEditorialComments = ( ) return ( (canHeViewEditorialComments(state, collection) || - canEICViewEditorialComments(state, collection)) && + canEICViewEditorialComments(state, collection) || + canAuthorViewEditorialComments(state, collection, fragmentId)) && editorialRecommentations.length > 0 ) } diff --git a/packages/component-faraday-ui/src/EditorialReportCard.js b/packages/component-faraday-ui/src/EditorialReportCard.js index a89ca77499af8c0d0a6b6ceff3b6b5af97c617d5..8414bcdeea77494c6aefd0190cf0d93ae48014bb 100644 --- a/packages/component-faraday-ui/src/EditorialReportCard.js +++ b/packages/component-faraday-ui/src/EditorialReportCard.js @@ -17,6 +17,8 @@ const EditorialReportCard = ({ recommendation, editorName, editorRole, + handlingEditorName, + collection, report: { createdOn, reviewer }, }) => ( <Root> @@ -33,7 +35,9 @@ const EditorialReportCard = ({ <Item justify="flex-end"> {reviewer && ( <Fragment> - <Text mr={1 / 2}>{editorName}</Text> + <Text mr={1 / 2}> + {handlingEditorName !== 'Assigned' ? editorName : ''} + </Text> <Tag mr={2}>{editorRole}</Tag> </Fragment> )} @@ -77,6 +81,8 @@ export default compose( 'reviewer.lastName', '', )}`, + getHandlingEditorName: ({ collection }) => () => + `${get(collection, 'handlingEditor.name', '')}`, getRecommendationLabel: ({ report, journal: { recommendations = [] }, @@ -87,10 +93,17 @@ export default compose( ), }), withProps( - ({ report, getReviewerRole, getReviewerName, getRecommendationLabel }) => ({ + ({ + report, + getReviewerRole, + getReviewerName, + getHandlingEditorName, + getRecommendationLabel, + }) => ({ recommendation: getRecommendationLabel(), publicReport: getReportComments({ report, isPublic: true }), privateReport: getReportComments({ report, isPublic: false }), + handlingEditorName: getHandlingEditorName(), editorName: getReviewerName(), editorRole: getReviewerRole(), }), diff --git a/packages/component-faraday-ui/src/EditorialReportCard.md b/packages/component-faraday-ui/src/EditorialReportCard.md index 0c81711ef2c425f242e7f7b7433347f78de2aa15..4d62d34b58bddfeacd5aa3f9fa5a6b8760e6b62f 100644 --- a/packages/component-faraday-ui/src/EditorialReportCard.md +++ b/packages/component-faraday-ui/src/EditorialReportCard.md @@ -47,12 +47,12 @@ const journal = { }, ], } -;<EditorialReportCard - report={report} - journal={journal} - publicLabel="Message For Author" - privateLabel="Message For Editorial Team" - /> +;<EditorialReportCard + report={report} + journal={journal} + publicLabel="Message For Author" + privateLabel="Message For Editorial Team" +/> ``` Card with message for the editorial team @@ -102,12 +102,12 @@ const journal = { }, ], } -;<EditorialReportCard - report={report} - journal={journal} - publicLabel="Message For Author" - privateLabel="Message For Editorial Team" - /> +;<EditorialReportCard + report={report} + journal={journal} + publicLabel="Message For Author" + privateLabel="Message For Editorial Team" +/> ``` Card with message for the editorial team and for the author @@ -162,11 +162,10 @@ const journal = { }, ], } - -;<EditorialReportCard - report={report} - journal={journal} - publicLabel="Message For Author" - privateLabel="Message For Editorial Team" - /> +;<EditorialReportCard + report={report} + journal={journal} + publicLabel="Message For Author" + privateLabel="Message For Editorial Team" +/> ``` diff --git a/packages/component-manuscript/src/components/EditorialCommentCard.js b/packages/component-manuscript/src/components/EditorialCommentCard.js index 366200e4fba723bc2c2a7431b4d19b39ea0501b9..f1efbc17760242aff648829f64a6fa27c3584afc 100644 --- a/packages/component-manuscript/src/components/EditorialCommentCard.js +++ b/packages/component-manuscript/src/components/EditorialCommentCard.js @@ -6,7 +6,13 @@ import { withFileDownload, } from 'pubsweet-component-faraday-ui' -const EditorialCommentCard = ({ journal, reports = [], toggle, expanded }) => ( +const EditorialCommentCard = ({ + journal, + reports = [], + toggle, + expanded, + collection, +}) => ( <ContextualBox expanded={expanded} label="Editorial Comments" @@ -16,6 +22,7 @@ const EditorialCommentCard = ({ journal, reports = [], toggle, expanded }) => ( > {reports.map(report => ( <EditorialReportCard + collection={collection} journal={journal} key={report.id} privateLabel="Message For Editorial Team" diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index 6c1cfc840e633a7eb86a685e7b0f7f2316eae15c..44414cf04113d8822ace002256b938b6cc2e46c8 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -83,7 +83,6 @@ const ManuscriptLayout = ({ currentUser={currentUser} editorInChief={editorInChief} fragment={fragment} - handlingEditors={handlingEditors} inviteHE={toggleAssignHE} isFetching={isFetching.editorsFetching} journal={journal} @@ -99,6 +98,7 @@ const ManuscriptLayout = ({ {get(currentUser, 'permissions.canViewEditorialComments', true) && ( <EditorialCommentCard + collection={collection} expanded={heRecommendationExpanded} journal={journal} reports={editorialRecommendations} diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js index 912cab3e23ec4fe707dffe55fe8e41b96d755d9f..3d1ce6f0603c78fd873ae0ee51c5459d88c63f9c 100644 --- a/packages/component-manuscript/src/components/ManuscriptPage.js +++ b/packages/component-manuscript/src/components/ManuscriptPage.js @@ -54,6 +54,7 @@ import { canOverrideTechnicalChecks, getOwnPendingRecommendation, getOwnSubmittedRecommendation, + canAuthorViewEditorialComments, getFragmentReviewerRecommendations, getInvitationsWithReviewersForFragment, } from 'pubsweet-component-faraday-selectors' @@ -179,6 +180,11 @@ export default compose( canEditManuscript: canEditManuscript(state, collection, fragment), canViewReviewersDetails: canViewReviewersDetails(state, collection), canOverrideTechChecks: canOverrideTechnicalChecks(state, collection), + canAuthorViewEditorialComments: canAuthorViewEditorialComments( + state, + collection, + match.params.version, + ), }, }, isFetching: { diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index c97f8b89a8f9acb1b7b626e5fc5b79636889bf65..0d990961263d0d0ff397c1deb7786c6b2e39b2a5 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -7,6 +7,7 @@ const statuses = config.get('statuses') const keysToOmit = ['email', 'id'] const publicStatusesPermissions = ['author', 'reviewer'] const authorAllowedStatuses = ['revisionRequested', 'rejected', 'accepted'] +const authorCanViewHENameStatuses = ['rejected', 'accepted'] const parseAuthorsData = (coll, matchingCollPerm) => { if (['reviewer'].includes(matchingCollPerm.permission)) { @@ -137,13 +138,13 @@ const filterAuthorRecommendations = (recommendations, status, isLast) => { return [] } -const stripeCollectionByRole = (coll = {}, role = '') => { +const stripeCollectionByRole = ({ collection = {}, role = '' }) => { if (role === 'author') { - const { handlingEditor } = coll + const { handlingEditor } = collection - if (!authorAllowedStatuses.includes(coll.status)) { + if (!authorCanViewHENameStatuses.includes(collection.status)) { return { - ...coll, + ...collection, handlingEditor: handlingEditor && handlingEditor.isAccepted && { ...omit(handlingEditor, keysToOmit), @@ -152,7 +153,7 @@ const stripeCollectionByRole = (coll = {}, role = '') => { } } } - return coll + return collection } const stripeFragmentByRole = ({ @@ -246,7 +247,7 @@ const getCollections = async ({ user, models }) => { collection.visibleStatus = get(statuses, `${status}.${up.role}.label`) const stripedColl = stripeCollectionByRole({ - coll: collection, + collection, role: up.role, }) @@ -262,7 +263,7 @@ const getCollections = async ({ user, models }) => { }) } - return { ...stripedColl.coll, visibleStatus } + return { ...stripedColl, visibleStatus } }), )).filter(Boolean) } diff --git a/packages/xpub-faraday/config/authsome-mode.js b/packages/xpub-faraday/config/authsome-mode.js index bf1c2ed4786f543a3777af550122385b83bb21c7..e480663e8f3c835340f53bf92251dd3a679d04d8 100644 --- a/packages/xpub-faraday/config/authsome-mode.js +++ b/packages/xpub-faraday/config/authsome-mode.js @@ -96,10 +96,10 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) { ) } - const parsedCollection = helpers.stripeCollectionByRole( + const parsedCollection = helpers.stripeCollectionByRole({ collection, role, - ) + }) return { ...parsedCollection, diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index 58aa8b2b798660dda269a16c8819a9126adf24c0..606bb666465c1455e78ce9cc9bb3cfb56cadfddb 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -11,7 +11,7 @@ describe('Authsome Helpers', () => { }) it('stripeCollection - should return collection', () => { const { collection } = testFixtures.collections - const result = ah.stripeCollectionByRole(collection) + const result = ah.stripeCollectionByRole({ collection }) expect(result).toBeTruthy() }) it('stripeFragment - should return fragment', () => { @@ -28,7 +28,8 @@ describe('Authsome Helpers', () => { isAccepted: true, } - const result = ah.stripeCollectionByRole(collection, 'author') + const role = 'author' + const result = ah.stripeCollectionByRole({ collection, role }) const { handlingEditor = {} } = result expect(handlingEditor.email).toBeFalsy() @@ -43,7 +44,8 @@ describe('Authsome Helpers', () => { isAccepted: false, } - const result = ah.stripeCollectionByRole(collection, 'author') + const role = 'author' + const result = ah.stripeCollectionByRole({ collection, role }) const { handlingEditor = {} } = result expect(handlingEditor).toBeFalsy() @@ -54,7 +56,8 @@ describe('Authsome Helpers', () => { const { collection } = testFixtures.collections collection.status = 'revisionRequested' - const result = ah.stripeCollectionByRole(collection, 'author') + const role = 'author' + const result = ah.stripeCollectionByRole({ collection, role }) const { handlingEditor = {} } = result expect(handlingEditor.name).not.toEqual('Assigned') @@ -64,7 +67,8 @@ describe('Authsome Helpers', () => { const { collection } = testFixtures.collections collection.status = 'underReview' - const result = ah.stripeCollectionByRole(collection, 'admin') + const role = 'admin' + const result = ah.stripeCollectionByRole({ collection, role }) const { handlingEditor = {} } = result expect(handlingEditor.name).not.toEqual('Assigned') @@ -74,7 +78,8 @@ describe('Authsome Helpers', () => { const { collection } = testFixtures.collections collection.status = 'revisionRequested' - const result = ah.stripeCollectionByRole(collection, 'admin') + const role = 'admin' + const result = ah.stripeCollectionByRole({ collection, role }) const { handlingEditor = {} } = result expect(handlingEditor.name).not.toEqual('Assigned') @@ -84,7 +89,8 @@ describe('Authsome Helpers', () => { const { collection } = testFixtures.collections delete collection.handlingEditor - const result = ah.stripeCollectionByRole(collection, 'admin') + const role = 'admin' + const result = ah.stripeCollectionByRole({ collection, role }) expect(result.handlingEditor).toBeFalsy() })