diff --git a/packages/component-faraday-ui/src/EditorialReportCard.js b/packages/component-faraday-ui/src/EditorialReportCard.js index 9f326c34063697f2aa29ed40f35047d22e86f605..1f394ee94dd7a7af80267eadfc9e59aeb07161b1 100644 --- a/packages/component-faraday-ui/src/EditorialReportCard.js +++ b/packages/component-faraday-ui/src/EditorialReportCard.js @@ -69,13 +69,13 @@ const EditorialReportCard = ({ export default compose( withHandlers({ - getReviewerRole: ({ report }) => () => { + getEditorRole: ({ report }) => () => { if (get(report, 'reviewer.handlingEditor')) { return 'HE' } return get(report, 'reviewer.editorInChief') ? 'EiC' : '' }, - getReviewerName: ({ report }) => () => + getEditorName: ({ report }) => () => `${get(report, 'reviewer.firstName', '')} ${get( report, 'reviewer.lastName', @@ -96,8 +96,8 @@ export default compose( withProps( ({ report, - getReviewerRole, - getReviewerName, + getEditorRole, + getEditorName, getHandlingEditorName, getRecommendationLabel, }) => ({ @@ -105,8 +105,8 @@ export default compose( publicReport: getReportComments({ report, isPublic: true }), privateReport: getReportComments({ report, isPublic: false }), handlingEditorName: getHandlingEditorName(), - editorName: getReviewerName(), - editorRole: getReviewerRole(), + editorName: getEditorName(), + editorRole: getEditorRole(), }), ), )(EditorialReportCard) diff --git a/packages/component-faraday-ui/src/contextualBoxes/AuthorReviews.js b/packages/component-faraday-ui/src/contextualBoxes/AuthorReviews.js index 447a7614b1a06bf362b4d03db9d0d4a6244a571e..1bd5ca285bd9e16c2af76402abe6689c3bf2738a 100644 --- a/packages/component-faraday-ui/src/contextualBoxes/AuthorReviews.js +++ b/packages/component-faraday-ui/src/contextualBoxes/AuthorReviews.js @@ -16,7 +16,7 @@ const SubmittedReportsNumberForAuthorReviews = ({ reports }) => ( ) const AuthorReviews = ({ invitations, journal, reports, fragment }) => - reports.length && ( + reports.length > 0 && ( <ContextualBox label="Review Reports" rightChildren={ diff --git a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js index 70c2afdd45b6ddaf6027801ad72a21902afed42c..b7e6f5389f196f87344e2b5f35a2f0630117c644 100644 --- a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js +++ b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js @@ -22,7 +22,7 @@ const ManuscriptHeader = ({ fragment = {}, manuscriptType = {}, editorInChief = 'Unassigned', - collection: { visibleStatus = 'Draft', customId }, + collection: { visibleStatus = 'Draft', customId, handlingEditor }, }) => { const { authors = [], metadata = {}, submitted = null } = fragment const { title = 'No title', journal = '', type = '' } = metadata @@ -116,18 +116,25 @@ export default compose( revokeInvitation, pendingInvitation = {}, handlingEditors = [], - currentUser: { permissions: { canAssignHE }, id: currentUserId }, + currentUser: { + permissions: { canAssignHE }, + id: currentUserId, + admin, + editorInChief, + }, collection: { handlingEditor }, + currentUser, }) => () => { if (pendingInvitation.userId === currentUserId) { return <Text ml={1}>Invited</Text> } - if (pendingInvitation.userId) { + if (pendingInvitation.userId && (admin || editorInChief)) { const person = chain(handlingEditors) .filter(he => he.id === pendingInvitation.userId) .map(he => ({ ...he, name: `${he.firstName} ${he.lastName}` })) .first() .value() + return ( <PersonInvitation isFetching={isFetching} @@ -140,6 +147,7 @@ export default compose( /> ) } + if (heInvitation) { return <Text ml={1}>{handlingEditor.name}</Text> } diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index f78aac588a8a3e8afccf1252e70fdb14e22d6919..ff0edc3b07796666fa8a85ea258a9f14b88decf8 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -76,12 +76,12 @@ const ManuscriptLayout = ({ getSignedUrl={getSignedUrl} history={history} /> - <ManuscriptHeader collection={collection} currentUser={currentUser} editorInChief={editorInChief} fragment={fragment} + handlingEditors={handlingEditors} inviteHE={toggleAssignHE} isFetching={isFetching.editorsFetching} journal={journal} diff --git a/packages/component-manuscript/src/redux/editors.js b/packages/component-manuscript/src/redux/editors.js index ffe5ac1f4fd9382d1899270f2d419b7701528055..e28c0dd29ff392776fa2092639ec8fceda19026a 100644 --- a/packages/component-manuscript/src/redux/editors.js +++ b/packages/component-manuscript/src/redux/editors.js @@ -43,22 +43,11 @@ export const getHandlingEditors = () => dispatch => dispatch(setHandlingEditors(res.users)), ) -export const assignHandlingEditor = ({ email, collectionId }) => dispatch => { - dispatch(editorsRequest()) - return create(`/collections/${collectionId}/invitations`, { +export const assignHandlingEditor = ({ email, collectionId }) => + create(`/collections/${collectionId}/invitations`, { email, role: 'handlingEditor', - }).then( - res => { - dispatch(editorsDone()) - return res - }, - err => { - dispatch(editorsDone()) - throw err - }, - ) -} + }) export const revokeHandlingEditor = ({ invitationId, diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index c962ebd7c50c2c70c4a60e310368f00e089682c2..1f885f1b2d421e5fd996f2c37de90f2ba8aa659d 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -4,10 +4,8 @@ const logger = require('@pubsweet/logger') 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)) { @@ -138,24 +136,6 @@ const filterAuthorRecommendations = (recommendations, status, isLast) => { return [] } -const stripeCollectionByRole = ({ collection = {}, role = '' }) => { - if (role === 'author') { - const { handlingEditor } = collection - - if (!authorCanViewHENameStatuses.includes(collection.status)) { - return { - ...collection, - handlingEditor: handlingEditor && - handlingEditor.isAccepted && { - ...omit(handlingEditor, keysToOmit), - name: 'Assigned', - }, - } - } - } - return collection -} - const stripeFragmentByRole = ({ fragment = {}, role = '', @@ -255,11 +235,6 @@ const getCollections = async ({ user, models }) => { const status = get(collection, 'status', 'draft') collection.visibleStatus = get(statuses, `${status}.${up.role}.label`) - const stripedColl = stripeCollectionByRole({ - collection, - role: up.role, - }) - const role = get(up, 'role', 'author') let visibleStatus = get(statuses, `${status}.${role}.label`) @@ -272,7 +247,7 @@ const getCollections = async ({ user, models }) => { }) } - return { ...stripedColl, visibleStatus } + return { ...collection, visibleStatus } }), )).filter(Boolean) } @@ -316,7 +291,6 @@ module.exports = { hasPermissionForObject, isInDraft, hasFragmentInDraft, - stripeCollectionByRole, stripeFragmentByRole, getUsersList, parseUser, diff --git a/packages/xpub-faraday/config/authsome-mode.js b/packages/xpub-faraday/config/authsome-mode.js index e480663e8f3c835340f53bf92251dd3a679d04d8..7b269f3855277ae6aea96a9afca4043f647af6f2 100644 --- a/packages/xpub-faraday/config/authsome-mode.js +++ b/packages/xpub-faraday/config/authsome-mode.js @@ -96,13 +96,8 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) { ) } - const parsedCollection = helpers.stripeCollectionByRole({ - collection, - role, - }) - return { - ...parsedCollection, + ...collection, visibleStatus, } }, diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index ced5b1e955140c07bfa275ae1736d1e34edc909a..0e51ce6aed419d58cda2bf016f2bbc09d821e8b5 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -9,90 +9,6 @@ describe('Authsome Helpers', () => { testFixtures = cloneDeep(fixturesService.fixtures) models = fixturesService.Model.build(testFixtures) }) - it('stripeCollection - should return collection', () => { - const { collection } = testFixtures.collections - const result = ah.stripeCollectionByRole({ collection }) - expect(result).toBeTruthy() - }) - it('stripeFragment - should return fragment', () => { - const { fragment } = testFixtures.fragments - const result = ah.stripeFragmentByRole({ fragment }) - expect(result).toBeTruthy() - }) - - it('stripeCollection - author should not see accepted HE name before recommendation made', () => { - const { collection } = testFixtures.collections - collection.status = 'underReview' - collection.handlingEditor = { - ...collection.handlingEditor, - isAccepted: true, - } - - const role = 'author' - const result = ah.stripeCollectionByRole({ collection, role }) - const { handlingEditor = {} } = result - - expect(handlingEditor.email).toBeFalsy() - expect(handlingEditor.name).toEqual('Assigned') - }) - - it('stripeCollection - author should not see Assigned until HE accepted ', () => { - const { collection } = testFixtures.collections - collection.status = 'underReview' - collection.handlingEditor = { - ...collection.handlingEditor, - isAccepted: false, - } - - const role = 'author' - const result = ah.stripeCollectionByRole({ collection, role }) - const { handlingEditor = {} } = result - - expect(handlingEditor).toBeFalsy() - expect(handlingEditor.name).not.toEqual('Assigned') - }) - - it('stripeCollection - author should see HE name after recommendation made', () => { - const { collection } = testFixtures.collections - collection.status = 'revisionRequested' - - const role = 'author' - const result = ah.stripeCollectionByRole({ collection, role }) - const { handlingEditor = {} } = result - - expect(handlingEditor.name).not.toEqual('Assigned') - }) - - it('stripeCollection - other user than author should see HE name before recommendation made', () => { - const { collection } = testFixtures.collections - collection.status = 'underReview' - - const role = 'admin' - const result = ah.stripeCollectionByRole({ collection, role }) - const { handlingEditor = {} } = result - - expect(handlingEditor.name).not.toEqual('Assigned') - }) - - it('stripeCollection - other user than author should see HE name after recommendation made', () => { - const { collection } = testFixtures.collections - collection.status = 'revisionRequested' - - const role = 'admin' - const result = ah.stripeCollectionByRole({ collection, role }) - const { handlingEditor = {} } = result - - expect(handlingEditor.name).not.toEqual('Assigned') - }) - - it('stripeCollection - returns if collection does not have HE', () => { - const { collection } = testFixtures.collections - delete collection.handlingEditor - - const role = 'admin' - const result = ah.stripeCollectionByRole({ collection, role }) - expect(result.handlingEditor).toBeFalsy() - }) describe('stripeFragmentByRole', () => { it('reviewer should not see authors email', () => {