Commit f504c840 authored by Giannis Kopanas's avatar Giannis Kopanas

fix(manuscript):delete manuscript

parent 9778b6d5
Pipeline #10449 failed with stages
in 5 minutes and 34 seconds
......@@ -64,6 +64,7 @@ class XpubCollabraMode {
const id = teamId.id ? teamId.id : teamId
const team = await this.context.models.Team.find(id)
if (!team) return [false]
return membershipCondition(team)
}),
)
......@@ -134,7 +135,7 @@ class XpubCollabraMode {
* @returns {boolean}
*/
isAssignedReviewerEditor(object) {
return this.isTeamMember('reviewer', object)
return this.isTeamMember('reviewerEditor', object)
}
/**
......@@ -176,7 +177,7 @@ class XpubCollabraMode {
// return true
// }
let permission = this.checkTeamMembers(
let permission = await this.checkTeamMembers(
[
'isAssignedSeniorEditor',
'isAssignedHandlingEditor',
......@@ -185,26 +186,11 @@ class XpubCollabraMode {
manuscript,
)
// TODO: REMOVE if permision work
// permission = permission
// ? true
// : await this.canReadatLeastOneFragmentOfCollection(manuscript, [
// 'isAssignedReviewerEditor',
// ])
permission = permission ? true : await this.isAuthor(manuscript)
return permission
}
// TODO: REMOVE if permision work
// async canReadatLeastOneFragmentOfCollection(collection, teamMembers) {
// const permission = await Promise.all(
// collection.map(async id => this.checkTeamMembers(teamMembers, { id })),
// )
// return permission.includes(true)
// }
/**
* Checks if a user can list users
*
......@@ -467,7 +453,7 @@ class XpubCollabraMode {
const schemaReviewers = ['id', 'reviewers']
let permission =
(await this.isAuthor(current)) && !current.status === 'submitted'
(await this.isAuthor(current)) && current.status !== 'submitted'
permission = permission
? true
......@@ -511,11 +497,7 @@ class XpubCollabraMode {
this.user = await this.context.models.User.find(this.userId)
const manuscript = this.object
return (
this.isAuthor(manuscript) &&
manuscript.status !== 'submitted' &&
manuscript.status !== 'revising'
)
return this.isAuthor(manuscript) && manuscript.status !== 'submitted'
}
/**
......@@ -693,51 +675,15 @@ module.exports = {
// return false
return user.admin
},
GET: (userId, operation, object, context) => {
const mode = new XpubCollabraMode(userId, operation, object, context)
// GET /api/users
if (mode.object && mode.object.path === '/users') {
return mode.canListUsers()
}
// GET /api/fragments
if (mode.object && mode.object.path === '/fragments') {
return mode.canListFragments()
}
// GET /api/teams
if (mode.object && mode.object.path === '/teams') {
return mode.canListTeams()
}
// GET /api/collection
if (mode.object && mode.object.type === 'manuscript') {
return mode.canReadManuscript()
}
// GET /api/fragment
if (mode.object && mode.object.type === 'fragment') {
return mode.canReadFragment()
}
// GET /api/team
if (object && object.type === 'Team') {
return mode.canReadTeam()
}
// GET /api/user
if (mode.object && mode.object.type === 'user') {
return mode.canReadUser()
}
return false
},
create: (userId, operation, object, context) => true,
update: (userId, operation, object, context) => {
const mode = new XpubCollabraMode(userId, operation, object, context)
if (mode.object === 'Manuscript') {
if (mode.object === 'Manuscript' || mode.object === 'Team') {
return true
}
if (mode.object.current.type === 'team') {
return true
}
......@@ -750,11 +696,6 @@ module.exports = {
return mode.canUpdateUser()
}
// PATCH /api/teams/:id
if (mode.object.current && mode.object.current.type === 'team') {
return mode.canUpdateTeam()
}
return false
},
delete: (userId, operation, object, context) => {
......@@ -765,7 +706,7 @@ module.exports = {
}
if (object === 'Manuscript' || object.type === 'Manuscript') {
return mode.canDeleteManuscript()
return mode.isAuthor(object)
}
if (object === 'Team' || object.type === 'Team') {
......@@ -802,10 +743,13 @@ module.exports = {
read: (userId, operation, object, context) => {
const mode = new XpubCollabraMode(userId, operation, object, context)
if (object === 'Manuscript' || object.type === 'Manuscript') {
return mode.canReadManuscript()
if (object === 'Manuscript') {
return true
}
if (object.type === 'Manuscript') {
return mode.canReadManuscript()
}
if (object.type === 'team' || object === 'Team') {
return mode.canReadTeam()
}
......
// const { Team, User } = require('pubsweet-server')
// const clone = require('lodash/clone')
// const merge = require('lodash/merge')
// const union = require('lodash/union')
const Journal = require('./journal')
const Manuscript = require('../../manuscript/src/manuscript')
......@@ -30,105 +25,6 @@ const resolvers = {
)
return journal
},
// async dashboardArticles(_, { currentUserId }, context) {
// const { connectors } = context
// const articles = await Journal.all()
// const currentUser = await User.find(currentUserId)
// const teams = await Team.all()
// const globalTeams = teams.filter(t => t.global)
// const isGlobal = isUserInGlobalTeams(globalTeams, currentUser)
// const data = {
// author: [],
// editor: [],
// isGlobal,
// }
// articles.forEach(article => {
// const articleCopy = clone(article)
// const articleTeams = teams.filter(
// t => t.object && t.object.objectId === article.id,
// )
// /* Create reviewer status */
// const invitedTeam = articleTeams.find(
// t => t.teamType === 'reviewersInvited',
// )
// const acceptedTeam = articleTeams.find(
// t => t.teamType === 'reviewersAccepted',
// )
// const submittedReview = reviews.find(
// r => r.articleVersionId === article.id && r.status.submitted,
// )
// const reviewerStatus = clone(cleanReviewStatus)
// if (invitedTeam && invitedTeam.members.length > 0)
// reviewerStatus.invited = true
// if (acceptedTeam && acceptedTeam.members.length > 0)
// reviewerStatus.accepted = true
// if (submittedReview) reviewerStatus.submitted = true
// /* End create reviewer status */
// articleCopy.status = {
// ...articleCopy.status,
// reviewers: reviewerStatus,
// }
// // User is author of article
// const authorTeam = articleTeams.find(t => t.teamType === 'author')
// if (isMember(authorTeam, currentUserId)) {
// data.author.push({ ...articleCopy })
// }
// // User is an editor or science officer
// if (isGlobal && article.status && article.status.submission.initial) {
// const editorTeam = articleTeams.find(t => t.teamType === 'editor')
// const assignedEditorId = editorTeam.members[0]
// let assignedEditor
// if (assignedEditorId) {
// assignedEditor = connectors.User.fetchOne(assignedEditorId, context)
// }
// data.editor.push({ ...articleCopy, assignedEditor })
// }
// })
// return data
// },
// async globalTeams() {
// let teams
// try {
// teams = await Team.findByField('global', true)
// } catch (e) {
// teams = []
// }
// return teams
// },
// async manuscript(_, { id }) {
// return Manuscript.find(id)
// },
// async manuscripts(_, vars, ctx) {
// return ctx.connectors.Manuscript.fetchAll(ctx)
// },
// async teamsForArticle(_, { id }) {
// let teams
// try {
// teams = await Team.findByField('object.objectId', id)
// } catch (e) {
// teams = []
// }
// return teams
// },
},
}
......
......@@ -121,7 +121,13 @@ class Manuscript extends BaseModel {
async createNewVersion() {
const manuscriptReviews = await this.getReviews()
const manuscriptTeams = await this.getTeams()
const AuthorTeam = manuscriptTeams.find(team => team.teamType === 'author')
const teams = manuscriptTeams.filter(
team =>
team.teamType === 'author' ||
team.teamType === 'seniorEditor' ||
team.teamType === 'handlingEditor',
)
const manuscriptFiles = await File.findByObject({
object: 'Manuscript',
object_id: this.id,
......@@ -142,9 +148,18 @@ class Manuscript extends BaseModel {
dataManuscript.parentId = this.parentId || this.id
const newManuscript = await dataManuscript.save()
AuthorTeam.object.objectId = newManuscript.id
await new Team(omit(AuthorTeam, ['id', 'role', 'objectType'])).save()
if (teams.length > 0) {
// Copy Teams to the new Version
await Promise.all(
teams.map(async team => {
team.object.objectId = newManuscript.id
await new Team(omit(team, ['id', 'role', 'objectType'])).save()
}),
)
}
// Copy Files to the new Version
await Promise.all(
manuscriptFiles.map(async file => {
const newFile = omit(file, ['id'])
......
......@@ -65,7 +65,7 @@ const resolvers = {
manuscript.parentId,
)
parentManuscripts.forEach(manuscirpt => {
parentManuscripts.forEach(manuscript => {
deleteManuscript.push(manuscript.id)
})
}
......@@ -119,9 +119,11 @@ const resolvers = {
async submitManuscript(_, { id, input }, ctx) {
const data = JSON.parse(input)
const manuscript = await ctx.connectors.Manuscript.fetchOne(id, ctx)
const update = merge({}, manuscript, data)
const previousVersion = await new Manuscript(update).createNewVersion()
const manuscriptVersion = await previousVersion.save()
return manuscriptVersion
},
......
Markdown is supported
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