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