itizawa 5 лет назад
Родитель
Сommit
e7783984b3

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

@@ -1,76 +0,0 @@
-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');
-  },
-};
-
-// {
-//   "_id" : ObjectId("5f4747ea4060d22072d3b188"),
-//   "ns" : "crowi",
-//   "key" : "customize:layout",
-//   "value" : "\"kibela\"",
-//   "__v" : 0
-// }

+ 5 - 3
src/server/models/config.js

@@ -22,8 +22,12 @@ module.exports = function(crowi) {
     // overwrite
     config['app:installed'] = true;
     config['app:fileUpload'] = true;
+    config['customize:layout'] = 'growi';
     config['customize:isSavedStatesOfTabChanges'] = false;
 
+    config['mail:sesAccessKeyId'] = undefined;
+    config['mail:sesSecretAccessKey']= undefined;
+
     return config;
   }
 
@@ -97,9 +101,6 @@ module.exports = function(crowi) {
       'mail:smtpUser'     : undefined,
       'mail:smtpPassword' : undefined,
 
-      'mail:sesAccessKeyId' : undefined,
-      'mail:sesSecretAccessKey' : undefined,
-
       'plugin:isEnabledPlugins' : true,
 
       'customize:css' : undefined,
@@ -191,6 +192,7 @@ module.exports = function(crowi) {
         file: crowi.fileUploadService.getFileUploadEnabled(),
       },
       registrationWhiteList: crowi.configManager.getConfig('crowi', 'security:registrationWhiteList'),
+      layoutType: crowi.configManager.getConfig('crowi', 'customize:layout'),
       themeType: crowi.configManager.getConfig('crowi', 'customize:theme'),
       isEnabledLinebreaks: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks'),
       isEnabledLinebreaksInComments: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments'),

+ 16 - 11
src/server/routes/page.js

@@ -147,7 +147,7 @@ module.exports = function(crowi, app) {
   const ApiResponse = require('../util/apiResponse');
   const getToday = require('../util/getToday');
 
-  const { slackNotificationService } = crowi;
+  const { slackNotificationService, configManager } = crowi;
   const interceptorManager = crowi.getInterceptorManager();
   const globalNotificationService = crowi.getGlobalNotificationService();
   const pageService = crowi.pageService;
@@ -304,8 +304,9 @@ module.exports = function(crowi, app) {
   async function showTopPage(req, res, next) {
     const portalPath = req.path;
     const revisionId = req.query.revision;
+    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
-    const view = 'layout-growi/page_list';
+    const view = `layout-${layoutName}/page_list`;
     const renderVars = { path: portalPath };
 
     let portalPage = await Page.findByPathAndViewer(portalPath, req.user);
@@ -332,6 +333,7 @@ module.exports = function(crowi, app) {
   async function showPageForGrowiBehavior(req, res, next) {
     const path = getPathFromRequest(req);
     const revisionId = req.query.revision;
+    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
     let page = await Page.findByPathAndViewer(path, req.user);
 
@@ -351,7 +353,7 @@ module.exports = function(crowi, app) {
     const offset = parseInt(req.query.offset) || 0;
     const renderVars = {};
 
-    let view = 'layout-growi/page';
+    let view = `layout-${layoutName}/page`;
 
     page.initLatestRevisionField(revisionId);
 
@@ -368,7 +370,7 @@ module.exports = function(crowi, app) {
 
     if (isUserPage(page.path)) {
       // change template
-      view = 'layout-growi/user_page';
+      view = `layout-${layoutName}/user_page`;
       await addRenderVarsForUserPage(renderVars, page, req.user);
     }
 
@@ -415,13 +417,14 @@ module.exports = function(crowi, app) {
     const { linkId } = req.params;
     const revisionId = req.query.revision;
 
-    const view = 'layout-growi/shared_page';
+    const layoutName = configManager.getConfig('crowi', 'customize:layout');
+    const view = `layout-${layoutName}/shared_page`;
 
     const shareLink = await ShareLink.findOne({ _id: linkId }).populate('relatedPage');
 
     if (shareLink == null || shareLink.relatedPage == null) {
       // page or sharelink are not found
-      return res.render('layout-growi/not_found_shared_page');
+      return res.render(`layout-${layoutName}/not_found_shared_page`);
     }
 
     let page = shareLink.relatedPage;
@@ -429,7 +432,7 @@ module.exports = function(crowi, app) {
     // check if share link is expired
     if (shareLink.isExpired()) {
       // page is not found
-      return res.render('layout-growi/expired_shared_page');
+      return res.render(`layout-${layoutName}/expired_shared_page`);
     }
 
     const renderVars = {};
@@ -490,18 +493,19 @@ module.exports = function(crowi, app) {
     const path = getPathFromRequest(req);
 
     const isCreatable = Page.isCreatableName(path);
+    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
     let view;
     const renderVars = { path };
 
     if (!isCreatable) {
-      view = 'layout-growi/not_creatable';
+      view = `layout-${layoutName}/not_creatable`;
     }
     else if (req.isForbidden) {
-      view = 'layout-growi/forbidden';
+      view = `layout-${layoutName}/forbidden`;
     }
     else {
-      view = 'layout-growi/not_found';
+      view = `layout-${layoutName}/not_found`;
 
       // retrieve templates
       if (req.user != null) {
@@ -532,6 +536,7 @@ module.exports = function(crowi, app) {
   actions.deletedPageListShow = async function(req, res) {
     // normalizePath makes '/trash/' -> '/trash'
     const path = pathUtils.normalizePath(`/trash${getPathFromRequest(req)}`);
+    const layoutName = configManager.getConfig('crowi', 'customize:layout');
 
     const limit = 50;
     const offset = parseInt(req.query.offset) || 0;
@@ -556,7 +561,7 @@ module.exports = function(crowi, app) {
 
     renderVars.pager = generatePager(result.offset, result.limit, result.totalCount);
     renderVars.pages = result.pages;
-    res.render('layout-growi/page_list', renderVars);
+    res.render(`layout-${layoutName}/page_list`, renderVars);
   };
 
   /**