Browse Source

Merge pull request #1064 from weseek/imprv/abolish-old-config-api-cleaning

Imprv/abolish old config api cleaning
Yuki Takei 6 years ago
parent
commit
46baff69d7

+ 2 - 2
src/migrations/20180927102719-init-serverurl.js

@@ -79,7 +79,7 @@ module.exports = {
   },
   },
 
 
   async down(db) {
   async down(db) {
-    logger.info('Undo migration');
+    logger.info('Rollback migration');
     mongoose.connect(config.mongoUri, config.mongodb.options);
     mongoose.connect(config.mongoUri, config.mongodb.options);
 
 
     const Config = getModelSafely('Config') || require('@server/models/config')();
     const Config = getModelSafely('Config') || require('@server/models/config')();
@@ -90,7 +90,7 @@ module.exports = {
       key: 'app:siteUrl',
       key: 'app:siteUrl',
     });
     });
 
 
-    logger.info('Migration has successfully undoed');
+    logger.info('Migration has been successfully rollbacked');
   },
   },
 
 
 };
 };

+ 7 - 5
src/migrations/20181019114028-abolish-page-group-relation.js

@@ -38,7 +38,7 @@ module.exports = {
       return;
       return;
     }
     }
 
 
-    const Page = getModelSafely('Page') || require('@server/models/page');
+    const Page = getModelSafely('Page') || require('@server/models/page')();
     const UserGroup = getModelSafely('UserGroup') || require('@server/models/user-group')();
     const UserGroup = getModelSafely('UserGroup') || require('@server/models/user-group')();
 
 
     // retrieve all documents from 'pagegrouprelations'
     // retrieve all documents from 'pagegrouprelations'
@@ -72,10 +72,10 @@ module.exports = {
   },
   },
 
 
   async down(db) {
   async down(db) {
-    logger.info('Undo migration');
+    logger.info('Rollback migration');
     mongoose.connect(config.mongoUri, config.mongodb.options);
     mongoose.connect(config.mongoUri, config.mongodb.options);
 
 
-    const Page = getModelSafely('Page') || require('@server/models/page');
+    const Page = getModelSafely('Page') || require('@server/models/page')();
     const UserGroup = getModelSafely('UserGroup') || require('@server/models/user-group')();
     const UserGroup = getModelSafely('UserGroup') || require('@server/models/user-group')();
 
 
     // retrieve all Page documents which granted by UserGroup
     // retrieve all Page documents which granted by UserGroup
@@ -107,9 +107,11 @@ module.exports = {
     }
     }
     /* eslint-enable no-await-in-loop */
     /* eslint-enable no-await-in-loop */
 
 
-    await db.collection('pagegrouprelations').insertMany(insertDocs);
+    if (insertDocs.length > 0) {
+      await db.collection('pagegrouprelations').insertMany(insertDocs);
+    }
 
 
-    logger.info('Migration has successfully undoed');
+    logger.info('Migration has been successfully rollbacked');
   },
   },
 
 
 };
 };

+ 7 - 3
src/migrations/20190618055300-abolish-crowi-classic-auth.js

@@ -1,4 +1,4 @@
-const logger = require('@alias/logger')('growi:migrate:make-email-unique');
+const logger = require('@alias/logger')('growi:migrate:abolish-crowi-classic-auth');
 
 
 const mongoose = require('mongoose');
 const mongoose = require('mongoose');
 const config = require('@root/config/migrate');
 const config = require('@root/config/migrate');
@@ -15,7 +15,11 @@ module.exports = {
 
 
     // enable passport and delete configs for crowi classic auth
     // enable passport and delete configs for crowi classic auth
     await Promise.all([
     await Promise.all([
-      Config.findOneAndUpdateByNsAndKey('crowi', 'security:isEnabledPassport', true),
+      Config.findOneAndUpdate(
+        { ns: 'crowi', key: 'security:isEnabledPassport' },
+        { ns: 'crowi', key: 'security:isEnabledPassport', value: JSON.stringify(true) },
+        { upsert: true },
+      ),
       Config.deleteOne({ ns: 'crowi', key: 'google:clientId' }),
       Config.deleteOne({ ns: 'crowi', key: 'google:clientId' }),
       Config.deleteOne({ ns: 'crowi', key: 'google:clientSecret' }),
       Config.deleteOne({ ns: 'crowi', key: 'google:clientSecret' }),
     ]);
     ]);
@@ -24,7 +28,7 @@ module.exports = {
     next();
     next();
   },
   },
 
 
-  down(db, next) {
+  async down(db, next) {
     // do not rollback
     // do not rollback
     next();
     next();
   },
   },

+ 2 - 2
src/migrations/20190618104011-add-config-app-installed.js

@@ -48,7 +48,7 @@ module.exports = {
   },
   },
 
 
   async down(db) {
   async down(db) {
-    logger.info('Undo migration');
+    logger.info('Rollback migration');
     mongoose.connect(config.mongoUri, config.mongodb.options);
     mongoose.connect(config.mongoUri, config.mongodb.options);
 
 
     const Config = getModelSafely('Config') || require('@server/models/config')();
     const Config = getModelSafely('Config') || require('@server/models/config')();
@@ -59,6 +59,6 @@ module.exports = {
       key: 'app:installed',
       key: 'app:installed',
     });
     });
 
 
-    logger.info('Migration has successfully undoed');
+    logger.info('Migration has been successfully rollbacked');
   },
   },
 };
 };

+ 2 - 4
src/server/crowi/express-init.js

@@ -65,12 +65,10 @@ module.exports = function(crowi, app) {
     const Config = crowi.model('Config');
     const Config = crowi.model('Config');
     app.set('tzoffset', tzoffset);
     app.set('tzoffset', tzoffset);
 
 
-    // req.config = config;
     req.csrfToken = null;
     req.csrfToken = null;
 
 
     res.locals.req = req;
     res.locals.req = req;
     res.locals.baseUrl = crowi.appService.getSiteUrl();
     res.locals.baseUrl = crowi.appService.getSiteUrl();
-    // res.locals.config = config;
     res.locals.env = env;
     res.locals.env = env;
     res.locals.now = now;
     res.locals.now = now;
     res.locals.tzoffset = tzoffset;
     res.locals.tzoffset = tzoffset;
@@ -78,8 +76,8 @@ module.exports = function(crowi, app) {
       pageGrants: Page.getGrantLabels(),
       pageGrants: Page.getGrantLabels(),
       userStatus: User.getUserStatusLabels(),
       userStatus: User.getUserStatusLabels(),
       language:   User.getLanguageLabels(),
       language:   User.getLanguageLabels(),
-      restrictGuestMode: Config.getRestrictGuestModeLabels(),
-      registrationMode: Config.getRegistrationModeLabels(),
+      restrictGuestMode: crowi.aclService.getRestrictGuestModeLabels(),
+      registrationMode: crowi.aclService.getRegistrationModeLabels(),
     };
     };
     res.locals.local_config = Config.getLocalconfig(); // config for browser context
     res.locals.local_config = Config.getLocalconfig(); // config for browser context
 
 

+ 0 - 16
src/server/crowi/index.js

@@ -225,22 +225,6 @@ Crowi.prototype.setupSessionConfig = function() {
   }));
   }));
 };
 };
 
 
