feat: pages admin + path parsing fixes
This commit is contained in:
@@ -28,12 +28,24 @@ router.get('/healthz', (req, res, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Administration
|
||||
*/
|
||||
router.get(['/a', '/a/*'], (req, res, next) => {
|
||||
_.set(res.locals, 'pageMeta.title', 'Admin')
|
||||
res.render('admin')
|
||||
})
|
||||
|
||||
/**
|
||||
* Create/Edit document
|
||||
*/
|
||||
router.get(['/e', '/e/*'], async (req, res, next) => {
|
||||
const pageArgs = pageHelper.parsePath(req.path, { stripExt: true })
|
||||
|
||||
if (WIKI.config.lang.namespacing && !pageArgs.explicitLocale) {
|
||||
return res.redirect(`/e/${pageArgs.locale}/${pageArgs.path}`)
|
||||
}
|
||||
|
||||
_.set(res, 'locals.siteConfig.lang', pageArgs.locale)
|
||||
|
||||
if (pageHelper.isReservedPath(pageArgs.path)) {
|
||||
@@ -75,28 +87,16 @@ router.get(['/e', '/e/*'], async (req, res, next) => {
|
||||
res.render('editor', { page })
|
||||
})
|
||||
|
||||
/**
|
||||
* Administration
|
||||
*/
|
||||
router.get(['/a', '/a/*'], (req, res, next) => {
|
||||
_.set(res.locals, 'pageMeta.title', 'Admin')
|
||||
res.render('admin')
|
||||
})
|
||||
|
||||
/**
|
||||
* Profile
|
||||
*/
|
||||
router.get(['/p', '/p/*'], (req, res, next) => {
|
||||
_.set(res.locals, 'pageMeta.title', 'User Profile')
|
||||
res.render('profile')
|
||||
})
|
||||
|
||||
/**
|
||||
* History
|
||||
*/
|
||||
router.get(['/h', '/h/*'], async (req, res, next) => {
|
||||
const pageArgs = pageHelper.parsePath(req.path, { stripExt: true })
|
||||
|
||||
if (WIKI.config.lang.namespacing && !pageArgs.explicitLocale) {
|
||||
return res.redirect(`/h/${pageArgs.locale}/${pageArgs.path}`)
|
||||
}
|
||||
|
||||
_.set(res, 'locals.siteConfig.lang', pageArgs.locale)
|
||||
|
||||
if (!WIKI.auth.checkAccess(req.user, ['read:pages'], pageArgs)) {
|
||||
@@ -119,12 +119,24 @@ router.get(['/h', '/h/*'], async (req, res, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Profile
|
||||
*/
|
||||
router.get(['/p', '/p/*'], (req, res, next) => {
|
||||
_.set(res.locals, 'pageMeta.title', 'User Profile')
|
||||
res.render('profile')
|
||||
})
|
||||
|
||||
/**
|
||||
* Source
|
||||
*/
|
||||
router.get(['/s', '/s/*'], async (req, res, next) => {
|
||||
const pageArgs = pageHelper.parsePath(req.path, { stripExt: true })
|
||||
|
||||
if (WIKI.config.lang.namespacing && !pageArgs.explicitLocale) {
|
||||
return res.redirect(`/s/${pageArgs.locale}/${pageArgs.path}`)
|
||||
}
|
||||
|
||||
_.set(res, 'locals.siteConfig.lang', pageArgs.locale)
|
||||
|
||||
if (!WIKI.auth.checkAccess(req.user, ['read:pages'], pageArgs)) {
|
||||
@@ -155,6 +167,10 @@ router.get('/*', async (req, res, next) => {
|
||||
const isPage = (stripExt || pageArgs.path.indexOf('.') === -1)
|
||||
|
||||
if (isPage) {
|
||||
if (WIKI.config.lang.namespacing && !pageArgs.explicitLocale) {
|
||||
return res.redirect(`/${pageArgs.locale}/${pageArgs.path}`)
|
||||
}
|
||||
|
||||
if (!WIKI.auth.checkAccess(req.user, ['read:pages'], pageArgs)) {
|
||||
_.set(res.locals, 'pageMeta.title', 'Unauthorized')
|
||||
return res.status(403).render('unauthorized', { action: 'view' })
|
||||
|
@@ -42,6 +42,18 @@ module.exports = {
|
||||
'createdAt',
|
||||
'updatedAt'
|
||||
])
|
||||
},
|
||||
async single (obj, args, context, info) {
|
||||
let page = await WIKI.models.pages.getPageFromDb(args.id)
|
||||
if (page) {
|
||||
return {
|
||||
...page,
|
||||
locale: page.localeCode,
|
||||
editor: page.editorKey
|
||||
}
|
||||
} else {
|
||||
throw new WIKI.Error.PageNotFound()
|
||||
}
|
||||
}
|
||||
},
|
||||
PageMutation: {
|
||||
|
@@ -28,6 +28,10 @@ type PageQuery {
|
||||
): PageSearchResponse! @auth(requires: ["manage:system", "read:pages"])
|
||||
|
||||
list: [PageListItem!]! @auth(requires: ["manage:system"])
|
||||
|
||||
single(
|
||||
id: Int!
|
||||
): Page @auth(requires: ["manage:pages", "delete:pages", "manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@@ -80,6 +84,29 @@ type PageResponse {
|
||||
|
||||
type Page {
|
||||
id: Int!
|
||||
path: String!
|
||||
hash: String!
|
||||
title: String!
|
||||
description: String!
|
||||
isPrivate: Boolean!
|
||||
isPublished: Boolean!
|
||||
privateNS: String
|
||||
publishStartDate: Date!
|
||||
publishEndDate: String!
|
||||
content: String!
|
||||
render: String
|
||||
toc: String
|
||||
contentType: String!
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
editor: String!
|
||||
locale: String!
|
||||
authorId: Int!
|
||||
authorName: String!
|
||||
authorEmail: String!
|
||||
creatorId: Int!
|
||||
creatorName: String!
|
||||
creatorEmail: String!
|
||||
}
|
||||
|
||||
type PageHistory {
|
||||
|
@@ -125,6 +125,10 @@ module.exports = {
|
||||
message: 'Cannot create this page because an entry already exists at the same path.',
|
||||
code: 6002
|
||||
}),
|
||||
PageNotFound: CustomError('PageNotFound', {
|
||||
message: 'This page does not exist.',
|
||||
code: 6003
|
||||
}),
|
||||
SearchActivationFailed: CustomError('SearchActivationFailed', {
|
||||
message: 'Search Engine activation failed.',
|
||||
code: 4002
|
||||
|
@@ -16,7 +16,8 @@ module.exports = {
|
||||
locale: WIKI.config.lang.code,
|
||||
path: 'home',
|
||||
private: false,
|
||||
privateNS: ''
|
||||
privateNS: '',
|
||||
explicitLocale: false
|
||||
}
|
||||
|
||||
// Clean Path
|
||||
@@ -31,6 +32,7 @@ module.exports = {
|
||||
}
|
||||
if (localeSegmentRegex.test(pathParts[0])) {
|
||||
pathObj.locale = pathParts[0]
|
||||
pathObj.explicitLocale = true
|
||||
pathParts.shift()
|
||||
}
|
||||
|
||||
|
@@ -104,6 +104,7 @@ module.exports = async () => {
|
||||
// View accessible data
|
||||
// ----------------------------------------
|
||||
|
||||
app.locals.analyticsCode = {}
|
||||
app.locals.basedir = WIKI.ROOTPATH
|
||||
app.locals.config = WIKI.config
|
||||
app.locals.pageMeta = {
|
||||
|
@@ -350,23 +350,23 @@ module.exports = class Page extends Model {
|
||||
'pages.path': opts.path,
|
||||
'pages.localeCode': opts.locale
|
||||
})
|
||||
.andWhere(builder => {
|
||||
if (queryModeID) return
|
||||
builder.where({
|
||||
'pages.isPublished': true
|
||||
}).orWhere({
|
||||
'pages.isPublished': false,
|
||||
'pages.authorId': opts.userId
|
||||
})
|
||||
})
|
||||
.andWhere(builder => {
|
||||
if (queryModeID) return
|
||||
if (opts.isPrivate) {
|
||||
builder.where({ 'pages.isPrivate': true, 'pages.privateNS': opts.privateNS })
|
||||
} else {
|
||||
builder.where({ 'pages.isPrivate': false })
|
||||
}
|
||||
})
|
||||
// .andWhere(builder => {
|
||||
// if (queryModeID) return
|
||||
// builder.where({
|
||||
// 'pages.isPublished': true
|
||||
// }).orWhere({
|
||||
// 'pages.isPublished': false,
|
||||
// 'pages.authorId': opts.userId
|
||||
// })
|
||||
// })
|
||||
// .andWhere(builder => {
|
||||
// if (queryModeID) return
|
||||
// if (opts.isPrivate) {
|
||||
// builder.where({ 'pages.isPrivate': true, 'pages.privateNS': opts.privateNS })
|
||||
// } else {
|
||||
// builder.where({ 'pages.isPrivate': false })
|
||||
// }
|
||||
// })
|
||||
.first()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user