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