From 4398573645095a797ff428246bbc7d5566d127ae Mon Sep 17 00:00:00 2001 From: NGPixel Date: Mon, 2 Mar 2020 00:43:19 -0500 Subject: [PATCH] feat: save conflict check polling --- client/components/editor.vue | 34 +++++++++++++++++++++++++++++++ server/controllers/common.js | 3 ++- server/graph/resolvers/page.js | 18 ++++++++++++++++ server/graph/schemas/page.graphql | 5 +++++ server/views/editor.pug | 1 + 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/client/components/editor.vue b/client/components/editor.vue index 5e5bc562..b233a6c9 100644 --- a/client/components/editor.vue +++ b/client/components/editor.vue @@ -13,6 +13,9 @@ full-width ) template(slot='actions') + v-btn.mr-3.animated.fadeIn(color='amber', outlined, small, v-if='isConflict') + .overline.amber--text.mr-3 Conflict + status-indicator(intermediary, pulse) v-btn.animated.fadeInDown( text color='green' @@ -55,9 +58,11 @@ diff --git a/server/controllers/common.js b/server/controllers/common.js index 94805ed8..51217b88 100644 --- a/server/controllers/common.js +++ b/server/controllers/common.js @@ -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 diff --git a/server/graph/resolvers/page.js b/server/graph/resolvers/page.js index 9be541ed..52d36b0c 100644 --- a/server/graph/resolvers/page.js +++ b/server/graph/resolvers/page.js @@ -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: { diff --git a/server/graph/schemas/page.graphql b/server/graph/schemas/page.graphql index 0eb9b319..0ef5f0cb 100644 --- a/server/graph/schemas/page.graphql +++ b/server/graph/schemas/page.graphql @@ -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"]) } # ----------------------------------------------- diff --git a/server/views/editor.pug b/server/views/editor.pug index 38a7f00e..52789404 100644 --- a/server/views/editor.pug +++ b/server/views/editor.pug @@ -17,4 +17,5 @@ block body init-mode=page.mode init-editor=page.editorKey init-content=page.content + checkout-date=page.updatedAt )