Skip to content

Commit

Permalink
feat: add singleByPath GraphQL resolver (#6011)
Browse files Browse the repository at this point in the history
Co-authored-by: k k <kleangseu@yahoo.com>
  • Loading branch information
leangseu and k k committed Jan 30, 2023
1 parent 1da80ea commit 0d914b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions server/graph/resolvers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions server/graph/schemas/page.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0d914b0

Please sign in to comment.