From 2668dde7bd7241a3a615016da5226e6b5ec1df12 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Mon, 20 Nov 2017 23:08:30 -0500 Subject: [PATCH] feat: upgradeFromMongo (wip) + panel UI improvements --- .../js/components/config-manager.component.js | 3 +- client/scss/components/panel.scss | 6 ++ server/app/data.yml | 2 + server/configure.js | 37 +++++--- server/modules/system.js | 30 ++++-- server/views/configure/index.pug | 5 - tools/fuse.js | 4 +- wercker.yml | 92 ------------------- 8 files changed, 59 insertions(+), 120 deletions(-) delete mode 100644 wercker.yml diff --git a/client/js/components/config-manager.component.js b/client/js/components/config-manager.component.js index 99620c11..75305bce 100644 --- a/client/js/components/config-manager.component.js +++ b/client/js/components/config-manager.component.js @@ -51,8 +51,7 @@ export default { telemetry: true, title: siteConfig.title || 'Wiki', upgrade: false, - upgMongo: 'mongodb://', - upgUserGroups: false + upgMongo: 'mongodb://' }, considerations: { https: false, diff --git a/client/scss/components/panel.scss b/client/scss/components/panel.scss index 73dfac27..3ea6fa60 100644 --- a/client/scss/components/panel.scss +++ b/client/scss/components/panel.scss @@ -33,7 +33,9 @@ border-top-left-radius: 4px; border-top-right-radius: 4px; background-color: mc('blue', '700'); + background-image: linear-gradient(to bottom, mc('blue', '700') 0%, mc('blue', '800') 100%); border-bottom-color: mc('blue', '900'); + box-shadow: inset 0 0 0 1px mc('blue', '600'), inset 0 0 0px 2px rgba(mc('blue', '800'), .5); color: #FFF; > i::before { @@ -42,6 +44,10 @@ } + & + .panel-content { + box-shadow: inset 0 0 0 1px #FFF, inset 0 30px 80px -25px mc('blue', '100'); + } + > span { font-weight: 500; } diff --git a/server/app/data.yml b/server/app/data.yml index 82ef2ba2..2aee5b37 100644 --- a/server/app/data.yml +++ b/server/app/data.yml @@ -108,4 +108,6 @@ langs: - id: es name: Spanish - EspaƱol +rtlLangs: + - fa # --------------------------------- diff --git a/server/configure.js b/server/configure.js index 94023cd5..e8da7c0d 100644 --- a/server/configure.js +++ b/server/configure.js @@ -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) { diff --git a/server/modules/system.js b/server/modules/system.js index a507208c..bf150e44 100644 --- a/server/modules/system.js +++ b/server/modules/system.js @@ -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() }) }) } diff --git a/server/views/configure/index.pug b/server/views/configure/index.pug index bf4b0816..489ad586 100644 --- a/server/views/configure/index.pug +++ b/server/views/configure/index.pug @@ -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 diff --git a/tools/fuse.js b/tools/fuse.js index 4bf534f6..eabbcb89 100644 --- a/tools/fuse.js +++ b/tools/fuse.js @@ -29,9 +29,9 @@ const args = require('yargs') const dev = args.dev if (dev) { - console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... ')) + console.info(colors.bgWhite.black(' Starting Wiki.js in DEVELOPER mode... ')) } else { - console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... ')) + console.info(colors.bgWhite.black(' Starting Wiki.js in BUILD mode... ')) } // ------------------------------------------------------- diff --git a/wercker.yml b/wercker.yml deleted file mode 100644 index 62bdd216..00000000 --- a/wercker.yml +++ /dev/null @@ -1,92 +0,0 @@ -build: - box: node:8 - steps: - - script: - name: install dependencies - code: | - apt-get update - apt-get install build-essential -y - npm install -g yarn - - script: - name: yarn install - code: | - yarn config set cache-folder "$WERCKER_CACHE_DIR/yarn" - yarn install - - script: - name: build - code: yarn run build - - npm-test - - script: - name: purge dev files - code: | - yarn install --production --ignore-scripts --prefer-offline - -deploy-docker-master: - box: node:8-alpine - steps: - - script: - name: install dependencies - code: | - apk update - apk add bash curl git openssh - - script: - name: copy app files - code: | - mkdir -p /var/wiki - cp -LR assets node_modules server config.sample.yml package.json LICENSE /var/wiki - rm -rf /pipeline - - internal/docker-push: - username: $DOCKER_HUB_USERNAME - password: $DOCKER_HUB_PASSWORD - tag: latest, master - ports: "3000" - working-dir: /var/wiki - entrypoint: node server - env: "WIKI_JS_HEROKU=1" - repository: requarks/wiki - registry: https://registry.hub.docker.com - -deploy-docker-dev: - box: node:8-alpine - steps: - - script: - name: install dependencies - code: | - apk update - apk add bash curl git openssh - - script: - name: copy app files - code: | - mkdir -p /var/wiki - cp -LR assets node_modules server config.sample.yml package.json LICENSE /var/wiki - rm -rf /pipeline - - internal/docker-push: - username: $DOCKER_HUB_USERNAME - password: $DOCKER_HUB_PASSWORD - tag: dev - ports: "3000" - working-dir: /var/wiki - entrypoint: node server - repository: requarks/wiki - registry: https://registry.hub.docker.com - -deploy-github: - box: node:8 - steps: - - script: - name: package - code: | - tar -chzf wiki-js.tar.gz assets server config.sample.yml package.json wiki.js LICENSE - tar -chzf node_modules.tar.gz node_modules - SEMVER_NEXT=`curl --request POST --url https://beta.requarks.io/api/version/increment --header "authorization: $WIKIJSORG_TOKEN" --header 'cache-control: no-cache' --header 'content-type: application/json' --data '{"channel": "stable"}'` - - github-create-release: - token: $GITHUB_TOKEN - tag: "v${SEMVER_NEXT}" - prerelease: true - title: "$SEMVER_NEXT Release" - - github-upload-asset: - token: $GITHUB_TOKEN - file: wiki-js.tar.gz - - github-upload-asset: - token: $GITHUB_TOKEN - file: node_modules.tar.gz