Skip to content
Snippets Groups Projects
Commit a3c79c26 authored by Audrey Hamelers's avatar Audrey Hamelers
Browse files

recover deleted manuscript (admin)

parent b724ad8f
No related branches found
No related tags found
2 merge requests!110Dev,!109Shared data model
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
GET_MANUSCRIPT, GET_MANUSCRIPT,
UPDATE_MANUSCRIPT, UPDATE_MANUSCRIPT,
DELETE_MANUSCRIPT, DELETE_MANUSCRIPT,
RECOVER_MANUSCRIPT,
} from './operations' } from './operations'
export const ManuscriptMutations = BaseComponent => ({ export const ManuscriptMutations = BaseComponent => ({
...@@ -55,17 +56,35 @@ export const ManuscriptMutations = BaseComponent => ({ ...@@ -55,17 +56,35 @@ export const ManuscriptMutations = BaseComponent => ({
callBack && callBack() callBack && callBack()
} }
return ( return (
<BaseComponent <Mutation
changeCitation={changeCitation} mutation={RECOVER_MANUSCRIPT}
deleteMan={deleteMan} refetchQueries={() => refetch}
manuscript={manuscript}
setStatus={setStatus}
updateEmbargo={updateEmbargo}
updateGrants={updateGrants}
{...props}
> >
{children} {(recoverManuscript, { data }) => {
</BaseComponent> const recoverMan = async callBack => {
await recoverManuscript({
variables: {
id: manuscript.id,
},
})
callBack && callBack()
}
return (
<BaseComponent
changeCitation={changeCitation}
deleteMan={deleteMan}
manuscript={manuscript}
recoverMan={recoverMan}
setStatus={setStatus}
updateEmbargo={updateEmbargo}
updateGrants={updateGrants}
{...props}
>
{children}
</BaseComponent>
)
}}
</Mutation>
) )
}} }}
</Mutation> </Mutation>
......
...@@ -104,7 +104,7 @@ const ParseJson = ({ col, val }) => { ...@@ -104,7 +104,7 @@ const ParseJson = ({ col, val }) => {
case 'title': case 'title':
return <em>{val}</em> return <em>{val}</em>
case 'deleted': case 'deleted':
return 'not deleted' return 'recovered'
case 'article ids': case 'article ids':
return set.map( return set.map(
(p, i) => (p, i) =>
......
...@@ -134,13 +134,17 @@ const MetaEdit = withTheme( ...@@ -134,13 +134,17 @@ const MetaEdit = withTheme(
<H2>Send/Remove</H2> <H2>Send/Remove</H2>
{manuscript.deleted ? ( {manuscript.deleted ? (
<React.Fragment> <React.Fragment>
This manuscript has been deleted <Notification type="info">
{`Manuscript succesfully deleted. If not already sent, please send a message to the user(s) explaining the deletion.`}
</Notification>
<FlexP> <FlexP>
<RouteButton onClick={() => props.deleteMan(close())}> <RouteButton
onClick={() => props.recoverMan(close())}
>
<Icon color="currentColor" size={2.5}> <Icon color="currentColor" size={2.5}>
refresh-cw refresh-cw
</Icon> </Icon>
Reinstate manuscript Recover manuscript
</RouteButton> </RouteButton>
</FlexP> </FlexP>
</React.Fragment> </React.Fragment>
...@@ -190,25 +194,13 @@ const MetaEdit = withTheme( ...@@ -190,25 +194,13 @@ const MetaEdit = withTheme(
</RouteButton> </RouteButton>
<span className="hidden"> <span className="hidden">
{` Are you certain? `} {` Are you certain? `}
<Action <Action onClick={() => props.deleteMan()}>
onClick={e => {
const sec =
e.currentTarget.parentElement.parentElement
.nextElementSibling
props.deleteMan(() =>
sec.classList.remove('hidden'),
)
}}
>
Confirm deletion Confirm deletion
</Action> </Action>
</span> </span>
{curr >= done && {curr >= done &&
' Manuscript has been sent to PMC and must be withdrawn.'} ' Manuscript has been sent to PMC and must be withdrawn.'}
</FlexP> </FlexP>
<Notification className="hidden" type="info">
{`Manuscript succesfully deleted. If not already sent, please send a message to the user(s) explaining the deletion.`}
</Notification>
</React.Fragment> </React.Fragment>
)} )}
<Exit close={close} /> <Exit close={close} />
......
...@@ -158,3 +158,9 @@ export const DELETE_MANUSCRIPT = gql` ...@@ -158,3 +158,9 @@ export const DELETE_MANUSCRIPT = gql`
deleteManuscript(id: $id) deleteManuscript(id: $id)
} }
` `
export const RECOVER_MANUSCRIPT = gql`
mutation RecoverManuscript($id: ID!) {
recoverManuscript(id: $id)
}
`
...@@ -156,11 +156,6 @@ const Manuscript = { ...@@ -156,11 +156,6 @@ const Manuscript = {
try { try {
const manuscript = await ManuscriptAccess.selectById(id) const manuscript = await ManuscriptAccess.selectById(id)
if (manuscript) { if (manuscript) {
if (manuscript.deleted) {
// lodash.assign(manuscript, { deleted: null })
// await manuscript.save()
return true
}
await ManuscriptAccess.delete(id, userId) await ManuscriptAccess.delete(id, userId)
return true return true
} }
...@@ -170,6 +165,16 @@ const Manuscript = { ...@@ -170,6 +165,16 @@ const Manuscript = {
return false return false
} }
}, },
recover: async (id, userId) => {
const manuscript = await ManuscriptAccess.selectById(id)
if (manuscript && manuscript.deleted) {
lodash.assign(manuscript, { deleted: null })
await manuscript.save()
return true
}
logger.error('Nothing to recover')
return false
},
create: async (data, userId, organizationId) => { create: async (data, userId, organizationId) => {
await authorization.can(userId, 'create', { await authorization.can(userId, 'create', {
......
...@@ -87,6 +87,13 @@ const resolvers = { ...@@ -87,6 +87,13 @@ const resolvers = {
return ManuscriptManager.delete(id, user) return ManuscriptManager.delete(id, user)
}, },
async recoverManuscript(_, { id }, { user }) {
if (!user) {
throw new Error('Not logged in')
}
return ManuscriptManager.recover(id, user)
},
async replaceManuscript(_, { keepId, throwId }, { user }) { async replaceManuscript(_, { keepId, throwId }, { user }) {
if (!user) { if (!user) {
throw new Error('Not logged in') throw new Error('Not logged in')
......
...@@ -32,6 +32,7 @@ extend type Query { ...@@ -32,6 +32,7 @@ extend type Query {
extend type Mutation { extend type Mutation {
createManuscript(data: CreateManuscriptInput!): Manuscript! createManuscript(data: CreateManuscriptInput!): Manuscript!
deleteManuscript(id: ID!): Boolean! deleteManuscript(id: ID!): Boolean!
recoverManuscript(id: ID!): Boolean!
replaceManuscript(keepId: ID!, throwId: ID!): Boolean! replaceManuscript(keepId: ID!, throwId: ID!): Boolean!
updateManuscript(data: ManuscriptInput!): Manuscript! updateManuscript(data: ManuscriptInput!): Manuscript!
submitManuscript(data: ManuscriptInput!): ManuscriptResult! submitManuscript(data: ManuscriptInput!): ManuscriptResult!
......
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