diff --git a/packages/component-faraday-ui/src/ManuscriptCard.js b/packages/component-faraday-ui/src/ManuscriptCard.js index 252281852a4b69e74d461504bb64de8242e1c6af..fb471ea96a51267573dcf00e32d8fe422379b18d 100644 --- a/packages/component-faraday-ui/src/ManuscriptCard.js +++ b/packages/component-faraday-ui/src/ManuscriptCard.js @@ -76,7 +76,7 @@ const ManuscriptCard = ({ <Row alignItems="center" justify="flex-start" mb={1}> <H4>Handling editor</H4> <Text ml={1} mr={3} whiteSpace="nowrap"> - {get(handlingEditor, 'name', 'Assigned')} + {get(handlingEditor, 'name', 'Undefined')} </Text> {canViewReports && ( <Fragment> diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index 81f6466321cd4cea33a47fa28c3c18cdb75b6365..08e583c721fa6103de2f4729e0f2e64a348567a7 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -80,7 +80,7 @@ const stripeCollectionByRole = ({ collection = {}, role = '' }) => { return { ...collection, handlingEditor: handlingEditor && - handlingEditor.isAccepted && { + !handlingEditor.isAccepted && { ...omit(handlingEditor, keysToOmit), name: 'Assigned', }, @@ -161,23 +161,23 @@ const getCollections = async ({ user, models }) => { const userPermisssions = await getUserPermissions({ user, Team: models.Team }) const collections = (await Promise.all( - userPermisssions.map(async up => { + userPermisssions.map(async userPermission => { let fragment = {} let collection = {} try { - if (up.objectType === 'collection') { - collection = await models.Collection.find(up.objectId) + if (userPermission.objectType === 'collection') { + collection = await models.Collection.find(userPermission.objectId) const latestFragmentId = collection.fragments[collection.fragments.length - 1] collection.currentVersion = await models.Fragment.find( latestFragmentId, ) } else { - fragment = await models.Fragment.find(up.objectId) + fragment = await models.Fragment.find(userPermission.objectId) collection = await models.Collection.find(fragment.collectionId) collection.currentVersion = stripeFragmentByRole({ fragment, - role: up.role, + role: userPermission.role, user, }) } @@ -186,9 +186,12 @@ const getCollections = async ({ user, models }) => { return null } const status = get(collection, 'status', 'draft') - collection.visibleStatus = get(statuses, `${status}.${up.role}.label`) + collection.visibleStatus = get( + statuses, + `${status}.${userPermission.role}.label`, + ) - const role = get(up, 'role', 'author') + const role = get(userPermission, 'role', 'author') const parsedStatuses = await setCollectionStatus({ role, user, @@ -197,7 +200,7 @@ const getCollections = async ({ user, models }) => { }) const stripedColl = stripeCollectionByRole({ collection, - role: up.role, + role: userPermission.role, }) return { @@ -299,5 +302,6 @@ module.exports = { setCollectionStatus, stripeFragmentByRole, getTeamsByPermissions, + stripeCollectionByRole, hasPermissionForObject, } diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index a15e1f9852337441114611dcc2a0e426bf904c5c..c5634168fdf6ab29134874c7c3fa9ee96183b2d0 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -10,6 +10,91 @@ describe('Authsome Helpers', () => { models = fixturesService.Model.build(testFixtures) }) + describe('stripeCollectionByRole', () => { + it('should return a collection', () => { + const { collection } = testFixtures.collections + const newCollection = ah.stripeCollectionByRole({ + collection, + }) + expect(newCollection).toBeTruthy() + }) + + it('Author should not see HE name on dashboard before HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: false, + } + collection.status = 'heInvited' + const role = 'author' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + + expect(handlingEditor.email).toBeFalsy() + expect(handlingEditor.name).toEqual('Assigned') + }) + + it('EIC and Admin should see HE name before HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: false, + } + collection.status = 'heInvited' + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.email).toBeTruthy() + expect(handlingEditor.name).not.toEqual('Assigned') + }) + + it('EIC and Admin should see HE name after HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: true, + } + collection.status = 'heAssigned' + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.email).toBeTruthy() + expect(handlingEditor.name).not.toEqual('Assigned') + }) + + it('Atuhor should see HE name on dashboard after HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: true, + } + collection.status = 'heAssigned' + const role = 'author' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + 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 newCollection = ah.stripeCollectionByRole({ collection, role }) + expect(newCollection.handlingEditor).toBeFalsy() + }) + }) + describe('stripeFragmentByRole', () => { it('reviewer should not see authors email', () => { const { fragment } = testFixtures.fragments