refactor: remove config namespaces
This commit is contained in:
@@ -23,6 +23,15 @@ exports.up = knex => {
|
||||
table.string('slug').notNullable()
|
||||
table.integer('parentId').unsigned().references('id').inTable('assetFolders')
|
||||
})
|
||||
// AUTHENTICATION ----------------------
|
||||
.createTable('authentication', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('title').notNullable()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.boolean('useForm').notNullable().defaultTo(false)
|
||||
table.jsonb('config').notNullable()
|
||||
})
|
||||
// COMMENTS ----------------------------
|
||||
.createTable('comments', table => {
|
||||
table.increments('id').primary()
|
||||
@@ -30,6 +39,14 @@ exports.up = knex => {
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// EDITORS -----------------------------
|
||||
.createTable('editors', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('title').notNullable()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.jsonb('config')
|
||||
})
|
||||
// GROUPS ------------------------------
|
||||
.createTable('groups', table => {
|
||||
table.increments('id').primary()
|
||||
@@ -54,6 +71,7 @@ exports.up = knex => {
|
||||
table.string('path').notNullable()
|
||||
table.string('title').notNullable()
|
||||
table.string('description')
|
||||
table.boolean('isPrivate').notNullable().defaultTo(false)
|
||||
table.boolean('isPublished').notNullable().defaultTo(false)
|
||||
table.string('publishStartDate')
|
||||
table.string('publishEndDate')
|
||||
@@ -66,9 +84,16 @@ exports.up = knex => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.jsonb('value')
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
// STORAGE -----------------------------
|
||||
.createTable('storage', table => {
|
||||
table.increments('id').primary()
|
||||
table.string('key').notNullable().unique()
|
||||
table.string('title').notNullable()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.jsonb('config')
|
||||
})
|
||||
// TAGS --------------------------------
|
||||
.createTable('tags', table => {
|
||||
table.increments('id').primary()
|
||||
@@ -82,16 +107,17 @@ exports.up = knex => {
|
||||
table.increments('id').primary()
|
||||
table.string('email').notNullable()
|
||||
table.string('name').notNullable()
|
||||
table.string('provider').notNullable().defaultTo('local')
|
||||
table.string('providerId')
|
||||
table.string('password')
|
||||
table.boolean('tfaIsActive').notNullable().defaultTo(false)
|
||||
table.string('tfaSecret')
|
||||
table.enum('role', ['admin', 'guest', 'user']).notNullable().defaultTo('guest')
|
||||
table.string('jobTitle').defaultTo('')
|
||||
table.string('location').defaultTo('')
|
||||
table.string('pictureUrl')
|
||||
table.string('timezone').notNullable().defaultTo('America/New_York')
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
|
||||
table.unique(['provider', 'email'])
|
||||
})
|
||||
// =====================================
|
||||
// RELATION TABLES
|
||||
@@ -120,11 +146,16 @@ exports.up = knex => {
|
||||
table.integer('authorId').unsigned().references('id').inTable('users')
|
||||
})
|
||||
.table('pages', table => {
|
||||
table.string('editor').references('key').inTable('editors')
|
||||
table.string('locale', 2).references('code').inTable('locales')
|
||||
table.integer('authorId').unsigned().references('id').inTable('users')
|
||||
})
|
||||
.table('users', table => {
|
||||
table.string('locale', 2).references('code').inTable('locales')
|
||||
table.string('provider').references('key').inTable('authentication').notNullable().defaultTo('local')
|
||||
table.string('locale', 2).references('code').inTable('locales').notNullable().defaultTo('en')
|
||||
table.string('defaultEditor').references('key').inTable('editors').notNullable().defaultTo('markdown')
|
||||
|
||||
table.unique(['provider', 'email'])
|
||||
})
|
||||
}
|
||||
|
||||
|
64
server/db/models/authentication.js
Normal file
64
server/db/models/authentication.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const Model = require('objection').Model
|
||||
const autoload = require('auto-load')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* Authentication model
|
||||
*/
|
||||
module.exports = class Authentication extends Model {
|
||||
static get tableName() { return 'authentication' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: ['key', 'title', 'isEnabled', 'useForm'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
title: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
useForm: {type: 'boolean'},
|
||||
config: {type: 'object'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async getEnabledStrategies() {
|
||||
return WIKI.db.authentication.query().where({ isEnabled: true })
|
||||
}
|
||||
|
||||
static async refreshStrategiesFromDisk() {
|
||||
try {
|
||||
const dbStrategies = await WIKI.db.authentication.query()
|
||||
const diskStrategies = autoload(path.join(WIKI.SERVERPATH, 'modules/authentication'))
|
||||
let newStrategies = []
|
||||
_.forOwn(diskStrategies, (strategy, strategyKey) => {
|
||||
if (!_.some(dbStrategies, ['key', strategy.key])) {
|
||||
newStrategies.push({
|
||||
key: strategy.key,
|
||||
title: strategy.title,
|
||||
isEnabled: false,
|
||||
useForm: strategy.useForm,
|
||||
config: _.reduce(strategy.props, (result, value, key) => {
|
||||
_.set(result, value, '')
|
||||
return result
|
||||
}, {})
|
||||
})
|
||||
}
|
||||
})
|
||||
if (newStrategies.length > 0) {
|
||||
await WIKI.db.authentication.query().insert(newStrategies)
|
||||
WIKI.logger.info(`Loaded ${newStrategies.length} new authentication strategies: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new authentication strategies found: [ SKIPPED ]`)
|
||||
}
|
||||
} catch (err) {
|
||||
WIKI.logger.error(`Failed to scan or load new authentication providers: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
}
|
||||
}
|
62
server/db/models/editors.js
Normal file
62
server/db/models/editors.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const Model = require('objection').Model
|
||||
const autoload = require('auto-load')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* Editor model
|
||||
*/
|
||||
module.exports = class Editor extends Model {
|
||||
static get tableName() { return 'editors' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: ['key', 'title', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
title: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
config: {type: 'object'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async getEnabledEditors() {
|
||||
return WIKI.db.editors.query().where({ isEnabled: true })
|
||||
}
|
||||
|
||||
static async refreshEditorsFromDisk() {
|
||||
try {
|
||||
const dbEditors = await WIKI.db.editors.query()
|
||||
const diskEditors = autoload(path.join(WIKI.SERVERPATH, 'modules/editor'))
|
||||
let newEditors = []
|
||||
_.forOwn(diskEditors, (strategy, strategyKey) => {
|
||||
if (!_.some(dbEditors, ['key', strategy.key])) {
|
||||
newEditors.push({
|
||||
key: strategy.key,
|
||||
title: strategy.title,
|
||||
isEnabled: false,
|
||||
config: _.reduce(strategy.props, (result, value, key) => {
|
||||
_.set(result, value, '')
|
||||
return result
|
||||
}, {})
|
||||
})
|
||||
}
|
||||
})
|
||||
if (newEditors.length > 0) {
|
||||
await WIKI.db.editors.query().insert(newEditors)
|
||||
WIKI.logger.info(`Loaded ${newEditors.length} new editors: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new editors found: [ SKIPPED ]`)
|
||||
}
|
||||
} catch (err) {
|
||||
WIKI.logger.error(`Failed to scan or load new editors: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,9 +1,12 @@
|
||||
const Model = require('objection').Model
|
||||
const _ = require('lodash')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* Settings model
|
||||
*/
|
||||
module.exports = class User extends Model {
|
||||
module.exports = class Setting extends Model {
|
||||
static get tableName() { return 'settings' }
|
||||
|
||||
static get jsonSchema () {
|
||||
@@ -25,7 +28,18 @@ module.exports = class User extends Model {
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
$beforeInsert() {
|
||||
this.createdAt = new Date().toISOString()
|
||||
this.updatedAt = new Date().toISOString()
|
||||
}
|
||||
|
||||
static async getConfig() {
|
||||
const settings = await WIKI.db.settings.query()
|
||||
if (settings.length > 0) {
|
||||
return _.reduce(settings, (res, val, key) => {
|
||||
_.set(res, val.key, (val.value.v) ? val.value.v : val.value)
|
||||
return res
|
||||
}, {})
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,9 @@ module.exports = class User extends Model {
|
||||
tfaIsActive: {type: 'boolean', default: false},
|
||||
tfaSecret: {type: 'string'},
|
||||
locale: {type: 'string'},
|
||||
jobTitle: {type: 'string'},
|
||||
location: {type: 'string'},
|
||||
pictureUrl: {type: 'string'},
|
||||
createdAt: {type: 'string'},
|
||||
updatedAt: {type: 'string'}
|
||||
}
|
||||
|
Reference in New Issue
Block a user