Skip to content
Snippets Groups Projects
Commit fe24e5ef authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

fix(submission): fix adding author to collection

parent 3c473d14
No related branches found
No related tags found
1 merge request!21Sprint #16 features
......@@ -19,39 +19,26 @@ const generateCustomId = () =>
.toString()
.slice(-7)
const redirectToRoute = (history, route) => {
// redirect after a short delay
window.setTimeout(() => {
history.push(route)
}, 10)
}
export const isRevisionFlow = (state, collection, fragment = {}) =>
collection.fragments.length > 1 && !fragment.submitted
/* actions */
// const addSubmittingAuthor = (user, collectionId, fragmentId) => {
// const author = {
// ...pick(user, ['id', 'email', 'affiliation', 'firstName', 'lastName']),
// isSubmitting: true,
// isCorresponding: true,
// }
// create(`/collections/${collectionId}/fragments/${fragmentId}/users`, {
// role: 'author',
// ...author,
// })
// }
const getAuthors = currentUser => {
if (!currentUser.admin) {
return [
{
...pick(currentUser, [
'id',
'email',
'affiliation',
'firstName',
'lastName',
]),
isSubmitting: true,
isCorresponding: true,
},
]
const addSubmittingAuthor = (user, collectionId, fragmentId) => {
const author = {
...pick(user, ['id', 'email', 'affiliation', 'firstName', 'lastName']),
isSubmitting: true,
isCorresponding: true,
}
return []
return create(`/collections/${collectionId}/fragments/${fragmentId}/users`, {
role: 'author',
...author,
})
}
export const createDraftSubmission = history => (dispatch, getState) => {
......@@ -67,7 +54,6 @@ export const createDraftSubmission = history => (dispatch, getState) => {
return dispatch(
actions.createFragment(collection, {
created: new Date(), // TODO: set on server
authors: getAuthors(currentUser),
collectionId: collection.id,
files: {
manuscripts: [],
......@@ -83,14 +69,13 @@ export const createDraftSubmission = history => (dispatch, getState) => {
throw new Error('Failed to create a project')
}
const route = `/projects/${collection.id}/versions/${fragment.id}/submit`
// if (!currentUser.admin) {
// addSubmittingAuthor(currentUser, collection.id, fragment.id)
// }
// redirect after a short delay
window.setTimeout(() => {
history.push(route)
}, 10)
if (!currentUser.admin) {
addSubmittingAuthor(currentUser, collection.id, fragment.id).then(() =>
redirectToRoute(history, route),
)
} else {
redirectToRoute(history, route)
}
})
})
}
......
......@@ -135,18 +135,11 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
p => p.objectId === object.id || p.objectId === object.collectionId,
)
const collectionId = get(object, 'collectionId')
const {
owners,
status,
fragments,
} = await context.models.Collection.find(collectionId)
if (owners.includes(user.id)) {
return true
}
if (!permission) return false
const collectionId = get(object, 'collectionId')
const { status, fragments } = await context.models.Collection.find(
collectionId,
)
return {
filter: fragment =>
......
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