feat: sidebar item permissions + admin nav edit
This commit is contained in:
@@ -25,7 +25,7 @@ const bruteforce = new ExpressBrute(new BruteKnex({
|
||||
router.get('/login', async (req, res, next) => {
|
||||
_.set(res.locals, 'pageMeta.title', 'Login')
|
||||
|
||||
if (req.query.legacy || req.get('user-agent').indexOf('Trident') >= 0) {
|
||||
if (req.query.legacy || (req.get('user-agent') && req.get('user-agent').indexOf('Trident') >= 0)) {
|
||||
const { formStrategies, socialStrategies } = await WIKI.models.authentication.getStrategiesForLegacyClient()
|
||||
res.render('legacy/login', {
|
||||
err: false,
|
||||
|
@@ -395,7 +395,7 @@ router.get('/*', async (req, res, next) => {
|
||||
if (page) {
|
||||
_.set(res.locals, 'pageMeta.title', page.title)
|
||||
_.set(res.locals, 'pageMeta.description', page.description)
|
||||
const sidebar = await WIKI.models.navigation.getTree({ cache: true, locale: pageArgs.locale })
|
||||
const sidebar = await WIKI.models.navigation.getTree({ cache: true, locale: pageArgs.locale, groups: req.user.groups })
|
||||
const injectCode = {
|
||||
css: WIKI.config.theming.injectCSS,
|
||||
head: WIKI.config.theming.injectHead,
|
||||
|
@@ -105,6 +105,7 @@ module.exports = {
|
||||
connection: dbConfig,
|
||||
pool: {
|
||||
...WIKI.config.pool,
|
||||
propagateCreateError: false,
|
||||
async afterCreate(conn, done) {
|
||||
// -> Set Connection App Name
|
||||
switch (WIKI.config.db.type) {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
const _ = require('lodash')
|
||||
const { createApolloFetch } = require('apollo-fetch')
|
||||
const bugsnag = require('@bugsnag/node')
|
||||
const Bugsnag = require('@bugsnag/js')
|
||||
const { v4: uuid } = require('uuid')
|
||||
const os = require('os')
|
||||
const fs = require('fs-extra')
|
||||
@@ -8,21 +8,20 @@ const fs = require('fs-extra')
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
client: null,
|
||||
enabled: false,
|
||||
init() {
|
||||
this.client = bugsnag({
|
||||
Bugsnag.start({
|
||||
apiKey: WIKI.data.telemetry.BUGSNAG_ID,
|
||||
appType: 'server',
|
||||
appVersion: WIKI.version,
|
||||
autoNotify: false,
|
||||
collectUserIp: false,
|
||||
autoDetectErrors: false,
|
||||
autoTrackSessions: false,
|
||||
hostname: _.get(WIKI.config, 'telemetry.clientId', uuid()),
|
||||
notifyReleaseStages: ['production'],
|
||||
enabledReleaseStages: ['production'],
|
||||
releaseStage: WIKI.IS_DEBUG ? 'development' : 'production',
|
||||
projectRoot: WIKI.ROOTPATH,
|
||||
logger: null,
|
||||
beforeSend: (report) => {
|
||||
onError: (report) => {
|
||||
if (!WIKI.telemetry.enabled) { return false }
|
||||
}
|
||||
})
|
||||
@@ -34,7 +33,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
sendError(err) {
|
||||
this.client.notify(err)
|
||||
Bugsnag.notify(err)
|
||||
},
|
||||
sendEvent(eventCategory, eventAction, eventLabel) {
|
||||
// TODO
|
||||
|
@@ -11,7 +11,7 @@ module.exports = {
|
||||
},
|
||||
NavigationQuery: {
|
||||
async tree (obj, args, context, info) {
|
||||
return WIKI.models.navigation.getTree({ cache: false, locale: 'all' })
|
||||
return WIKI.models.navigation.getTree({ cache: false, locale: 'all', bypassAuth: true })
|
||||
},
|
||||
config (obj, args, context, info) {
|
||||
return WIKI.config.nav
|
||||
@@ -23,7 +23,9 @@ module.exports = {
|
||||
await WIKI.models.navigation.query().patch({
|
||||
config: args.tree
|
||||
}).where('key', 'site')
|
||||
await WIKI.cache.set('nav:sidebar', args.tree, 300)
|
||||
for (const tree of args.tree) {
|
||||
await WIKI.cache.set(`nav:sidebar:${tree.locale}`, tree.items, 300)
|
||||
}
|
||||
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Navigation updated successfully')
|
||||
|
@@ -53,6 +53,8 @@ type NavigationItem {
|
||||
icon: String
|
||||
targetType: String
|
||||
target: String
|
||||
visibilityMode: String
|
||||
visibilityGroups: [Int]
|
||||
}
|
||||
|
||||
input NavigationItemInput {
|
||||
@@ -62,6 +64,8 @@ input NavigationItemInput {
|
||||
icon: String
|
||||
targetType: String
|
||||
target: String
|
||||
visibilityMode: String
|
||||
visibilityGroups: [Int]
|
||||
}
|
||||
|
||||
type NavigationConfig {
|
||||
|
@@ -22,20 +22,24 @@ module.exports = class Navigation extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static async getTree({ cache = false, locale = 'en' } = {}) {
|
||||
static async getTree({ cache = false, locale = 'en', groups = [], bypassAuth = false } = {}) {
|
||||
if (cache) {
|
||||
const navTreeCached = await WIKI.cache.get(`nav:sidebar:${locale}`)
|
||||
if (navTreeCached) {
|
||||
return navTreeCached
|
||||
return bypassAuth ? navTreeCached : WIKI.models.navigation.getAuthorizedItems(navTreeCached, groups)
|
||||
}
|
||||
}
|
||||
const navTree = await WIKI.models.navigation.query().findOne('key', 'site')
|
||||
const navTree = await WIKI.models.navigation.query().findOne('key', `site`)
|
||||
if (navTree) {
|
||||
// Check for pre-2.1 format
|
||||
// Check for pre-2.3 format
|
||||
if (_.has(navTree.config[0], 'kind')) {
|
||||
navTree.config = [{
|
||||
locale: 'en',
|
||||
items: navTree.config
|
||||
items: navTree.config.map(item => ({
|
||||
...item,
|
||||
visibilityMode: 'all',
|
||||
visibilityGroups: []
|
||||
}))
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -44,10 +48,20 @@ module.exports = class Navigation extends Model {
|
||||
await WIKI.cache.set(`nav:sidebar:${tree.locale}`, tree.items, 300)
|
||||
}
|
||||
}
|
||||
return locale === 'all' ? navTree.config : WIKI.cache.get(`nav:sidebar:${locale}`)
|
||||
if (bypassAuth) {
|
||||
return locale === 'all' ? navTree.config : WIKI.cache.get(`nav:sidebar:${locale}`)
|
||||
} else {
|
||||
return locale === 'all' ? WIKI.models.navigation.getAuthorizedItems(navTree.config, groups) : WIKI.models.navigation.getAuthorizedItems(WIKI.cache.get(`nav:sidebar:${locale}`), groups)
|
||||
}
|
||||
} else {
|
||||
WIKI.logger.warn('Site Navigation is missing or corrupted.')
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
static getAuthorizedItems(tree = [], groups = []) {
|
||||
return _.filter(tree, leaf => {
|
||||
return leaf.visibilityMode === 'all' || _.intersection(leaf.visibilityGroups, groups).length > 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -315,12 +315,17 @@ module.exports = () => {
|
||||
key: 'site',
|
||||
config: [
|
||||
{
|
||||
id: uuid(),
|
||||
icon: 'mdi-home',
|
||||
kind: 'link',
|
||||
label: 'Home',
|
||||
target: '/',
|
||||
targetType: 'home'
|
||||
locale: 'en',
|
||||
items: [
|
||||
{
|
||||
id: uuid(),
|
||||
icon: 'mdi-home',
|
||||
kind: 'link',
|
||||
label: 'Home',
|
||||
target: '/',
|
||||
targetType: 'home'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
Reference in New Issue
Block a user