feat: upgradeFromMongo (wip) + panel UI improvements

This commit is contained in:
NGPixel
2017-11-20 23:08:30 -05:00
parent 82ea0b50fb
commit 2668dde7bd
8 changed files with 59 additions and 120 deletions

View File

@@ -108,4 +108,6 @@ langs:
-
id: es
name: Spanish - Español
rtlLangs:
- fa
# ---------------------------------

View File

@@ -20,7 +20,7 @@ module.exports = () => {
const favicon = require('serve-favicon')
const http = require('http')
const Promise = require('bluebird')
const fs = require('fs-extra')
const fs = Promise.promisifyAll(require('fs-extra'))
const yaml = require('js-yaml')
const _ = require('lodash')
const cfgHelper = require('./helpers/config')
@@ -236,22 +236,37 @@ module.exports = () => {
})
}
// Load configuration file
let confRaw = await fs.readFile(path.join(wiki.ROOTPATH, 'config.yml'), 'utf8')
// Update config file
let confRaw = await fs.readFileAsync(path.join(wiki.ROOTPATH, 'config.yml'), 'utf8')
let conf = yaml.safeLoad(confRaw)
// Update config
conf.host = req.body.host
conf.port = req.body.port
conf.paths.repo = req.body.pathRepo
// Generate session secret
let sessionSecret = (await crypto.randomBytesAsync(32)).toString('hex')
console.info(sessionSecret)
// Save updated config to file
confRaw = yaml.safeDump(conf)
await fs.writeFile(path.join(wiki.ROOTPATH, 'config.yml'), confRaw)
await fs.writeFileAsync(path.join(wiki.ROOTPATH, 'config.yml'), confRaw)
// Populate config namespaces
wiki.config.auth = wiki.config.auth || {}
wiki.config.features = wiki.config.features || {}
wiki.config.git = wiki.config.git || {}
wiki.config.logging = wiki.config.logging || {}
wiki.config.site = wiki.config.site || {}
wiki.config.theme = wiki.config.theme || {}
wiki.config.uploads = wiki.config.uploads || {}
// Site namespace
wiki.config.site.title = req.body.title
wiki.config.site.path = req.body.path
wiki.config.site.lang = req.body.lang
wiki.config.site.rtl = _.includes(wiki.data.rtlLangs, req.body.lang)
wiki.config.site.sessionSecret = (await crypto.randomBytesAsync(32)).toString('hex')
// Auth namespace
wiki.config.auth.public = (req.body.public === 'true')
// Logging namespace
wiki.config.logging.telemetry = (req.body.telemetry === 'true')
res.json({ ok: true })
} catch (err) {

View File

@@ -2,7 +2,7 @@
const Promise = require('bluebird')
// const pm2 = Promise.promisifyAll(require('pm2'))
// const _ = require('lodash')
const _ = require('lodash')
const cfgHelper = require('../helpers/config')
module.exports = {
@@ -20,7 +20,7 @@ module.exports = {
return new Promise((resolve, reject) => {
// Connect to MongoDB
return mongo.connect(parsedMongoConStr, {
mongo.connect(parsedMongoConStr, {
autoReconnect: false,
reconnectTries: 2,
reconnectInterval: 1000,
@@ -34,19 +34,33 @@ module.exports = {
// Check if users table is populated
let userCount = await users.count()
if (userCount < 1) {
throw new Error('Users table is empty or invalid!')
if (userCount < 2) {
throw new Error('MongoDB Upgrade: Users table is empty!')
}
// Fetch all users
let userData = await users.find({}).toArray()
console.info(userData)
// Import all users
let userData = await users.find({
email: {
$not: 'guest'
}
}).toArray()
await wiki.db.User.bulkCreate(_.map(userData, usr => {
return {
email: usr.email,
name: usr.name || 'Imported User',
password: usr.password || '',
provider: usr.provider || 'local',
providerId: usr.providerId || '',
role: 'user',
createdAt: usr.createdAt
}
}))
resolve(true)
} catch (err) {
reject(err)
db.close()
}
db.close()
})
})
}

View File

@@ -319,11 +319,6 @@ block body
label.label Connection String to Wiki.js 1.x MongoDB database
input(type='text', placeholder='mongodb://', v-model='conf.upgMongo', data-vv-scope='upgrade', name='ipt-mongo', v-validate='{ required: true, min: 2 }')
span.desc A MongoDB database connection string where a Wiki.js 1.x installation is located. #[strong No alterations will be made to this database. ]
section
p.control.is-fullwidth
input#ipt-public(type='checkbox', v-model='conf.upgUserGroups', data-vv-scope='upgrade', name='ipt-public')
label.label(for='ipt-public') Create groups based on individual permissions
span.desc User groups will be created based on existing users permissions. If multiple users have the exact same permission rules, they will be put in the same user group.
.panel-footer
.progress-bar: div(v-bind:style='{width: currentProgress}')
button.button.is-small.is-light-blue.is-outlined(v-on:click='proceedToAdmin', v-bind:disabled='loading') Back