mizozobu 6 лет назад
Родитель
Сommit
3efa1d9bf9

+ 15 - 1
src/server/crowi/index.js

@@ -40,6 +40,7 @@ function Crowi(rootdir) {
   this.globalNotificationService = null;
   this.crowiSlackNotificationService = null;
   this.xssService = null;
+  this.aclService = null;
   this.restQiitaAPIService = null;
   this.cdnResourcesService = new CdnResourcesService();
   this.interceptorManager = new InterceptorManager();
@@ -85,6 +86,9 @@ Crowi.prototype.init = async function() {
     this.setupSlack(),
     this.setupCsrf(),
     this.setUpGlobalNotification(),
+    this.setUpCrowiSlacklNotification(),
+    this.setUpXss(),
+    this.setUpAcl(),
     this.setUpRestQiitaAPI(),
   ]);
 };
@@ -453,13 +457,23 @@ Crowi.prototype.setUpCrowiSlacklNotification = function() {
 /**
  * setup XssService
  */
-Crowi.prototype.setUpCrowiSlacklNotification = function() {
+Crowi.prototype.setUpXss = function() {
   const XssService = require('../service/xss');
   if (this.xssService == null) {
     this.xssService = new XssService(this);
   }
 };
 
+/**
+ * setup AclService
+ */
+Crowi.prototype.setUpAcl = function() {
+  const AclService = require('../service/acl');
+  if (this.aclService == null) {
+    this.aclService = new AclService(this);
+  }
+};
+
 /**
  * setup RestQiitaAPIService
  */

+ 44 - 0
src/server/service/acl.js

@@ -0,0 +1,44 @@
+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 GlobalNotificationSetting
+ */
+class AclService {
+
+  constructor(crowi) {
+    this.crowi = crowi;
+  }
+
+  getIsPublicWikiOnly() {
+    // CONF.RF save PUBLIC_WIKI_ONLY in mongodb?
+    const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
+    if (publicWikiOnly === 'true' || publicWikiOnly === 1) {
+      return true;
+    }
+    return false;
+  }
+
+  getIsGuestAllowedToRead() {
+    // return true if puclic wiki mode
+    if (this.getIsPublicWikiOnly()) {
+      return true;
+    }
+
+    // return false if undefined
+    const isRestrictGuestMode = this.crowi.configManager.getConfig('crowi', 'security:restrictGuestMode');
+    if (isRestrictGuestMode) {
+      return false;
+    }
+
+    return SECURITY_RESTRICT_GUEST_MODE_READONLY === isRestrictGuestMode;
+  }
+
+}
+
+module.exports = AclService;

+ 0 - 30
src/server/service/config-manager.js

@@ -108,36 +108,6 @@ class ConfigManager {
     return method !== 'none';
   }
 
-  getIsPublicWikiOnly() {
-    // CONF.RF save PUBLIC_WIKI_ONLY in mongodb?
-    const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
-    if (publicWikiOnly === 'true' || publicWikiOnly === 1) {
-      return true;
-    }
-    return false;
-  }
-
-  getIsGuestAllowedToRead() {
-    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';
-
-    // return true if puclic wiki mode
-    if (this.getIsPublicWikiOnly()) {
-      return true;
-    }
-
-    // return false if undefined
-    const isRestrictGuestMode = this.getConfig('crowi', 'security:restrictGuestMode');
-    if (isRestrictGuestMode) {
-      return false;
-    }
-
-    return SECURITY_RESTRICT_GUEST_MODE_READONLY === isRestrictGuestMode;
-  }
-
   /**
    * update configs in the same namespace
    *

+ 1 - 1
src/server/util/middlewares.js

@@ -207,7 +207,7 @@ module.exports = (crowi, app) => {
    * @param {boolean} isStrictly whethere strictly restricted (default true)
    */
   middlewares.loginRequired = function(isStrictly = true) {
-    const isGuestAllowedToRead = crowi.configManager.getIsGuestAllowedToRead();
+    const isGuestAllowedToRead = crowi.aclService.getIsGuestAllowedToRead();
 
     return function(req, res, next) {
       const User = crowi.model('User');