feat: save conflict resolution

This commit is contained in:
NGPixel
2020-03-21 19:18:08 -04:00
parent bacbe4f543
commit 4b0e3d1c43
12 changed files with 400 additions and 31 deletions

View File

@@ -139,7 +139,7 @@ module.exports = {
async single (obj, args, context, info) {
let page = await WIKI.models.pages.getPageFromDb(args.id)
if (page) {
if (WIKI.auth.checkAccess(context.req.user, ['read:history'], {
if (WIKI.auth.checkAccess(context.req.user, ['manage:pages', 'delete:pages'], {
path: page.path,
locale: page.localeCode
})) {
@@ -263,13 +263,35 @@ module.exports = {
path: page.path,
locale: page.localeCode
})) {
return page.updatedAt !== args.checkoutDate
return page.updatedAt > args.checkoutDate
} else {
throw new WIKI.Error.PageUpdateForbidden()
}
} else {
throw new WIKI.Error.PageNotFound()
}
},
/**
* FETCH LATEST VERSION FOR CONFLICT COMPARISON
*/
async conflictLatest (obj, args, context, info) {
let page = await WIKI.models.pages.getPageFromDb(args.id)
if (page) {
if (WIKI.auth.checkAccess(context.req.user, ['write:pages', 'manage:pages'], {
path: page.path,
locale: page.localeCode
})) {
return {
...page,
tags: page.tags.map(t => t.tag),
locale: page.localeCode
}
} else {
throw new WIKI.Error.PageViewForbidden()
}
} else {
throw new WIKI.Error.PageNotFound()
}
}
},
PageMutation: {

View File

@@ -66,6 +66,10 @@ type PageQuery {
id: Int!
checkoutDate: Date!
): Boolean! @auth(requires: ["write:pages", "manage:pages", "manage:system"])
conflictLatest(
id: Int!
): PageConflictLatest! @auth(requires: ["write:pages", "manage:pages", "manage:system"])
}
# -----------------------------------------------
@@ -277,6 +281,21 @@ type PageLinkItem {
links: [String]!
}
type PageConflictLatest {
id: Int!
authorId: String!
authorName: String!
content: String!
createdAt: Date!
description: String!
isPublished: Boolean!
locale: String!
path: String!
tags: [String]
title: String!
updatedAt: Date!
}
enum PageOrderBy {
CREATED
ID