Skip to content
Snippets Groups Projects
Commit f9c81784 authored by Giannis Kopanas's avatar Giannis Kopanas
Browse files

Merge branch 'fix-colabra-submit' into 'master'

fix submit form

See merge request xpub/xpub!252
parents 2d5deb4d 8c7caffd
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -517,6 +517,14 @@ class XpubCollabraMode { ...@@ -517,6 +517,14 @@ class XpubCollabraMode {
return false return false
} }
async isAllowedToReview(object) {
this.user = await this.context.models.User.find(this.userId)
const permission = await this.isAssignedReviewerEditor({
id: object.manuscriptId,
})
return permission
}
async canViewMySubmissionSection() { async canViewMySubmissionSection() {
this.user = await this.context.models.User.find(this.userId) this.user = await this.context.models.User.find(this.userId)
const manuscripts = await Promise.all( const manuscripts = await Promise.all(
...@@ -676,10 +684,14 @@ module.exports = { ...@@ -676,10 +684,14 @@ module.exports = {
return user.admin return user.admin
}, },
create: (userId, operation, object, context) => true, create: (userId, operation, object, context) => true,
update: (userId, operation, object, context) => { update: async (userId, operation, object, context) => {
const mode = new XpubCollabraMode(userId, operation, object, context) const mode = new XpubCollabraMode(userId, operation, object, context)
if (mode.object === 'Manuscript' || mode.object === 'Team') { if (
mode.object === 'Manuscript' ||
mode.object === 'Review' ||
mode.object === 'Team'
) {
return true return true
} }
...@@ -687,6 +699,10 @@ module.exports = { ...@@ -687,6 +699,10 @@ module.exports = {
return true return true
} }
if (mode.object.current.type === 'Review') {
return mode.isAllowedToReview(mode.object.current)
}
if (mode.object.current.type === 'Manuscript') { if (mode.object.current.type === 'Manuscript') {
return mode.canUpdateManuscript() return mode.canUpdateManuscript()
} }
...@@ -736,13 +752,17 @@ module.exports = { ...@@ -736,13 +752,17 @@ module.exports = {
return mode.canViewPage() return mode.canViewPage()
}, },
'can view only admin': () => false, 'can view only admin': () => false,
read: (userId, operation, object, context) => { read: async (userId, operation, object, context) => {
const mode = new XpubCollabraMode(userId, operation, object, context) const mode = new XpubCollabraMode(userId, operation, object, context)
if (object === 'Manuscript') { if (object === 'Manuscript' || object === 'Review') {
return true return true
} }
if (object.type === 'Review') {
return mode.isAllowedToReview(object)
}
if (object.type === 'Manuscript') { if (object.type === 'Manuscript') {
return mode.canReadManuscript() return mode.canReadManuscript()
} }
......
...@@ -5,15 +5,20 @@ const resolvers = { ...@@ -5,15 +5,20 @@ const resolvers = {
Mutation: { Mutation: {
async updateReview(_, { id, input }, ctx) { async updateReview(_, { id, input }, ctx) {
if (id) { if (id) {
const review = await Review.find(id) const review = await ctx.connectors.Review.fetchOne(id, ctx)
const update = merge({}, review, input) const update = merge({}, review, input)
const updateReview = await new Review(update).save() await ctx.connectors.Review.update(id, update, ctx)
updateReview.comments = await updateReview.getComments() // Load Review
return updateReview const rvw = await new Review(update)
rvw.comments = await rvw.getComments()
return rvw
} }
input.userId = ctx.user input.userId = ctx.user
const review = await new Review(input).save() const review = await new Review(input)
await review.save()
review.comments = await review.getComments() review.comments = await review.getComments()
return review return review
}, },
}, },
......
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