feat: save conflict check polling

This commit is contained in:
NGPixel
2020-03-02 00:43:19 -05:00
parent 6890d9e04e
commit 4398573645
5 changed files with 60 additions and 1 deletions

View File

@@ -147,7 +147,8 @@ router.get(['/e', '/e/*'], async (req, res, next) => {
mode: 'create',
content: null,
title: null,
description: null
description: null,
updatedAt: new Date().toISOString()
}
// -> From Template

View File

@@ -252,6 +252,24 @@ module.exports = {
}
return result
}, [])
},
/**
* CHECK FOR EDITING CONFLICT
*/
async checkConflicts (obj, args, context, info) {
let page = await WIKI.models.pages.query().select('path', 'localeCode', 'updatedAt').findById(args.id)
if (page) {
if (WIKI.auth.checkAccess(context.req.user, ['write:pages', 'manage:pages'], {
path: page.path,
locale: page.localeCode
})) {
return page.updatedAt !== args.checkoutDate
} else {
throw new WIKI.Error.PageUpdateForbidden()
}
} else {
throw new WIKI.Error.PageNotFound()
}
}
},
PageMutation: {

View File

@@ -61,6 +61,11 @@ type PageQuery {
links(
locale: String!
): [PageLinkItem] @auth(requires: ["manage:system", "read:pages"])
checkConflicts(
id: Int!
checkoutDate: Date!
): Boolean! @auth(requires: ["write:pages", "manage:pages", "manage:system"])
}
# -----------------------------------------------

View File

@@ -17,4 +17,5 @@ block body
init-mode=page.mode
init-editor=page.editorKey
init-content=page.content
checkout-date=page.updatedAt
)