Просмотр исходного кода

revert changes of c5c1f86c3fad690cf346c995354216b131345d88

https://github.com/weseek/growi/commit/c5c1f86c3fad690cf346c995354216b131345d88
Yuki Takei 5 лет назад
Родитель
Сommit
4e60559a6b
2 измененных файлов с 82 добавлено и 20 удалено
  1. 68 0
      src/migrations/20200827045151-remove-layout-setting.js
  2. 14 20
      src/server/routes/page.js

+ 68 - 0
src/migrations/20200827045151-remove-layout-setting.js

@@ -0,0 +1,68 @@
+require('module-alias/register');
+const logger = require('@alias/logger')('growi:migrate:remove-layout-setting');
+
+const mongoose = require('mongoose');
+const config = require('@root/config/migrate');
+
+const { getModelSafely } = require('@commons/util/mongoose-utils');
+
+module.exports = {
+  async up(db, client) {
+    logger.info('Apply migration');
+    mongoose.connect(config.mongoUri, config.mongodb.options);
+
+    const Config = getModelSafely('Config') || require('@server/models/config')();
+
+    const layoutType = await Config.findOne({ key: 'customize:layout' });
+
+    if (layoutType == null) {
+      return;
+    }
+
+    const promise = [
+      // remove layout
+      Config.findOneAndDelete({ key: 'customize:layout' }),
+    ];
+
+    if (layoutType.value === '"kibela"') {
+      promise.push(
+        Config.update(
+          { key: 'customize:theme' },
+          { value: JSON.stringify('kibela') },
+        ),
+      );
+    }
+
+    await Promise.all(promise);
+
+    logger.info('Migration has successfully applied');
+  },
+
+  async down(db, client) {
+    logger.info('Rollback migration');
+    mongoose.connect(config.mongoUri, config.mongodb.options);
+
+    const Config = getModelSafely('Config') || require('@server/models/config')();
+
+    const theme = await Config.findOne({ key: 'customize:theme' });
+    const insertLayoutType = (theme.value === '"kibela"') ? 'kibela' : 'growi';
+
+    const insertConfig = new Config({
+      ns: 'crowi',
+      key: 'customize:layout',
+      value: JSON.stringify(insertLayoutType),
+    });
+
+    const promise = [
+      insertConfig.save(),
+      Config.update(
+        { key: 'customize:theme', value: JSON.stringify('kibela') },
+        { value: JSON.stringify('default') },
+      ),
+    ];
+
+    await Promise.all(promise);
+
+    logger.info('Migration has been successfully rollbacked');
+  },
+};

+ 14 - 20
src/server/routes/page.js

@@ -143,16 +143,16 @@ module.exports = function(crowi, app) {
   const ApiResponse = require('../util/apiResponse');
   const ApiResponse = require('../util/apiResponse');
   const getToday = require('../util/getToday');
   const getToday = require('../util/getToday');
 
 
-  const { slackNotificationService, configManager } = crowi;
+  const { slackNotificationService, configManager, xssService } = crowi;
   const interceptorManager = crowi.getInterceptorManager();
   const interceptorManager = crowi.getInterceptorManager();
   const globalNotificationService = crowi.getGlobalNotificationService();
   const globalNotificationService = crowi.getGlobalNotificationService();
 
 
   const XssOption = require('../../lib/service/xss/xssOption');
   const XssOption = require('../../lib/service/xss/xssOption');
   const Xss = require('../../lib/service/xss/index');
   const Xss = require('../../lib/service/xss/index');
   const initializedConfig = {
   const initializedConfig = {
-    isEnabledXssPrevention: crowi.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
-    tagWhiteList: crowi.xssService.getTagWhiteList(),
-    attrWhiteList: crowi.xssService.getAttrWhiteList(),
+    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+    tagWhiteList: xssService.getTagWhiteList(),
+    attrWhiteList: xssService.getAttrWhiteList(),
   };
   };
   const xssOption = new XssOption(initializedConfig);
   const xssOption = new XssOption(initializedConfig);
   const xss = new Xss(xssOption);
   const xss = new Xss(xssOption);
@@ -330,9 +330,8 @@ module.exports = function(crowi, app) {
   async function showTopPage(req, res, next) {
   async function showTopPage(req, res, next) {
     const portalPath = req.path;
     const portalPath = req.path;
     const revisionId = req.query.revision;
     const revisionId = req.query.revision;
-    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
 
-    const view = `layout-${layoutName}/page_list`;
+    const view = 'layout-growi/page_list';
     const renderVars = { path: portalPath };
     const renderVars = { path: portalPath };
 
 
     let portalPage = await Page.findByPathAndViewer(portalPath, req.user);
     let portalPage = await Page.findByPathAndViewer(portalPath, req.user);
@@ -364,7 +363,6 @@ module.exports = function(crowi, app) {
   async function showPageForGrowiBehavior(req, res, next) {
   async function showPageForGrowiBehavior(req, res, next) {
     const path = getPathFromRequest(req);
     const path = getPathFromRequest(req);
     const revisionId = req.query.revision;
     const revisionId = req.query.revision;
-    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
 
     let page = await Page.findByPathAndViewer(path, req.user);
     let page = await Page.findByPathAndViewer(path, req.user);
 
 
@@ -384,7 +382,7 @@ module.exports = function(crowi, app) {
     const offset = parseInt(req.query.offset) || 0;
     const offset = parseInt(req.query.offset) || 0;
     const renderVars = {};
     const renderVars = {};
 
 
-    let view = `layout-${layoutName}/page`;
+    let view = 'layout-growi/page';
 
 
     page.initLatestRevisionField(revisionId);
     page.initLatestRevisionField(revisionId);
 
 
@@ -406,7 +404,7 @@ module.exports = function(crowi, app) {
 
 
     if (isUserPage(page.path)) {
     if (isUserPage(page.path)) {
       // change template
       // change template
-      view = `layout-${layoutName}/user_page`;
+      view = 'layout-growi/user_page';
       await addRenderVarsForUserPage(renderVars, page, req.user);
       await addRenderVarsForUserPage(renderVars, page, req.user);
     }
     }
 
 
@@ -453,13 +451,11 @@ module.exports = function(crowi, app) {
     const { linkId } = req.params;
     const { linkId } = req.params;
     const revisionId = req.query.revision;
     const revisionId = req.query.revision;
 
 
-    const layoutName = configManager.getConfig('crowi', 'customize:layout');
-
     const shareLink = await ShareLink.findOne({ _id: linkId }).populate('relatedPage');
     const shareLink = await ShareLink.findOne({ _id: linkId }).populate('relatedPage');
 
 
     if (shareLink == null || shareLink.relatedPage == null) {
     if (shareLink == null || shareLink.relatedPage == null) {
       // page or sharelink are not found
       // page or sharelink are not found
-      return res.render(`layout-${layoutName}/not_found_shared_page`);
+      return res.render('layout-growi/not_found_shared_page');
     }
     }
 
 
     const renderVars = {};
     const renderVars = {};
@@ -469,7 +465,7 @@ module.exports = function(crowi, app) {
     // check if share link is expired
     // check if share link is expired
     if (shareLink.isExpired()) {
     if (shareLink.isExpired()) {
       // page is not found
       // page is not found
-      return res.render(`layout-${layoutName}/expired_shared_page`, renderVars);
+      return res.render('layout-growi/expired_shared_page', renderVars);
     }
     }
 
 
     let page = shareLink.relatedPage;
     let page = shareLink.relatedPage;
@@ -491,7 +487,7 @@ module.exports = function(crowi, app) {
     addRenderVarsForScope(renderVars, page);
     addRenderVarsForScope(renderVars, page);
 
 
     await interceptorManager.process('beforeRenderPage', req, res, renderVars);
     await interceptorManager.process('beforeRenderPage', req, res, renderVars);
-    return res.render(`layout-${layoutName}/shared_page`, renderVars);
+    return res.render('layout-growi/shared_page', renderVars);
   };
   };
 
 
   /**
   /**
@@ -528,19 +524,18 @@ module.exports = function(crowi, app) {
     const path = getPathFromRequest(req);
     const path = getPathFromRequest(req);
 
 
     const isCreatable = Page.isCreatableName(path);
     const isCreatable = Page.isCreatableName(path);
-    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
 
     let view;
     let view;
     const renderVars = { path };
     const renderVars = { path };
 
 
     if (!isCreatable) {
     if (!isCreatable) {
-      view = `layout-${layoutName}/not_creatable`;
+      view = 'layout-growi/not_creatable';
     }
     }
     else if (req.isForbidden) {
     else if (req.isForbidden) {
-      view = `layout-${layoutName}/forbidden`;
+      view = 'layout-growi/forbidden';
     }
     }
     else {
     else {
-      view = `layout-${layoutName}/not_found`;
+      view = 'layout-growi/not_found';
 
 
       // retrieve templates
       // retrieve templates
       if (req.user != null) {
       if (req.user != null) {
@@ -571,7 +566,6 @@ module.exports = function(crowi, app) {
   actions.deletedPageListShow = async function(req, res) {
   actions.deletedPageListShow = async function(req, res) {
     // normalizePath makes '/trash/' -> '/trash'
     // normalizePath makes '/trash/' -> '/trash'
     const path = pathUtils.normalizePath(`/trash${getPathFromRequest(req)}`);
     const path = pathUtils.normalizePath(`/trash${getPathFromRequest(req)}`);
-    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
 
     const limit = 50;
     const limit = 50;
     const offset = parseInt(req.query.offset) || 0;
     const offset = parseInt(req.query.offset) || 0;
@@ -596,7 +590,7 @@ module.exports = function(crowi, app) {
 
 
     renderVars.pager = generatePager(result.offset, result.limit, result.totalCount);
     renderVars.pager = generatePager(result.offset, result.limit, result.totalCount);
     renderVars.pages = result.pages;
     renderVars.pages = result.pages;
-    res.render(`layout-${layoutName}/page_list`, renderVars);
+    res.render('layout-growi/page_list', renderVars);
   };
   };
 
 
   /**
   /**