-// Crowi.prototype.setupAppConfig = function() {
-//   return new Promise((resolve, reject) => {
-//     this.model('Config', require('../models/config')(this));
-//     const Config = this.model('Config');
-//     Config.loadAllConfig((err, doc) => {
-//       if (err) {
-//         return reject();
-//       }
-
-//       this.setConfig(doc);
-
-//       return resolve();
-//     });
-//   });
-// };
-
 Crowi.prototype.setupConfigManager = async function() {
 Crowi.prototype.setupConfigManager = async function() {
   const ConfigManager = require('../service/config-manager');
   const ConfigManager = require('../service/config-manager');
   this.configManager = new ConfigManager(this.model('Config'));
   this.configManager = new ConfigManager(this.model('Config'));

+ 1 - 151
src/server/models/config.js

@@ -5,13 +5,6 @@
 
 
 module.exports = function(crowi) {
 module.exports = function(crowi) {
   const mongoose = require('mongoose');
   const mongoose = require('mongoose');
-  const debug = require('debug')('growi:models:config');
-
-  const SECURITY_RESTRICT_GUEST_MODE_DENY = 'Deny';
-  const SECURITY_RESTRICT_GUEST_MODE_READONLY = 'Readonly';
-  const SECURITY_REGISTRATION_MODE_OPEN = 'Open';
-  const SECURITY_REGISTRATION_MODE_RESTRICTED = 'Resricted';
-  const SECURITY_REGISTRATION_MODE_CLOSED = 'Closed';
 
 
   const configSchema = new mongoose.Schema({
   const configSchema = new mongoose.Schema({
     ns: { type: String, required: true, index: true },
     ns: { type: String, required: true, index: true },
@@ -19,12 +12,6 @@ module.exports = function(crowi) {
     value: { type: String, required: true },
     value: { type: String, required: true },
   });
   });
 
 
-  function validateCrowi() {
-    if (crowi == null) {
-      throw new Error('"crowi" is null. Init Config model with "crowi" argument first.');
-    }
-  }
-
   /**
   /**
    * default values when GROWI is cleanly installed
    * default values when GROWI is cleanly installed
    */
    */
@@ -168,114 +155,7 @@ module.exports = function(crowi) {
     return getDefaultNotificationConfigs();
     return getDefaultNotificationConfigs();
   };
   };
 
 
-  configSchema.statics.getRestrictGuestModeLabels = function() {
-    const labels = {};
-    labels[SECURITY_RESTRICT_GUEST_MODE_DENY] = 'security_setting.guest_mode.deny';
-    labels[SECURITY_RESTRICT_GUEST_MODE_READONLY] = 'security_setting.guest_mode.readonly';
-
-    return labels;
-  };
-
-  configSchema.statics.getRegistrationModeLabels = function() {
-    const labels = {};
-    labels[SECURITY_REGISTRATION_MODE_OPEN] = 'security_setting.registration_mode.open';
-    labels[SECURITY_REGISTRATION_MODE_RESTRICTED] = 'security_setting.registration_mode.restricted';
-    labels[SECURITY_REGISTRATION_MODE_CLOSED] = 'security_setting.registration_mode.closed';
-
-    return labels;
-  };
-
-  configSchema.statics.updateConfigCache = function(ns, config) {
-    validateCrowi();
-
-    // const originalConfig = crowi.getConfig();
-    // const newNSConfig = originalConfig[ns] || {};
-    // Object.keys(config).forEach((key) => {
-    //   if (config[key] || config[key] === '' || config[key] === false) {
-    //     newNSConfig[key] = config[key];
-    //   }
-    // });
-
-    // originalConfig[ns] = newNSConfig;
-    // crowi.setConfig(originalConfig);
-
-    // // initialize custom css/script
-    // Config.initCustomCss(originalConfig);
-    // Config.initCustomScript(originalConfig);
-  };
-
-  // Execute only once for installing application
-  // configSchema.statics.applicationInstall = function(callback) {
-  //   const Config = this;
-  //   Config.count({ ns: 'crowi' }, (err, count) => {
-  //     if (count > 0) {
-  //       return callback(new Error('Application already installed'), null);
-  //     }
-  //     Config.updateNamespaceByArray('crowi', getArrayForInstalling(), (err, configs) => {
-  //       Config.updateConfigCache('crowi', configs);
-  //       return callback(err, configs);
-  //     });
-  //   });
-  // };
-
-  configSchema.statics.updateNamespaceByArray = function(ns, configs, callback) {
-    const Config = this;
-    if (configs.length < 0) {
-      return callback(new Error('Argument #1 is not array.'), null);
-    }
-
-    Object.keys(configs).forEach((key) => {
-      const value = configs[key];
-
-      Config.findOneAndUpdate(
-        { ns, key },
-        { ns, key, value: JSON.stringify(value) },
-        { upsert: true },
-        (err, config) => {
-          debug('Config.findAndUpdate', err, config);
-        },
-      );
-    });
-
-    return callback(null, configs);
-  };
-
-  configSchema.statics.findOneAndUpdateByNsAndKey = async function(ns, key, value) {
-    return this.findOneAndUpdate(
-      { ns, key },
-      { ns, key, value: JSON.stringify(value) },
-      { upsert: true },
-    );
-  };
-
-  // configSchema.statics.loadAllConfig = function(callback) {
-  //   const Config = this;
-
-
-  //   const config = {};
-  //   config.crowi = {}; // crowi namespace
-
-  //   Config.find()
-  //     .sort({ ns: 1, key: 1 })
-  //     .exec((err, doc) => {
-  //       doc.forEach((el) => {
-  //         if (!config[el.ns]) {
-  //           config[el.ns] = {};
-  //         }
-  //         config[el.ns][el.key] = JSON.parse(el.value);
-  //       });
-
-  //       debug('Config loaded', config);
-
-  //       // initialize custom css/script
-  //       Config.initCustomCss(config);
-  //       Config.initCustomScript(config);
-
-  //       return callback(null, config);
-  //     });
-  // };
-
-  configSchema.statics.getLocalconfig = function() { // CONF.RF: これも別のメソッドにする
+  configSchema.statics.getLocalconfig = function() {
     const env = process.env;
     const env = process.env;
 
 
     const localConfig = {
     const localConfig = {
@@ -313,37 +193,7 @@ module.exports = function(crowi) {
     return localConfig;
     return localConfig;
   };
   };
 
 
-  configSchema.statics.userUpperLimit = function(crowi) {
-    const key = 'USER_UPPER_LIMIT';
-    const env = crowi.env[key];
-
-    if (undefined === crowi.env || undefined === crowi.env[key]) {
-      return 0;
-    }
-    return Number(env);
-  };
-
-  /*
-  configSchema.statics.isInstalled = function(config)
-  {
-    if (!config.crowi) {
-      return false;
-    }
-
-    if (config.crowi['app:installed']
-       && config.crowi['app:installed'] !== '0.0.0') {
-      return true;
-    }
-
-    return false;
-  }
-  */
-
   const Config = mongoose.model('Config', configSchema);
   const Config = mongoose.model('Config', configSchema);
-  Config.SECURITY_REGISTRATION_MODE_OPEN = SECURITY_REGISTRATION_MODE_OPEN;
-  Config.SECURITY_REGISTRATION_MODE_RESTRICTED = SECURITY_REGISTRATION_MODE_RESTRICTED;
-  Config.SECURITY_REGISTRATION_MODE_CLOSED = SECURITY_REGISTRATION_MODE_CLOSED;
-
 
 
   return Config;
   return Config;
 };
 };

+ 9 - 10
src/server/models/user.js

@@ -78,8 +78,7 @@ module.exports = function(crowi) {
   function decideUserStatusOnRegistration() {
   function decideUserStatusOnRegistration() {
     validateCrowi();
     validateCrowi();
 
 
-    const Config = crowi.model('Config');
-    const configManager = crowi.configManager;
+    const { configManager, aclService } = crowi;
 
 
     const isInstalled = configManager.getConfig('crowi', 'app:installed');
     const isInstalled = configManager.getConfig('crowi', 'app:installed');
     if (!isInstalled) {
     if (!isInstalled) {
@@ -89,10 +88,10 @@ module.exports = function(crowi) {
     // status decided depends on registrationMode
     // status decided depends on registrationMode
     const registrationMode = configManager.getConfig('crowi', 'security:registrationMode');
     const registrationMode = configManager.getConfig('crowi', 'security:registrationMode');
     switch (registrationMode) {
     switch (registrationMode) {
-      case Config.SECURITY_REGISTRATION_MODE_OPEN:
+      case aclService.labels.SECURITY_REGISTRATION_MODE_OPEN:
         return STATUS_ACTIVE;
         return STATUS_ACTIVE;
-      case Config.SECURITY_REGISTRATION_MODE_RESTRICTED:
-      case Config.SECURITY_REGISTRATION_MODE_CLOSED: // 一応
+      case aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED:
+      case aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED: // 一応
         return STATUS_REGISTERED;
         return STATUS_REGISTERED;
       default:
       default:
         return STATUS_ACTIVE; // どっちにすんのがいいんだろうな
         return STATUS_ACTIVE; // どっちにすんのがいいんだろうな
@@ -348,11 +347,10 @@ module.exports = function(crowi) {
   userSchema.statics.isEmailValid = function(email, callback) {
   userSchema.statics.isEmailValid = function(email, callback) {
     validateCrowi();
     validateCrowi();
 
 
-    const config = crowi.getConfig();
-    const whitelist = config.crowi['security:registrationWhiteList'];
+    const whitelist = crowi.configManager.getConfig('crowi', 'security:registrationWhiteList');
 
 
     if (Array.isArray(whitelist) && whitelist.length > 0) {
     if (Array.isArray(whitelist) && whitelist.length > 0) {
-      return config.crowi['security:registrationWhiteList'].some((allowedEmail) => {
+      return whitelist.some((allowedEmail) => {
         const re = new RegExp(`${allowedEmail}$`);
         const re = new RegExp(`${allowedEmail}$`);
         return re.test(email);
         return re.test(email);
       });
       });
@@ -511,8 +509,9 @@ module.exports = function(crowi) {
   };
   };
 
 
   userSchema.statics.isUserCountExceedsUpperLimit = async function() {
   userSchema.statics.isUserCountExceedsUpperLimit = async function() {
-    const Config = crowi.model('Config');
-    const userUpperLimit = Config.userUpperLimit(crowi);
+    const { aclService } = crowi;
+
+    const userUpperLimit = aclService.userUpperLimit();
     if (userUpperLimit === 0) {
     if (userUpperLimit === 0) {
       return false;
       return false;
     }
     }

+ 36 - 61
src/server/routes/admin.js

@@ -9,7 +9,6 @@ module.exports = function(crowi, app) {
   const ExternalAccount = models.ExternalAccount;
   const ExternalAccount = models.ExternalAccount;
   const UserGroup = models.UserGroup;
   const UserGroup = models.UserGroup;
   const UserGroupRelation = models.UserGroupRelation;
   const UserGroupRelation = models.UserGroupRelation;
-  const Config = models.Config;
   const GlobalNotificationSetting = models.GlobalNotificationSetting;
   const GlobalNotificationSetting = models.GlobalNotificationSetting;
   const GlobalNotificationMailSetting = models.GlobalNotificationMailSetting;
   const GlobalNotificationMailSetting = models.GlobalNotificationMailSetting;
   const GlobalNotificationSlackSetting = models.GlobalNotificationSlackSetting; // eslint-disable-line no-unused-vars
   const GlobalNotificationSlackSetting = models.GlobalNotificationSlackSetting; // eslint-disable-line no-unused-vars
@@ -97,11 +96,7 @@ module.exports = function(crowi, app) {
   // app.get('/admin/app'                  , admin.app.index);
   // app.get('/admin/app'                  , admin.app.index);
   actions.app = {};
   actions.app = {};
   actions.app.index = function(req, res) {
   actions.app.index = function(req, res) {
-    const settingForm = configManager.getConfigByPrefix('crowi', 'app:');
-
-    return res.render('admin/app', {
-      settingForm,
-    });
+    return res.render('admin/app');
   };
   };
 
 
   actions.app.settingUpdate = function(req, res) {
   actions.app.settingUpdate = function(req, res) {
@@ -110,10 +105,7 @@ module.exports = function(crowi, app) {
   // app.get('/admin/security'                  , admin.security.index);
   // app.get('/admin/security'                  , admin.security.index);
   actions.security = {};
   actions.security = {};
   actions.security.index = function(req, res) {
   actions.security.index = function(req, res) {
-    const settingForm = configManager.getConfigByPrefix('crowi', 'security:');
-    const isAclEnabled = aclService.getIsPublicWikiOnly();
-
-    return res.render('admin/security', { settingForm, isAclEnabled });
+    return res.render('admin/security');
   };
   };
 
 
   // app.get('/admin/markdown'                  , admin.markdown.index);
   // app.get('/admin/markdown'                  , admin.markdown.index);
@@ -236,26 +228,22 @@ module.exports = function(crowi, app) {
   };
   };
 
 
   // app.post('/admin/notification/slackSetting' , admin.notification.slackauth);
   // app.post('/admin/notification/slackSetting' , admin.notification.slackauth);
-  actions.notification.slackSetting = function(req, res) {
+  actions.notification.slackSetting = async function(req, res) {
     const slackSetting = req.form.slackSetting;
     const slackSetting = req.form.slackSetting;
 
 
-    req.session.slackSetting = slackSetting;
     if (req.form.isValid) {
     if (req.form.isValid) {
-      Config.updateNamespaceByArray('notification', slackSetting, (err, config) => {
-        Config.updateConfigCache('notification', config);
-        req.flash('successMessage', ['Successfully Updated!']);
-        req.session.slackSetting = null;
-
-        // Re-setup
-        crowi.setupSlack().then(() => {
-          return res.redirect('/admin/notification');
-        });
+      await configManager.updateConfigsInTheSameNamespace('notification', slackSetting);
+      req.flash('successMessage', ['Successfully Updated!']);
+
+      // Re-setup
+      crowi.setupSlack().then(() => {
       });
       });
     }
     }
     else {
     else {
       req.flash('errorMessage', req.form.errors);
       req.flash('errorMessage', req.form.errors);
-      return res.redirect('/admin/notification');
     }
     }
+
+    return res.redirect('/admin/notification');
   };
   };
 
 
   // app.get('/admin/notification/slackAuth'     , admin.notification.slackauth);
   // app.get('/admin/notification/slackAuth'     , admin.notification.slackauth);
@@ -268,19 +256,18 @@ module.exports = function(crowi, app) {
 
 
     const slack = crowi.slack;
     const slack = crowi.slack;
     slack.getOauthAccessToken(code)
     slack.getOauthAccessToken(code)
-      .then((data) => {
+      .then(async(data) => {
         debug('oauth response', data);
         debug('oauth response', data);
-        Config.updateNamespaceByArray('notification', { 'slack:token': data.access_token }, (err, config) => {
-          if (err) {
-            req.flash('errorMessage', ['Failed to save access_token. Please try again.']);
-          }
-          else {
-            Config.updateConfigCache('notification', config);
-            req.flash('successMessage', ['Successfully Connected!']);
-          }
 
 
-          return res.redirect('/admin/notification');
-        });
+        try {
+          await configManager.updateConfigsInTheSameNamespace('notification', { 'slack:token': data.access_token });
+          req.flash('successMessage', ['Successfully Connected!']);
+        }
+        catch (err) {
+          req.flash('errorMessage', ['Failed to save access_token. Please try again.']);
+        }
+
+        return res.redirect('/admin/notification');
       })
       })
       .catch((err) => {
       .catch((err) => {
         debug('oauth response ERROR', err);
         debug('oauth response ERROR', err);
@@ -309,13 +296,11 @@ module.exports = function(crowi, app) {
   };
   };
 
 
   // app.post('/admin/notification/slackSetting/disconnect' , admin.notification.disconnectFromSlack);
   // app.post('/admin/notification/slackSetting/disconnect' , admin.notification.disconnectFromSlack);
-  actions.notification.disconnectFromSlack = function(req, res) {
-    Config.updateNamespaceByArray('notification', { 'slack:token': '' }, (err, config) => {
-      Config.updateConfigCache('notification', config);
-      req.flash('successMessage', ['Successfully Disconnected!']);
+  actions.notification.disconnectFromSlack = async function(req, res) {
+    await configManager.updateConfigsInTheSameNamespace('notification', { 'slack:token': '' });
+    req.flash('successMessage', ['Successfully Disconnected!']);
 
 
-      return res.redirect('/admin/notification');
-    });
+    return res.redirect('/admin/notification');
   };
   };
 
 
   actions.globalNotification = {};
   actions.globalNotification = {};
@@ -422,8 +407,7 @@ module.exports = function(crowi, app) {
   actions.user = {};
   actions.user = {};
   actions.user.index = async function(req, res) {
   actions.user.index = async function(req, res) {
     const activeUsers = await User.countListByStatus(User.STATUS_ACTIVE);
     const activeUsers = await User.countListByStatus(User.STATUS_ACTIVE);
-    const Config = crowi.model('Config');
-    const userUpperLimit = Config.userUpperLimit(crowi);
+    const userUpperLimit = aclService.userUpperLimit();
     const isUserCountExceedsUpperLimit = await User.isUserCountExceedsUpperLimit();
     const isUserCountExceedsUpperLimit = await User.isUserCountExceedsUpperLimit();
 
 
     const page = parseInt(req.query.page) || 1;
     const page = parseInt(req.query.page) || 1;
@@ -859,14 +843,15 @@ module.exports = function(crowi, app) {
 
 
       // mail setting ならここで validation
       // mail setting ならここで validation
       if (form['mail:from']) {
       if (form['mail:from']) {
-        validateMailSetting(req, form, (err, data) => {
+        validateMailSetting(req, form, async(err, data) => {
           debug('Error validate mail setting: ', err, data);
           debug('Error validate mail setting: ', err, data);
           if (err) {
           if (err) {
             req.form.errors.push('SMTPを利用したテストメール送信に失敗しました。設定をみなおしてください。');
             req.form.errors.push('SMTPを利用したテストメール送信に失敗しました。設定をみなおしてください。');
             return res.json({ status: false, message: req.form.errors.join('\n') });
             return res.json({ status: false, message: req.form.errors.join('\n') });
           }
           }
 
 
-          return saveSetting(req, res, form);
+          await configManager.updateConfigsInTheSameNamespace('crowi', form);
+          return res.json({ status: true });
         });
         });
       }
       }
       else {
       else {
@@ -1190,8 +1175,10 @@ module.exports = function(crowi, app) {
       return res.json({ status: false, message: req.form.errors.join('\n') });
       return res.json({ status: false, message: req.form.errors.join('\n') });
     }
     }
 
 
-    await saveSetting(req, res, form);
-    await importer.initializeEsaClient();
+    await configManager.updateConfigsInTheSameNamespace('crowi', form);
+    importer.initializeEsaClient(); // let it run in the back aftert res
+
+    return res.json({ status: true });
   };
   };
 
 
   /**
   /**
@@ -1207,8 +1194,10 @@ module.exports = function(crowi, app) {
       return res.json({ status: false, message: req.form.errors.join('\n') });
       return res.json({ status: false, message: req.form.errors.join('\n') });
     }
     }
 
 
-    await saveSetting(req, res, form);
-    await importer.initializeQiitaClient();
+    await configManager.updateConfigsInTheSameNamespace('crowi', form);
+    importer.initializeQiitaClient(); // let it run in the back aftert res
+
+    return res.json({ status: true });
   };
   };
 
 
   /**
   /**
@@ -1343,20 +1332,6 @@ module.exports = function(crowi, app) {
     }
     }
   };
   };
 
 
-  /**
-   * save settings, update config cache, and response json
-   *
-   * @param {any} req
-   * @param {any} res
-   * @param {any} form
-   */
-  function saveSetting(req, res, form) {
-    Config.updateNamespaceByArray('crowi', form, (err, config) => {
-      Config.updateConfigCache('crowi', config);
-      return res.json({ status: true });
-    });
-  }
-
   function validateMailSetting(req, form, callback) {
   function validateMailSetting(req, form, callback) {
     const mailer = crowi.mailer;
     const mailer = crowi.mailer;
     const option = {
     const option = {

+ 0 - 20
src/server/routes/installer.js

@@ -89,26 +89,6 @@ module.exports = function(crowi, app) {
       req.flash('successMessage', 'GROWI のインストールが完了しました!はじめに、このページで各種設定を確認してください。');
       req.flash('successMessage', 'GROWI のインストールが完了しました!はじめに、このページで各種設定を確認してください。');
       return res.redirect('/admin/app');
       return res.redirect('/admin/app');
     });
     });
-
-    // Config.applicationInstall((err, configs) => {
-    //   if (err) {
-    //     logger.error(err);
-    //     return;
-    //   }
-
-    //   // save the globalLang config, and update the config cache
-    //   Config.updateNamespaceByArray('crowi', { 'app:globalLang': language }, (err, config) => {
-    //     Config.updateConfigCache('crowi', config);
-    //   });
-
-    //   // login with passport
-    //   req.logIn(adminUser, (err) => {
-    //     if (err) { return next() }
-
-    //     req.flash('successMessage', 'GROWI のインストールが完了しました!はじめに、このページで各種設定を確認してください。');
-    //     return res.redirect('/admin/app');
-    //   });
-    // });
   };
   };
 
 
   return actions;
   return actions;

+ 5 - 6
src/server/routes/login.js

@@ -8,10 +8,9 @@ module.exports = function(crowi, app) {
   const logger = require('@alias/logger')('growi:routes:login');
   const logger = require('@alias/logger')('growi:routes:login');
   const path = require('path');
   const path = require('path');
   const async = require('async');
   const async = require('async');
-  const config = crowi.getConfig();
   const mailer = crowi.getMailer();
   const mailer = crowi.getMailer();
   const User = crowi.model('User');
   const User = crowi.model('User');
-  const Config = crowi.model('Config');
+  const { configManager, appService, aclService } = crowi;
 
 
   const actions = {};
   const actions = {};
 
 
@@ -108,7 +107,7 @@ module.exports = function(crowi, app) {
     }
     }
 
 
     // config で closed ならさよなら
     // config で closed ならさよなら
-    if (config.crowi['security:registrationMode'] == Config.SECURITY_REGISTRATION_MODE_CLOSED) {
+    if (configManager.getConfig('crowi', 'security:registrationMode') == aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED) {
       return res.redirect('/');
       return res.redirect('/');
     }
     }
 
 
@@ -155,8 +154,8 @@ module.exports = function(crowi, app) {
 
 
 
 
           // 作成後、承認が必要なモードなら、管理者に通知する
           // 作成後、承認が必要なモードなら、管理者に通知する
-          const appTitle = Config.appTitle(config);
-          if (config.crowi['security:registrationMode'] === Config.SECURITY_REGISTRATION_MODE_RESTRICTED) {
+          const appTitle = appService.getAppTitle();
+          if (configManager.getConfig('crowi', 'security:registrationMode') === aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED) {
             // TODO send mail
             // TODO send mail
             User.findAdmins((err, admins) => {
             User.findAdmins((err, admins) => {
               async.each(
               async.each(
@@ -169,7 +168,7 @@ module.exports = function(crowi, app) {
                     vars: {
                     vars: {
                       createdUser: userData,
                       createdUser: userData,
                       adminUser,
                       adminUser,
-                      url: crowi.appService.getSiteUrl(),
+                      url: appService.getSiteUrl(),
                       appTitle,
                       appTitle,
                     },
                     },
                   },
                   },

+ 1 - 2
src/server/routes/page.js

@@ -8,7 +8,6 @@ module.exports = function(crowi, app) {
 
 
   const Page = crowi.model('Page');
   const Page = crowi.model('Page');
   const User = crowi.model('User');
   const User = crowi.model('User');
-  const config = crowi.getConfig();
   const Bookmark = crowi.model('Bookmark');
   const Bookmark = crowi.model('Bookmark');
   const PageTagRelation = crowi.model('PageTagRelation');
   const PageTagRelation = crowi.model('PageTagRelation');
   const UpdatePost = crowi.model('UpdatePost');
   const UpdatePost = crowi.model('UpdatePost');
@@ -98,7 +97,7 @@ module.exports = function(crowi, app) {
         logger.error('Error occured in updating slack channels: ', err);
         logger.error('Error occured in updating slack channels: ', err);
       });
       });
 
 
-    if (slackNotificationService.hasSlackConfig(config)) {
+    if (slackNotificationService.hasSlackConfig()) {
       const promises = slackChannels.split(',').map((chan) => {
       const promises = slackChannels.split(',').map((chan) => {
         return crowi.slack.postPage(page, user, chan, updateOrCreate, previousRevision);
         return crowi.slack.postPage(page, user, chan, updateOrCreate, previousRevision);
       });
       });

+ 36 - 8
src/server/service/acl.js

@@ -1,11 +1,5 @@
 const logger = require('@alias/logger')('growi:service:AclService'); // eslint-disable-line no-unused-vars
 const logger = require('@alias/logger')('growi:service:AclService'); // eslint-disable-line no-unused-vars
 
 
-// const SECURITY_RESTRICT_GUEST_MODE_DENY = 'Deny';
-const SECURITY_RESTRICT_GUEST_MODE_READONLY = 'Readonly';
-// const SECURITY_REGISTRATION_MODE_OPEN = 'Open';
-// const SECURITY_REGISTRATION_MODE_RESTRICTED = 'Resricted';
-// const SECURITY_REGISTRATION_MODE_CLOSED = 'Closed';
-
 /**
 /**
  * the service class of AclService
  * the service class of AclService
  */
  */
@@ -13,10 +7,16 @@ class AclService {
 
 
   constructor(configManager) {
   constructor(configManager) {
     this.configManager = configManager;
     this.configManager = configManager;
+    this.labels = {
+      SECURITY_RESTRICT_GUEST_MODE_DENY: 'Deny',
+      SECURITY_RESTRICT_GUEST_MODE_READONLY: 'Readonly',
+      SECURITY_REGISTRATION_MODE_OPEN: 'Open',
+      SECURITY_REGISTRATION_MODE_RESTRICTED: 'Resricted',
+      SECURITY_REGISTRATION_MODE_CLOSED: 'Closed',
+    };
   }
   }
 
 
   getIsPublicWikiOnly() {
   getIsPublicWikiOnly() {
-    // CONF.RF save PUBLIC_WIKI_ONLY in mongodb?
     const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
     const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
     if (publicWikiOnly === 'true' || publicWikiOnly === 1) {
     if (publicWikiOnly === 'true' || publicWikiOnly === 1) {
       return true;
       return true;
@@ -36,7 +36,35 @@ class AclService {
       return false;
       return false;
     }
     }
 
 
-    return SECURITY_RESTRICT_GUEST_MODE_READONLY === isRestrictGuestMode;
+    return this.labels.SECURITY_RESTRICT_GUEST_MODE_READONLY === isRestrictGuestMode;
+  }
+
+  getRestrictGuestModeLabels() {
+    const labels = {};
+    labels[this.labels.SECURITY_RESTRICT_GUEST_MODE_DENY] = 'security_setting.guest_mode.deny';
+    labels[this.labels.SECURITY_RESTRICT_GUEST_MODE_READONLY] = 'security_setting.guest_mode.readonly';
+
+    return labels;
+  }
+
+  getRegistrationModeLabels() {
+    const labels = {};
+    labels[this.labelsSECURITY_REGISTRATION_MODE_OPEN] = 'security_setting.registration_mode.open';
+    labels[this.labelsSECURITY_REGISTRATION_MODE_RESTRICTED] = 'security_setting.registration_mode.restricted';
+    labels[this.labels.SECURITY_REGISTRATION_MODE_CLOSED] = 'security_setting.registration_mode.closed';
+
+    return labels;
+  }
+
+  userUpperLimit() {
+    // const limit = this.configManager.getConfig('crowi', 'USER_UPPER_LIMIT');
+    const limit = process.env.USER_UPPER_LIMIT;
+
+    if (limit) {
+      return Number(limit);
+    }
+
+    return 0;
   }
   }
 
 
 }
 }

+ 7 - 2
src/server/service/config-manager.js

@@ -48,11 +48,16 @@ class ConfigManager {
    * - undefined: a specified config does not exist.
    * - undefined: a specified config does not exist.
    */
    */
   getConfig(namespace, key) {
   getConfig(namespace, key) {
+    let value;
+
     if (this.searchOnlyFromEnvVarConfigs('crowi', 'security:passport-saml:useOnlyEnvVarsForSomeOptions')) {
     if (this.searchOnlyFromEnvVarConfigs('crowi', 'security:passport-saml:useOnlyEnvVarsForSomeOptions')) {
-      return this.searchInSAMLUseOnlyEnvMode(namespace, key);
+      value = this.searchInSAMLUseOnlyEnvMode(namespace, key);
     }
     }
 
 
-    return this.defaultSearch(namespace, key);
+    value = this.defaultSearch(namespace, key);
+
+    logger.debug(key, value);
+    return value;
   }
   }
 
 
   /**
   /**

+ 6 - 6
src/server/service/file-uploader/aws.js

@@ -6,15 +6,15 @@ const aws = require('aws-sdk');
 
 
 module.exports = function(crowi) {
 module.exports = function(crowi) {
   const Uploader = require('./uploader');
   const Uploader = require('./uploader');
-  const lib = new Uploader(crowi.configManager);
+  const { configManager } = crowi;
+  const lib = new Uploader(configManager);
 
 
   function getAwsConfig() {
   function getAwsConfig() {
-    const config = crowi.getConfig();
     return {
     return {
-      accessKeyId: config.crowi['aws:accessKeyId'],
-      secretAccessKey: config.crowi['aws:secretAccessKey'],
-      region: config.crowi['aws:region'],
-      bucket: config.crowi['aws:bucket'],
+      accessKeyId: configManager.getConfig('crowi', 'aws:accessKeyId'),
+      secretAccessKey: configManager.getConfig('crowi', 'aws:secretAccessKey'),
+      region: configManager.getConfig('crowi', 'aws:region'),
+      bucket: configManager.getConfig('crowi', 'aws:bucket'),
     };
     };
   }
   }
 
 

+ 5 - 6
src/server/util/middlewares.js

@@ -5,7 +5,7 @@ const md5 = require('md5');
 const entities = require('entities');
 const entities = require('entities');
 
 
 module.exports = (crowi, app) => {
 module.exports = (crowi, app) => {
-  const { appService } = crowi;
+  const { configManager, appService } = crowi;
 
 
   const middlewares = {};
   const middlewares = {};
 
 
@@ -275,11 +275,10 @@ module.exports = (crowi, app) => {
 
 
   middlewares.awsEnabled = function() {
   middlewares.awsEnabled = function() {
     return function(req, res, next) {
     return function(req, res, next) {
-      const config = req.config;
-      if (config.crowi['aws:region'] !== ''
-          && config.crowi['aws:bucket'] !== ''
-          && config.crowi['aws:accessKeyId'] !== ''
-          && config.crowi['aws:secretAccessKey'] !== '') {
+      if (configManager.getConfig('crowi', 'aws:region') !== ''
+          && configManager.getConfig('crowi', 'aws:bucket') !== ''
+          && configManager.getConfig('crowi', 'aws:accessKeyId') !== ''
+          && configManager.getConfig('crowi', 'aws:secretAccessKey') !== '') {
         req.flash('globalError', 'AWS settings required to use this function. Please ask the administrator.');
         req.flash('globalError', 'AWS settings required to use this function. Please ask the administrator.');
         return res.redirect('/');
         return res.redirect('/');
       }
       }

+ 2 - 3
src/server/util/slack.js

@@ -8,7 +8,6 @@ const urljoin = require('url-join');
 /* eslint-disable no-use-before-define */
 /* eslint-disable no-use-before-define */
 
 
 module.exports = function(crowi) {
 module.exports = function(crowi) {
-  const config = crowi.getConfig();
   const Slack = require('slack-node');
   const Slack = require('slack-node');
   const { configManager } = crowi;
   const { configManager } = crowi;
 
 
@@ -17,7 +16,7 @@ module.exports = function(crowi) {
   const postWithIwh = function(messageObj) {
   const postWithIwh = function(messageObj) {
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
       const client = new Slack();
       const client = new Slack();
-      client.setWebhook(config.notification['slack:incomingWebhookUrl']);
+      client.setWebhook(configManager.getConfig('notification', 'slack:incomingWebhookUrl'));
       client.webhook(messageObj, (err, res) => {
       client.webhook(messageObj, (err, res) => {
         if (err) {
         if (err) {
           debug('Post error', err, res);
           debug('Post error', err, res);
@@ -31,7 +30,7 @@ module.exports = function(crowi) {
 
 
   const postWithWebApi = function(messageObj) {
   const postWithWebApi = function(messageObj) {
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
-      const client = new Slack(config.notification['slack:token']);
+      const client = new Slack(configManager.getConfig('notification', 'slack:token'));
       // stringify attachments
       // stringify attachments
       if (messageObj.attachments != null) {
       if (messageObj.attachments != null) {
         messageObj.attachments = JSON.stringify(messageObj.attachments);
         messageObj.attachments = JSON.stringify(messageObj.attachments);

+ 12 - 12
src/server/views/admin/app.html

@@ -45,7 +45,7 @@
                    id="settingForm[app:title]"
                    id="settingForm[app:title]"
                    type="text"
                    type="text"
                    name="settingForm[app:title]"
                    name="settingForm[app:title]"
-                   value="{{ settingForm['app:title'] | default('') }}"
+                   value="{{ getConfig('crowi', 'app:title') | default('') }}"
                    placeholder="GROWI">
                    placeholder="GROWI">
             <p class="help-block">{{ t("app_setting.sitename_change") }}</p>
             <p class="help-block">{{ t("app_setting.sitename_change") }}</p>
           </div>
           </div>
@@ -58,7 +58,7 @@
                    id="settingForm[app:confidential]"
                    id="settingForm[app:confidential]"
                    type="text"
                    type="text"
                    name="settingForm[app:confidential]"
                    name="settingForm[app:confidential]"
-                   value="{{ settingForm['app:confidential'] | default('') }}"
+                   value="{{ getConfig('crowi', 'app:confidential') | default('') }}"
                    placeholder="{{ t('app_setting. ex&rpar;: internal use only') }}">
                    placeholder="{{ t('app_setting. ex&rpar;: internal use only') }}">
             <p class="help-block">{{ t("app_setting.header_content") }}</p>
             <p class="help-block">{{ t("app_setting.header_content") }}</p>
           </div>
           </div>
@@ -94,7 +94,7 @@
                      id="cbFileUpload"
                      id="cbFileUpload"
                      name="settingForm[app:fileUpload]"
                      name="settingForm[app:fileUpload]"
                      value="1"
                      value="1"
-                     {% if settingForm['app:fileUpload'] %}checked{% endif %}
+                     {% if getConfig('crowi', 'app:fileUpload') %}checked{% endif %}
                      {% if not fileUploadService.getIsUploadable() %}disabled="disabled"{% endif %}>
                      {% if not fileUploadService.getIsUploadable() %}disabled="disabled"{% endif %}>
               <label for="cbFileUpload">
               <label for="cbFileUpload">
                 {{ t("app_setting.enable_files_except_image") }}
                 {{ t("app_setting.enable_files_except_image") }}
@@ -181,7 +181,7 @@
                    type="text"
                    type="text"
                    name="settingForm[mail:from]"
                    name="settingForm[mail:from]"
                    placeholder="{{ t('eg') }} mail@growi.org"
                    placeholder="{{ t('eg') }} mail@growi.org"
-                   value="{{ settingForm['mail:from'] }}">
+                   value="{{ getConfig('crowi', 'mail:from') }}">
           </div>
           </div>
         </div>
         </div>
 
 
@@ -192,14 +192,14 @@
             <input class="form-control"
             <input class="form-control"
                    type="text"
                    type="text"
                    name="settingForm[mail:smtpHost]"
                    name="settingForm[mail:smtpHost]"
-                   value="{{ settingForm['mail:smtpHost']|default('') }}">
+                   value="{{ getConfig('crowi', 'mail:smtpHost') | default('') }}">
           </div>
           </div>
           <div class="col-xs-2">
           <div class="col-xs-2">
             <label>{{ t('app_setting.Port') }}</label>
             <label>{{ t('app_setting.Port') }}</label>
             <input class="form-control"
             <input class="form-control"
                    type="text"
                    type="text"
                    name="settingForm[mail:smtpPort]"
                    name="settingForm[mail:smtpPort]"
-                   value="{{ settingForm['mail:smtpPort']|default('') }}">
+                   value="{{ getConfig('crowi', 'mail:smtpPort') | default('') }}">
           </div>
           </div>
         </div>
         </div>
 
 
@@ -209,14 +209,14 @@
             <input class="form-control"
             <input class="form-control"
                    type="text"
                    type="text"
                    name="settingForm[mail:smtpUser]"
                    name="settingForm[mail:smtpUser]"
-                   value="{{ settingForm['mail:smtpUser']|default('') }}">
+                   value="{{ getConfig('crowi', 'mail:smtpUser') | default('') }}">
           </div>
           </div>
           <div class="col-xs-3">
           <div class="col-xs-3">
             <label>{{ t('Password') }}</label>
             <label>{{ t('Password') }}</label>
             <input class="form-control"
             <input class="form-control"
                    type="password"
                    type="password"
                    name="settingForm[mail:smtpPassword]"
                    name="settingForm[mail:smtpPassword]"
-                   value="{{ settingForm['mail:smtpPassword']|default('') }}">
+                   value="{{ getConfig('crowi', 'mail:smtpPassword') | default('') }}">
           </div>
           </div>
         </div>
         </div>
 
 
@@ -248,7 +248,7 @@
                    type="text"
                    type="text"
                    name="settingForm[aws:region]"
                    name="settingForm[aws:region]"
                    placeholder="例: ap-northeast-1"
                    placeholder="例: ap-northeast-1"
-                   value="{{ settingForm['aws:region'] }}">
+                   value="{{ getConfig('crowi', 'aws:region') | default('') }}">
           </div>
           </div>
         </div>
         </div>
 
 
@@ -260,7 +260,7 @@
                    type="text"
                    type="text"
                    name="settingForm[aws:bucket]"
                    name="settingForm[aws:bucket]"
                    placeholder="例: crowi"
                    placeholder="例: crowi"
-                   value="{{ settingForm['aws:bucket'] }}">
+                   value="{{ getConfig('crowi', 'aws:bucket') | default('') }}">
           </div>
           </div>
         </div>
         </div>
 
 
@@ -271,7 +271,7 @@
                    id="settingForm[aws:accessKeyId]"
                    id="settingForm[aws:accessKeyId]"
                    type="text"
                    type="text"
                    name="settingForm[aws:accessKeyId]"
                    name="settingForm[aws:accessKeyId]"
-                   value="{{ settingForm['aws:accessKeyId'] }}">
+                   value="{{ getConfig('crowi', 'aws:accessKeyId') | default('') }}">
           </div>
           </div>
 
 
         </div>
         </div>
@@ -283,7 +283,7 @@
                    id="settingForm[aws:secretAccessKey]"
                    id="settingForm[aws:secretAccessKey]"
                    type="text"
                    type="text"
                    name="settingForm[aws:secretAccessKey]"
                    name="settingForm[aws:secretAccessKey]"
-                   value="{{ settingForm['aws:secretAccessKey'] }}">
+                   value="{{ getConfig('crowi', 'aws:secretAccessKey') | default('') }}">
           </div>
           </div>
         </div>
         </div>
 
 

+ 10 - 10
src/server/views/admin/security.html

@@ -44,15 +44,15 @@
             <label for="settingForm[security:registrationMode]" class="col-xs-3 control-label">{{ t('Basic authentication') }}</label>
             <label for="settingForm[security:registrationMode]" class="col-xs-3 control-label">{{ t('Basic authentication') }}</label>
             <div class="col-xs-3">
             <div class="col-xs-3">
               <label for="">ID</label>
               <label for="">ID</label>
-              <input class="form-control" type="text" name="settingForm[security:basicName]" value="{{ settingForm['security:basicName']|default('') }}" autocomplete="nope" {% if not isAclEnabled  %}readonly{% endif%}>
+              <input class="form-control" type="text" name="settingForm[security:basicName]" value="{{ getConfig('crowi', 'security:basicName') | default('') }}" autocomplete="nope" {% if not aclService.getIsPublicWikiOnly()  %}readonly{% endif%}>
             </div>
             </div>
             <div class="col-xs-3">
             <div class="col-xs-3">
               <label for="">{{ t('Password') }}</label>
               <label for="">{{ t('Password') }}</label>
-              <input class="form-control" type="text" name="settingForm[security:basicSecret]" value="{{ settingForm['security:basicSecret']|default('') }}" autocomplete="nope" {% if not isAclEnabled  %}readonly{% endif%}>
+              <input class="form-control" type="text" name="settingForm[security:basicSecret]" value="{{ getConfig('crowi', 'security:basicSecret') | default('') }}" autocomplete="nope" {% if not aclService.getIsPublicWikiOnly()  %}readonly{% endif%}>
             </div>
             </div>
             <div class="col-xs-offset-3 col-xs-9">
             <div class="col-xs-offset-3 col-xs-9">
               <p class="help-block small">
               <p class="help-block small">
-                {% if not isAclEnabled %}
+                {% if not aclService.getIsPublicWikiOnly() %}
                   {{ t("security_setting.basic_acl_disable") }}<br>
                   {{ t("security_setting.basic_acl_disable") }}<br>
                 {% else %}
                 {% else %}
                   {{ t("security_setting.common_authentication") }}<br>
                   {{ t("security_setting.common_authentication") }}<br>
@@ -65,9 +65,9 @@
           <div class="form-group">
           <div class="form-group">
             <label for="settingForm[security:restrictGuestMode]" class="col-xs-3 control-label">{{ t('Guest users access') }}</label>
             <label for="settingForm[security:restrictGuestMode]" class="col-xs-3 control-label">{{ t('Guest users access') }}</label>
             <div class="col-xs-6">
             <div class="col-xs-6">
-              <select class="form-control selectpicker" name="settingForm[security:restrictGuestMode]" value="{{ settingForm['security:restrictGuestMode'] }}">
+              <select class="form-control selectpicker" name="settingForm[security:restrictGuestMode]" value="{{ getConfig('crowi', 'security:restrictGuestMode') }}">
                 {% for modeValue, modeLabel in consts.restrictGuestMode %}
                 {% for modeValue, modeLabel in consts.restrictGuestMode %}
-                <option value="{{ t(modeValue) }}" {% if modeValue == settingForm['security:restrictGuestMode'] %}selected{% endif %} >{{ t(modeLabel) }}</option>
+                <option value="{{ t(modeValue) }}" {% if modeValue == getConfig('crowi', 'security:restrictGuestMode') %}selected{% endif %} >{{ t(modeLabel) }}</option>
                 {% endfor %}
                 {% endfor %}
               </select>
               </select>
             </div>
             </div>
@@ -76,9 +76,9 @@
           <div class="form-group">
           <div class="form-group">
             <label for="settingForm[security:registrationMode]" class="col-xs-3 control-label">{{ t('Register limitation') }}</label>
             <label for="settingForm[security:registrationMode]" class="col-xs-3 control-label">{{ t('Register limitation') }}</label>
             <div class="col-xs-6">
             <div class="col-xs-6">
-              <select class="form-control selectpicker" name="settingForm[security:registrationMode]" value="{{ settingForm['security:registrationMode'] }}">
+              <select class="form-control selectpicker" name="settingForm[security:registrationMode]" value="{{ getConfig('crowi', 'security:registrationMode') }}">
                 {% for modeValue, modeLabel in consts.registrationMode %}
                 {% for modeValue, modeLabel in consts.registrationMode %}
-                <option value="{{ t(modeValue) }}" {% if modeValue == settingForm['security:registrationMode'] %}selected{% endif %} >{{ t(modeLabel) }}</option>
+                <option value="{{ t(modeValue) }}" {% if modeValue == getConfig('crowi', 'security:registrationMode') %}selected{% endif %} >{{ t(modeLabel) }}</option>
                 {% endfor %}
                 {% endfor %}
               </select>
               </select>
               <p class="help-block small">{{ t('The contents entered here will be shown in the header etc') }}</p>
               <p class="help-block small">{{ t('The contents entered here will be shown in the header etc') }}</p>
@@ -88,7 +88,7 @@
           <div class="form-group">
           <div class="form-group">
             <label for="settingForm[security:registrationWhiteList]" class="col-xs-3 control-label">{{ t('The whitelist of registration permission E-mail address') }}</label>
             <label for="settingForm[security:registrationWhiteList]" class="col-xs-3 control-label">{{ t('The whitelist of registration permission E-mail address') }}</label>
             <div class="col-xs-8">
             <div class="col-xs-8">
-              <textarea class="form-control" type="textarea" name="settingForm[security:registrationWhiteList]" placeholder="{{ t('security_setting.example') }}: @growi.org">{{ settingForm['security:registrationWhiteList']|join('&#13')|raw }}</textarea>
+              <textarea class="form-control" type="textarea" name="settingForm[security:registrationWhiteList]" placeholder="{{ t('security_setting.example') }}: @growi.org">{{ getConfig('crowi', 'security:registrationWhiteList') | join('&#13') | raw }}</textarea>
               <p class="help-block small">{{ t("security_setting.restrict_emails") }}{{ t("security_setting.for_instance") }}<code>@growi.org</code>{{ t("security_setting.only_those") }}<br>
               <p class="help-block small">{{ t("security_setting.restrict_emails") }}{{ t("security_setting.for_instance") }}<code>@growi.org</code>{{ t("security_setting.only_those") }}<br>
               {{ t("security_setting.insert_single") }}</p>
               {{ t("security_setting.insert_single") }}</p>
             </div>
             </div>
@@ -96,7 +96,7 @@
 
 
           <div class="form-group">
           <div class="form-group">
             {% set configName = 'settingForm[security:list-policy:hideRestrictedByOwner]' %}
             {% set configName = 'settingForm[security:list-policy:hideRestrictedByOwner]' %}
-            {% set configValue = settingForm['security:list-policy:hideRestrictedByOwner'] %}
+            {% set configValue = getConfig('crowi', 'security:list-policy:hideRestrictedByOwner') %}
             {% set isEnabled = !configValue %}
             {% set isEnabled = !configValue %}
             <label for="{{configName}}" class="col-xs-3 control-label">{{ t("security_setting.page_listing_1") }}</label>
             <label for="{{configName}}" class="col-xs-3 control-label">{{ t("security_setting.page_listing_1") }}</label>
             <div class="col-xs-9">
             <div class="col-xs-9">
@@ -117,7 +117,7 @@
 
 
           <div class="form-group">
           <div class="form-group">
             {% set configName = 'settingForm[security:list-policy:hideRestrictedByGroup]' %}
             {% set configName = 'settingForm[security:list-policy:hideRestrictedByGroup]' %}
-            {% set configValue = settingForm['security:list-policy:hideRestrictedByGroup'] %}
+            {% set configValue = getConfig('crowi', 'security:list-policy:hideRestrictedByGroup') %}
             {% set isEnabled = !configValue %}
             {% set isEnabled = !configValue %}
             <label for="{{configName}}" class="col-xs-3 control-label">{{ t("security_setting.page_listing_2") }}</label>
             <label for="{{configName}}" class="col-xs-3 control-label">{{ t("security_setting.page_listing_2") }}</label>
             <div class="col-xs-9">
             <div class="col-xs-9">

+ 2 - 2
src/server/views/layout/layout.html

@@ -154,8 +154,8 @@
         {% else %}
         {% else %}
         <li id="login-user"><a href="/login">Login</a></li>
         <li id="login-user"><a href="/login">Login</a></li>
         {% endif %}
         {% endif %}
-        {% if config.crowi['app:confidential'] && config.crowi['app:confidential'] != '' %}
-        <li class="confidential"><a href="#">{{ config.crowi['app:confidential'] }}</a></li>
+        {% if getConfig('crowi', 'app:confidential') %}
+        <li class="confidential"><a href="#">{{ getConfig('crowi', 'app:confidential') }}</a></li>
         {% endif %}
         {% endif %}
       </ul>
       </ul>
     </div><!-- /.navbar-header -->
     </div><!-- /.navbar-header -->

+ 5 - 5
src/server/views/login.html

@@ -228,7 +228,7 @@
 
 
         <div class="row">
         <div class="row">
           <div class="col-xs-12 text-right">
           <div class="col-xs-12 text-right">
-            {% if config.crowi['security:registrationMode'] != 'Closed' %}
+            {% if getConfig('crowi', 'security:registrationMode') != 'Closed' %}
             <a href="#register" id="register" class="link-switch">
             <a href="#register" id="register" class="link-switch">
               <i class="ti-check-box"></i> {{ t('Sign up is here') }}
               <i class="ti-check-box"></i> {{ t('Sign up is here') }}
             </a>
             </a>
@@ -240,9 +240,9 @@
       </div>
       </div>
 
 
 
 
-      {% if config.crowi['security:registrationMode'] != 'Closed' %}
+      {% if getConfig('crowi', 'security:registrationMode') != 'Closed' %}
       <div class="back">
       <div class="back">
-        {% if config.crowi['security:registrationMode'] == 'Restricted' %}
+        {% if getConfig('crowi', 'security:registrationMode') == 'Restricted' %}
         <p class="alert alert-warning">
         <p class="alert alert-warning">
           {{ t('page_register.notice.restricted') }}<br>
           {{ t('page_register.notice.restricted') }}<br>
           {{ t('page_register.notice.restricted_defail') }}
           {{ t('page_register.notice.restricted_defail') }}
@@ -267,12 +267,12 @@
             <span class="input-group-addon"><i class="icon-envelope"></i></span>
             <span class="input-group-addon"><i class="icon-envelope"></i></span>
             <input type="email" class="form-control" placeholder="{{ t('Email') }}" name="registerForm[email]" value="{{ req.body.registerForm.email }}" required>
             <input type="email" class="form-control" placeholder="{{ t('Email') }}" name="registerForm[email]" value="{{ req.body.registerForm.email }}" required>
           </div>
           </div>
-          {% if config.crowi['security:registrationWhiteList'] && config.crowi['security:registrationWhiteList'].length %}
+          {% if getConfig('crowi', 'security:registrationWhiteList') && getConfig('crowi', 'security:registrationWhiteList').length %}
           <p class="help-block">
           <p class="help-block">
             {{ t('page_register.form_help.email') }}
             {{ t('page_register.form_help.email') }}
           </p>
           </p>
           <ul>
           <ul>
-            {% for em in config.crowi['security:registrationWhiteList'] %}
+            {% for em in getConfig('crowi', 'security:registrationWhiteList') %}
             <li><code>{{ em }}</code></li>
             <li><code>{{ em }}</code></li>
             {% endfor %}
             {% endfor %}
           </ul>
           </ul>

+ 2 - 2
src/server/views/me/index.html

@@ -63,11 +63,11 @@
           <input class="form-control" type="email" name="userForm[email]" value="{{ user.email }}">
           <input class="form-control" type="email" name="userForm[email]" value="{{ user.email }}">
         </div>
         </div>
         <div class="col-sm-offset-2 col-sm-10">
         <div class="col-sm-offset-2 col-sm-10">
-          {% if config.crowi['security:registrationWhiteList'] && config.crowi['security:registrationWhiteList'].length %}
+          {% if getConfig('crowi', 'security:registrationWhiteList') && getConfig('crowi', 'security:registrationWhiteList').length %}
           <p class="help-block">
           <p class="help-block">
             {{ t('page_register.form_help.email') }}
             {{ t('page_register.form_help.email') }}
           <ul>
           <ul>
-            {% for em in config.crowi['security:registrationWhiteList'] %}
+            {% for em in getConfig('crowi', 'security:registrationWhiteList') %}
             <li><code>{{ em }}</code></li>
             <li><code>{{ em }}</code></li>
             {% endfor %}
             {% endfor %}
           </ul>
           </ul>