Skip to content
Snippets Groups Projects
Commit 13aad509 authored by Tania Fecheta's avatar Tania Fecheta
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into HIN-1132

parents f908d127 bbce4b59
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!156Develop,!154Hin 1132
...@@ -76,7 +76,7 @@ const ManuscriptCard = ({ ...@@ -76,7 +76,7 @@ const ManuscriptCard = ({
<Row alignItems="center" justify="flex-start" mb={1}> <Row alignItems="center" justify="flex-start" mb={1}>
<H4>Handling editor</H4> <H4>Handling editor</H4>
<Text ml={1} mr={3} whiteSpace="nowrap"> <Text ml={1} mr={3} whiteSpace="nowrap">
{get(handlingEditor, 'name', 'Unassigned')} {get(handlingEditor, 'name', 'Undefined')}
</Text> </Text>
{canViewReports && ( {canViewReports && (
<Fragment> <Fragment>
......
...@@ -170,7 +170,7 @@ export default compose( ...@@ -170,7 +170,7 @@ export default compose(
</Button> </Button>
) )
} }
return <Text ml={1}>Unassigned</Text> return <Text ml={1}>Assigned</Text>
}, },
}), }),
setDisplayName('ManuscriptHeader'), setDisplayName('ManuscriptHeader'),
......
...@@ -120,6 +120,27 @@ const fragments = { ...@@ -120,6 +120,27 @@ const fragments = {
createdOn: chance.timestamp(), createdOn: chance.timestamp(),
updatedOn: chance.timestamp(), updatedOn: chance.timestamp(),
}, },
{
recommendation: 'reject',
recommendationType: 'review',
comments: [
{
content: 'This is not submitted yet',
public: true,
files: [
{
id: chance.guid(),
name: 'file.pdf',
size: chance.natural(),
},
],
},
],
id: chance.guid(),
userId: reviewer.id,
createdOn: chance.timestamp(),
updatedOn: chance.timestamp(),
},
], ],
authors: [ authors: [
{ {
......
...@@ -158,47 +158,54 @@ class Fragment { ...@@ -158,47 +158,54 @@ class Fragment {
} = this.fragment } = this.fragment
const revAndEditorData = await Promise.all( const revAndEditorData = await Promise.all(
recommendations.map(async rec => { recommendations
const user = await UserModel.find(rec.userId) .filter(
let assignmentDate, isReviewer rec =>
rec.recommendationType === configRecommendations.type.editor ||
if (rec.recommendationType === configRecommendations.type.editor) { (rec.recommendationType === configRecommendations.type.review &&
if (!collection.handlingEditor) { rec.submittedOn),
throw new Error( )
`Collection ${collection.id} does not have a Handling Editor`, .map(async rec => {
) const user = await UserModel.find(rec.userId)
} let assignmentDate, isReviewer
if (user.id === collection.handlingEditor.id) {
const editorInvitation = collection.invitations.find( if (rec.recommendationType === configRecommendations.type.editor) {
if (!collection.handlingEditor) {
throw new Error(
`Collection ${collection.id} does not have a Handling Editor`,
)
}
if (user.id === collection.handlingEditor.id) {
const editorInvitation = collection.invitations.find(
inv => inv.userId === user.id,
)
assignmentDate = editorInvitation.respondedOn
} else {
assignmentDate = submitted
}
isReviewer = false
} else {
const reviewerInvitation = invitations.find(
inv => inv.userId === user.id, inv => inv.userId === user.id,
) )
assignmentDate = editorInvitation.respondedOn assignmentDate = reviewerInvitation.respondedOn
} else { isReviewer = true
assignmentDate = submitted
} }
isReviewer = false return {
} else { isReviewer,
const reviewerInvitation = invitations.find( assignmentDate,
inv => inv.userId === user.id, email: user.email,
) title: user.title,
assignmentDate = reviewerInvitation.respondedOn recommendation: rec,
isReviewer = true country: user.country,
} lastName: user.lastName,
firstName: user.firstName,
return { affiliation: user.affiliation,
isReviewer, submissionDate: rec.createdOn,
assignmentDate, }
email: user.email, }),
title: user.title,
recommendation: rec,
country: user.country,
lastName: user.lastName,
firstName: user.firstName,
affiliation: user.affiliation,
submissionDate: rec.createdOn,
}
}),
) )
return revAndEditorData return revAndEditorData
......
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
process.env.SUPPRESS_NO_CONFIG_WARNING = true process.env.SUPPRESS_NO_CONFIG_WARNING = true
const Chance = require('chance')
const config = require('config')
const { cloneDeep } = require('lodash') const { cloneDeep } = require('lodash')
const fixturesService = require('pubsweet-component-fixture-service') const fixturesService = require('pubsweet-component-fixture-service')
const Chance = require('chance')
const chance = new Chance() const chance = new Chance()
const { fixtures, Model } = fixturesService const { fixtures, Model } = fixturesService
const { Fragment } = require('../Helper') const { Fragment } = require('../Helper')
const { recommendations: configRecommendations } = config
const acceptedReviewerId = chance.guid() const acceptedReviewerId = chance.guid()
const submittedReviewerId1 = chance.guid() const submittedReviewerId1 = chance.guid()
const submittedReviewerId2 = chance.guid() const submittedReviewerId2 = chance.guid()
...@@ -240,7 +243,7 @@ describe('Fragment helper', () => { ...@@ -240,7 +243,7 @@ describe('Fragment helper', () => {
}) })
}) })
describe('getReviewersAndEditorsData', () => { describe('getReviewersAndEditorsData', () => {
it('should return an array of users (reviewers, editors) that have a connection with the fragment', async () => { it('should return an array of users (reviewers, editors) that have submitted a review', async () => {
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments const { fragment } = testFixtures.fragments
const fragmentHelper = new Fragment({ fragment }) const fragmentHelper = new Fragment({ fragment })
...@@ -251,7 +254,14 @@ describe('Fragment helper', () => { ...@@ -251,7 +254,14 @@ describe('Fragment helper', () => {
}) })
expect(fragmentUsers.length).toBeGreaterThan(0) expect(fragmentUsers.length).toBeGreaterThan(0)
expect(fragmentUsers).toHaveLength(fragment.recommendations.length) const submittedRecommendations = fragment.recommendations.filter(
rec =>
rec.recommendationType === configRecommendations.type.editor ||
(rec.recommendationType === configRecommendations.type.review &&
rec.submittedOn),
)
expect(fragmentUsers).toHaveLength(submittedRecommendations.length)
}) })
it('should return an error when the collection does not have a handling editor', async () => { it('should return an error when the collection does not have a handling editor', async () => {
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
......
...@@ -4,6 +4,8 @@ const { omit, get, last, chain } = require('lodash') ...@@ -4,6 +4,8 @@ const { omit, get, last, chain } = require('lodash')
const statuses = config.get('statuses') const statuses = config.get('statuses')
const keysToOmit = [`email`, `id`]
const authorCannotViewHENameStatuses = ['heInvited']
const authorAllowedStatuses = ['revisionRequested', 'rejected', 'accepted'] const authorAllowedStatuses = ['revisionRequested', 'rejected', 'accepted']
const getTeamsByPermissions = async ( const getTeamsByPermissions = async (
...@@ -70,6 +72,23 @@ const filterAuthorRecommendations = (recommendations, status, isLast) => { ...@@ -70,6 +72,23 @@ const filterAuthorRecommendations = (recommendations, status, isLast) => {
return [] return []
} }
const stripeCollectionByRole = ({ collection = {}, role = '' }) => {
if (role === 'author') {
const { handlingEditor } = collection
if (authorCannotViewHENameStatuses.includes(collection.status)) {
return {
...collection,
handlingEditor: handlingEditor &&
!handlingEditor.isAccepted && {
...omit(handlingEditor, keysToOmit),
name: 'Assigned',
},
}
}
}
return collection
}
const stripeFragmentByRole = ({ const stripeFragmentByRole = ({
fragment = {}, fragment = {},
role = '', role = '',
...@@ -142,23 +161,23 @@ const getCollections = async ({ user, models }) => { ...@@ -142,23 +161,23 @@ const getCollections = async ({ user, models }) => {
const userPermisssions = await getUserPermissions({ user, Team: models.Team }) const userPermisssions = await getUserPermissions({ user, Team: models.Team })
const collections = (await Promise.all( const collections = (await Promise.all(
userPermisssions.map(async up => { userPermisssions.map(async userPermission => {
let fragment = {} let fragment = {}
let collection = {} let collection = {}
try { try {
if (up.objectType === 'collection') { if (userPermission.objectType === 'collection') {
collection = await models.Collection.find(up.objectId) collection = await models.Collection.find(userPermission.objectId)
const latestFragmentId = const latestFragmentId =
collection.fragments[collection.fragments.length - 1] collection.fragments[collection.fragments.length - 1]
collection.currentVersion = await models.Fragment.find( collection.currentVersion = await models.Fragment.find(
latestFragmentId, latestFragmentId,
) )
} else { } else {
fragment = await models.Fragment.find(up.objectId) fragment = await models.Fragment.find(userPermission.objectId)
collection = await models.Collection.find(fragment.collectionId) collection = await models.Collection.find(fragment.collectionId)
collection.currentVersion = stripeFragmentByRole({ collection.currentVersion = stripeFragmentByRole({
fragment, fragment,
role: up.role, role: userPermission.role,
user, user,
}) })
} }
...@@ -167,17 +186,25 @@ const getCollections = async ({ user, models }) => { ...@@ -167,17 +186,25 @@ const getCollections = async ({ user, models }) => {
return null return null
} }
const status = get(collection, 'status', 'draft') 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({ const parsedStatuses = await setCollectionStatus({
role, role,
user, user,
collection, collection,
FragmentModel: models.Fragment, FragmentModel: models.Fragment,
}) })
const stripedColl = stripeCollectionByRole({
collection,
role: userPermission.role,
})
return { return {
...collection, ...stripedColl,
...parsedStatuses, ...parsedStatuses,
} }
}), }),
...@@ -275,5 +302,6 @@ module.exports = { ...@@ -275,5 +302,6 @@ module.exports = {
setCollectionStatus, setCollectionStatus,
stripeFragmentByRole, stripeFragmentByRole,
getTeamsByPermissions, getTeamsByPermissions,
stripeCollectionByRole,
hasPermissionForObject, hasPermissionForObject,
} }
...@@ -10,6 +10,91 @@ describe('Authsome Helpers', () => { ...@@ -10,6 +10,91 @@ describe('Authsome Helpers', () => {
models = fixturesService.Model.build(testFixtures) 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', () => { describe('stripeFragmentByRole', () => {
it('reviewer should not see authors email', () => { it('reviewer should not see authors email', () => {
const { fragment } = testFixtures.fragments const { fragment } = testFixtures.fragments
......
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment