From fb1490f0f21957f3abe7f6baf609ee7b67aaefda Mon Sep 17 00:00:00 2001 From: Leangseu Kim Date: Sun, 29 Jan 2023 21:43:55 -0500 Subject: [PATCH] feat: add singleByPath GraphQL resolver (#6011) Co-authored-by: k k --- server/graph/resolvers/page.js | 24 ++++++++++++++++++++++++ server/graph/schemas/page.graphql | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/server/graph/resolvers/page.js b/server/graph/resolvers/page.js index 15631a18a8..9e99686ad6 100644 --- a/server/graph/resolvers/page.js +++ b/server/graph/resolvers/page.js @@ -170,6 +170,30 @@ module.exports = { throw new WIKI.Error.PageNotFound() } }, + async singleByPath(obj, args, context, info) { + let page = await WIKI.models.pages.getPageFromDb({ + path: args.path, + locale: args.locale, + }); + if (page) { + if (WIKI.auth.checkAccess(context.req.user, ['manage:pages', 'delete:pages'], { + path: page.path, + locale: page.localeCode + })) { + return { + ...page, + locale: page.localeCode, + editor: page.editorKey, + scriptJs: page.extra.js, + scriptCss: page.extra.css + } + } else { + throw new WIKI.Error.PageViewForbidden() + } + } else { + throw new WIKI.Error.PageNotFound() + } + }, /** * FETCH TAGS */ diff --git a/server/graph/schemas/page.graphql b/server/graph/schemas/page.graphql index 10eebc8560..552ad32586 100644 --- a/server/graph/schemas/page.graphql +++ b/server/graph/schemas/page.graphql @@ -46,6 +46,11 @@ type PageQuery { id: Int! ): Page @auth(requires: ["read:pages", "manage:system"]) + singleByPath( + path: String! + locale: String! + ): Page @auth(requires: ["read:pages", "manage:system"]) + tags: [PageTag]! @auth(requires: ["manage:system", "read:pages"]) searchTags(