feat: admin - manage groups + permissions + page rules
This commit is contained in:
@@ -56,6 +56,7 @@ exports.up = knex => {
|
||||
table.increments('id').primary()
|
||||
table.string('name').notNullable()
|
||||
table.json('permissions').notNullable()
|
||||
table.json('pageRules').notNullable()
|
||||
table.boolean('isSystem').notNullable().defaultTo(false)
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
|
@@ -41,6 +41,7 @@ module.exports = {
|
||||
const group = await WIKI.models.groups.query().insertAndFetch({
|
||||
name: args.name,
|
||||
permissions: JSON.stringify(WIKI.data.groups.defaultPermissions),
|
||||
pageRules: JSON.stringify([]),
|
||||
isSystem: false
|
||||
})
|
||||
return {
|
||||
@@ -69,7 +70,11 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
async update(obj, args) {
|
||||
await WIKI.models.groups.query().patch({ name: args.name }).where('id', args.id)
|
||||
await WIKI.models.groups.query().patch({
|
||||
name: args.name,
|
||||
permissions: JSON.stringify(args.permissions),
|
||||
pageRules: JSON.stringify(args.pageRules)
|
||||
}).where('id', args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been updated.')
|
||||
}
|
||||
|
@@ -77,11 +77,14 @@ module.exports = {
|
||||
const osInfo = await getos()
|
||||
osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
|
||||
}
|
||||
return osLabel
|
||||
},
|
||||
async platform () {
|
||||
const isDockerized = await fs.pathExists('/.dockerenv')
|
||||
if (isDockerized) {
|
||||
osLabel = `${osLabel} (Docker Container)`
|
||||
return 'docker'
|
||||
}
|
||||
return osLabel
|
||||
return os.platform()
|
||||
},
|
||||
hostname() {
|
||||
return os.hostname()
|
||||
|
@@ -37,6 +37,8 @@ type GroupMutation {
|
||||
update(
|
||||
id: Int!
|
||||
name: String!
|
||||
permissions: [String]!
|
||||
pageRules: [PageRuleInput]!
|
||||
): DefaultResponse @auth(requires: ["write:groups", "manage:groups", "manage:system"])
|
||||
|
||||
delete(
|
||||
@@ -77,8 +79,46 @@ type Group {
|
||||
name: String!
|
||||
isSystem: Boolean!
|
||||
permissions: [String]!
|
||||
pageRules: [Right]
|
||||
pageRules: [PageRule]
|
||||
users: [UserMinimal]
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
}
|
||||
|
||||
type PageRule {
|
||||
id: String!
|
||||
deny: Boolean!
|
||||
match: PageRuleMatch!
|
||||
roles: [PageRuleRole]!
|
||||
path: String!
|
||||
locales: [String]!
|
||||
}
|
||||
|
||||
input PageRuleInput {
|
||||
id: String!
|
||||
deny: Boolean!
|
||||
match: PageRuleMatch!
|
||||
roles: [PageRuleRole]!
|
||||
path: String!
|
||||
locales: [String]!
|
||||
}
|
||||
|
||||
enum PageRuleRole {
|
||||
READ
|
||||
WRITE
|
||||
MANAGE
|
||||
DELETE
|
||||
AS_READ
|
||||
AS_WRITE
|
||||
AS_MANAGE
|
||||
CM_READ
|
||||
CM_WRITE
|
||||
CM_MANAGE
|
||||
}
|
||||
|
||||
enum PageRuleMatch {
|
||||
START
|
||||
EXACT
|
||||
END
|
||||
REGEX
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ type SystemInfo {
|
||||
nodeVersion: String
|
||||
operatingSystem: String
|
||||
pagesTotal: Int
|
||||
platform: String
|
||||
ramTotal: String
|
||||
redisHost: String
|
||||
redisTotalRAM: String
|
||||
|
@@ -11,7 +11,7 @@ module.exports = async (job) => {
|
||||
WIKI.logger.info('Purging orphaned upload files...')
|
||||
|
||||
try {
|
||||
const uplTempPath = path.resolve(process.cwd(), WIKI.config.paths.data, 'temp-upload')
|
||||
const uplTempPath = path.resolve(process.cwd(), WIKI.config.paths.data, 'uploads')
|
||||
const ls = await fs.readdirAsync(uplTempPath)
|
||||
const fifteenAgo = moment().subtract(15, 'minutes')
|
||||
|
||||
|
@@ -153,6 +153,7 @@ module.exports = async () => {
|
||||
|
||||
app.use((err, req, res, next) => {
|
||||
res.status(err.status || 500)
|
||||
res.locals.pageMeta.title = 'Error'
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: WIKI.IS_DEBUG ? err : {}
|
||||
|
@@ -26,6 +26,7 @@ module.exports = () => {
|
||||
const cfgHelper = require('./helpers/config')
|
||||
const crypto = Promise.promisifyAll(require('crypto'))
|
||||
const pem2jwk = require('pem-jwk').pem2jwk
|
||||
const semver = require('semver')
|
||||
|
||||
// ----------------------------------------
|
||||
// Define Express App
|
||||
@@ -83,6 +84,11 @@ module.exports = () => {
|
||||
WIKI.telemetry.sendEvent('setup', 'finalize')
|
||||
|
||||
try {
|
||||
// Basic checks
|
||||
if (!semver.satisfies(process.version, '>=10.14')) {
|
||||
throw new Error('Node.js 10.14.x or later required!')
|
||||
}
|
||||
|
||||
// Upgrade from WIKI.js 1.x?
|
||||
if (req.body.upgrade) {
|
||||
await WIKI.system.upgradeFromMongo({
|
||||
@@ -205,11 +211,15 @@ module.exports = () => {
|
||||
const adminGroup = await WIKI.models.groups.query().insert({
|
||||
name: 'Administrators',
|
||||
permissions: JSON.stringify(['manage:system']),
|
||||
pageRules: [],
|
||||
isSystem: true
|
||||
})
|
||||
const guestGroup = await WIKI.models.groups.query().insert({
|
||||
name: 'Guests',
|
||||
permissions: JSON.stringify(['read:pages']),
|
||||
pageRules: [
|
||||
{ id: 'guest', roles: ['READ', 'AS_READ', 'CM_READ'], match: 'START', deny: false, path: '', locales: [] }
|
||||
],
|
||||
isSystem: true
|
||||
})
|
||||
|
||||
|
@@ -5,7 +5,7 @@ block body
|
||||
v-app
|
||||
.newpage
|
||||
.newpage-content
|
||||
img.animated.fadeIn(src='/svg/icon-close-window.svg', alt='Henry')
|
||||
img.animated.fadeIn(src='/svg/icon-delete-file.svg', alt='Not Found')
|
||||
.headline= t('newpage.title')
|
||||
.subheading.mt-3= t('newpage.subtitle')
|
||||
v-btn.mt-5(href='/e' + pagePath, large)
|
||||
|
Reference in New Issue
Block a user