فهرست منبع

except site-url

mizozobu 6 سال پیش
والد
کامیت
142acdd5c9

+ 3 - 6
src/server/crowi/express-init.js

@@ -28,9 +28,6 @@ module.exports = function(crowi, app) {
   const configManager = crowi.configManager;
   const getConfig = configManager.getConfig;
 
-  // Service classes
-  const { siteUrlService } = crowi;
-
 
   const User = crowi.model('User');
   const lngDetector = new i18nMiddleware.LanguageDetector();
@@ -72,7 +69,7 @@ module.exports = function(crowi, app) {
     req.csrfToken = null;
 
     res.locals.req = req;
-    res.locals.baseUrl = siteUrlService.getSiteUrl();
+    res.locals.baseUrl = crowi.siteUrlService.getSiteUrl();
     // res.locals.config = config;
     res.locals.env = env;
     res.locals.now = now;
@@ -121,8 +118,8 @@ module.exports = function(crowi, app) {
       return next();
     }
 
-    const basicName = configManager.getConfig('crowi', 'security:basicName');
-    const basicSecret = configManager.getConfig('crowi', 'security:basicSecret');
+    const basicName = getConfig('crowi', 'security:basicName');
+    const basicSecret = getConfig('crowi', 'security:basicSecret');
     if (basicName && basicSecret) {
       return basicAuth(basicName, basicSecret)(req, res, next);
     }

+ 7 - 7
src/server/crowi/index.js

@@ -38,7 +38,7 @@ function Crowi(rootdir) {
   this.mailer = {};
   this.passportService = null;
   this.globalNotificationService = null;
-  this.crowiSlackNotificationService = null;
+  this.slackNotificationService = null;
   this.xssService = null;
   this.aclService = null;
   this.siteUrlService = null;
@@ -87,7 +87,7 @@ Crowi.prototype.init = async function() {
     this.setupSlack(),
     this.setupCsrf(),
     this.setUpGlobalNotification(),
-    this.setUpCrowiSlacklNotification(),
+    this.setUpSlacklNotification(),
     this.setUpXss(),
     this.setUpAcl(),
     this.setUpSiteUrl(),
@@ -447,12 +447,12 @@ Crowi.prototype.setUpGlobalNotification = function() {
 };
 
 /**
- * setup CrowiSlackNotificationService
+ * setup SlackNotificationService
  */
-Crowi.prototype.setUpCrowiSlacklNotification = function() {
-  const CrowiSlackNotificationService = require('../service/crowi-slack-notification');
-  if (this.crowiSlackNotificationService == null) {
-    this.crowiSlackNotificationService = new CrowiSlackNotificationService(this);
+Crowi.prototype.setUpSlacklNotification = function() {
+  const SlackNotificationService = require('../service/slack-notification');
+  if (this.slackNotificationService == null) {
+    this.slackNotificationService = new SlackNotificationService(this);
   }
 };
 

+ 4 - 4
src/server/service/acl.js

@@ -7,12 +7,12 @@ const SECURITY_RESTRICT_GUEST_MODE_READONLY = 'Readonly';
 // const SECURITY_REGISTRATION_MODE_CLOSED = 'Closed';
 
 /**
- * the service class of GlobalNotificationSetting
+ * the service class of AclService
  */
 class AclService {
 
-  constructor(crowi) {
-    this.crowi = crowi;
+  constructor(configManager) {
+    this.configManager = configManager;
   }
 
   getIsPublicWikiOnly() {
@@ -31,7 +31,7 @@ class AclService {
     }
 
     // return false if undefined
-    const isRestrictGuestMode = this.crowi.configManager.getConfig('crowi', 'security:restrictGuestMode');
+    const isRestrictGuestMode = this.configManager.getConfig('crowi', 'security:restrictGuestMode');
     if (isRestrictGuestMode) {
       return false;
     }

+ 17 - 6
src/server/service/config-manager.js

@@ -19,6 +19,7 @@ class ConfigManager {
     this.configModel = configModel;
     this.configLoader = new ConfigLoader(this.configModel);
     this.configObject = null;
+    this.configKeys = [];
 
     this.getConfig = this.getConfig.bind(this);
   }
@@ -29,6 +30,9 @@ class ConfigManager {
   async loadConfigs() {
     this.configObject = await this.configLoader.load();
     debug('ConfigManager#loadConfigs', this.configObject);
+
+    // cache all config keys
+    this.configKeys = this.getAllConfigKeys();
   }
 
   /**
@@ -52,14 +56,12 @@ class ConfigManager {
   }
 
   /**
-   * get a config specified by namespace and prefix
+   * get a config specified by namespace and regular expresssion
    */
-  getConfigByPrefix(namespace, prefix) {
-    const regexp = new RegExp(`^${prefix}:`);
-    const keys = this.getAllKeys();
+  getConfigByRegExp(namespace, regexp) {
     const result = {};
 
-    for (const key of keys) {
+    for (const key of this.configKeys) {
       if (regexp.test(key)) {
         result[key] = this.getConfig(namespace, key);
       }
@@ -68,10 +70,19 @@ class ConfigManager {
     return result;
   }
 
+  /**
+   * get a config specified by namespace and prefix
+   */
+  getConfigByPrefix(namespace, prefix) {
+    const regexp = new RegExp(`^${prefix}:`);
+
+    return this.getConfigByRegExp(namespace, regexp);
+  }
+
   /**
    * generate an array of config keys from this.configObject
    */
-  getAllKeys() {
+  getAllConfigKeys() {
     // type: fromDB, fromEnvVars
     const types = Object.keys(this.configObject);
     let namespaces = [];

+ 0 - 25
src/server/service/crowi-slack-notification.js

@@ -1,25 +0,0 @@
-const logger = require('@alias/logger')('growi:service:CrowiSlackNotification'); // eslint-disable-line no-unused-vars
-/**
- * the service class of GlobalNotificationSetting
- */
-class CrowiSlackNotificationService {
-
-  constructor(crowi) {
-    this.crowi = crowi;
-  }
-
-  hasSlackConfig() {
-    let hasSlackToken = false;
-    let hasSlackIwhUrl = false;
-
-    if (this.configObject.notification) {
-      hasSlackToken = !!this.crowi.configManager.getConfig('notification', 'slack:token');
-      hasSlackIwhUrl = !!this.crowi.configManager.getConfig('notification', 'slack:incomingWebhookUrl');
-    }
-
-    return hasSlackToken || hasSlackIwhUrl;
-  }
-
-}
-
-module.exports = CrowiSlackNotificationService;

+ 25 - 0
src/server/service/slack-notification.js

@@ -0,0 +1,25 @@
+const logger = require('@alias/logger')('growi:service:SlackNotification'); // eslint-disable-line no-unused-vars
+/**
+ * the service class of SlackNotificationService
+ */
+class SlackNotificationService {
+
+  constructor(configManager) {
+    this.configManager = configManager;
+  }
+
+  hasSlackConfig() {
+    let hasSlackToken = false;
+    let hasSlackIwhUrl = false;
+
+    if (this.configObject.notification) {
+      hasSlackToken = !!this.configManager.getConfig('notification', 'slack:token');
+      hasSlackIwhUrl = !!this.configManager.getConfig('notification', 'slack:incomingWebhookUrl');
+    }
+
+    return hasSlackToken || hasSlackIwhUrl;
+  }
+
+}
+
+module.exports = SlackNotificationService;

+ 9 - 9
src/server/service/xss.js

@@ -2,17 +2,17 @@ const logger = require('@alias/logger')('growi:service:XssSerivce'); // eslint-d
 const { tags, attrs } = require('@commons/service/xss/recommended-whitelist');
 
 /**
- * the service class of GlobalNotificationSetting
+ * the service class of XssSerivce
  */
 class XssSerivce {
 
-  constructor(crowi) {
-    this.crowi = crowi;
+  constructor(configManager) {
+    this.configManager = configManager;
   }
 
   getTagWhiteList() {
-    const isEnabledXssPrevention = this.crowi.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
-    const xssOpiton = this.crowi.configManager.getConfig('markdown', 'markdown:xss:option');
+    const isEnabledXssPrevention = this.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
+    const xssOpiton = this.configManager.getConfig('markdown', 'markdown:xss:option');
 
     if (isEnabledXssPrevention) {
       switch (xssOpiton) {
@@ -23,7 +23,7 @@ class XssSerivce {
           return tags;
 
         case 3: // custom white list
-          return this.crowi.configManager.getConfig('markdown', 'markdown:xss:tagWhiteList');
+          return this.configManager.getConfig('markdown', 'markdown:xss:tagWhiteList');
 
         default:
           return [];
@@ -35,8 +35,8 @@ class XssSerivce {
   }
 
   getAttrWhiteList() {
-    const isEnabledXssPrevention = this.crowi.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
-    const xssOpiton = this.crowi.configManager.getConfig('markdown', 'markdown:xss:option');
+    const isEnabledXssPrevention = this.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
+    const xssOpiton = this.configManager.getConfig('markdown', 'markdown:xss:option');
 
     if (isEnabledXssPrevention) {
       switch (xssOpiton) {
@@ -47,7 +47,7 @@ class XssSerivce {
           return attrs;
 
         case 3: // custom white list
-          return this.crowi.configManager.getConfig('markdown', 'markdown:xss:attrWhiteList');
+          return this.configManager.getConfig('markdown', 'markdown:xss:attrWhiteList');
 
         default:
           return [];