shinoka7 6 anni fa
parent
commit
ab51da13ac

+ 1 - 2
README.md

@@ -172,8 +172,7 @@ Environment Variables
     * MONGO_GRIDFS_TOTAL_LIMIT: Total capacity limit of MongoDB GridFS (bytes). default: `Infinity`
     * SAML_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS: If `true`, the system uses only the value of the environment variable as the value of the SAML option that can be set via the environment variable.
     * PUBLISH_OPEN_API: Publish GROWI OpenAPI resources with [ReDoc](https://github.com/Rebilly/ReDoc). Visit `/api-docs`.
-    * PUBLIC_WIKI_ONLY: Enable to make wiki public only.
-    * PRIVATE_WIKI_ONLY: Enable to make wiki private only.
+    * WIKI_MODE: Determines wiki mode (`public`, `private` or undefined). default: undefined
 * **Option to integrate with external systems**
     * HACKMD_URI: URI to connect to [HackMD(CodiMD)](https://hackmd.io/) server.
         * **This server must load the GROWI agent. [Here's how to prepare it](https://docs.growi.org/guide/admin-cookbook/integrate-with-hackmd.html).**

+ 1 - 2
config/env.dev.js

@@ -13,6 +13,5 @@ module.exports = {
   // PUBLISH_OPEN_API: true,
   // USER_UPPER_LIMIT: 0,
   // DEV_HTTPS: true,
-  // PUBLIC_WIKI_ONLY: true,
-  // PRIVATE_WIKI_ONLY: true,
+  // WIKI_MODE: 'private', // 'public', 'private', undefined
 };

+ 1 - 1
src/server/form/admin/securityGeneral.js

@@ -5,7 +5,7 @@ const stringToArray = require('../../util/formUtil').stringToArrayFilter;
 const normalizeCRLF = require('../../util/formUtil').normalizeCRLFFilter;
 
 module.exports = form(
-  field('settingForm[security:restrictGuestMode]').required(),
+  field('settingForm[security:restrictGuestMode]'),
   field('settingForm[security:registrationMode]').required(),
   field('settingForm[security:registrationWhiteList]').custom(normalizeCRLF).custom(stringToArray),
   field('settingForm[security:list-policy:hideRestrictedByOwner]').trim().toBooleanStrict(),

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

@@ -40,7 +40,6 @@ module.exports = function(crowi) {
       'app:fileUpload'    : false,
       'app:globalLang'    : 'en-US',
 
-      'security:disableGuestModeOption' : false,
       'security:restrictGuestMode'      : 'Deny',
 
       'security:registrationMode'      : 'Open',

+ 1 - 13
src/server/routes/admin.js

@@ -104,19 +104,7 @@ module.exports = function(crowi, app) {
 
   // app.get('/admin/security'                  , admin.security.index);
   actions.security = {};
-  actions.security.index = async function(req, res) {
-    const privateWikiOnly = !!process.env.PRIVATE_WIKI_ONLY;
-    const publicWikiOnly = !!process.env.PUBLIC_WIKI_ONLY;
-    // enable GuestModeOption only when privateWikiOnly AND publicWikiOnly are false/undefined
-    const enableGuestModeOption = !(privateWikiOnly || publicWikiOnly);
-
-    const disableGuestModeOption = configManager.getConfig('crowi', 'security:disableGuestModeOption');
-
-    // if equal, disableGuestModeOption needs to be updated
-    if (enableGuestModeOption === disableGuestModeOption) {
-      await configManager.updateConfigsInTheSameNamespace('crowi', { 'security:disableGuestModeOption': !enableGuestModeOption });
-    }
-
+  actions.security.index = function(req, res) {
     return res.render('admin/security');
   };
 

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

@@ -17,22 +17,20 @@ class AclService {
   }
 
   isAclEnabled() {
-    const isPublicWikiOnly = this.configManager.getConfig('crowi', 'security:isPublicWikiOnly');
-    const isPrivateWikiOnly = this.configManager.getConfig('crowi', 'security:isPrivateWikiOnly');
+    const wikiMode = this.configManager.getConfig('crowi', 'security:wikiMode');
 
-    return !(isPublicWikiOnly || isPrivateWikiOnly);
+    return wikiMode === undefined;
   }
 
   getIsGuestAllowedToRead() {
-    const isPublicWikiOnly = this.configManager.getConfig('crowi', 'security:isPublicWikiOnly');
-    const isPrivateWikiOnly = this.configManager.getConfig('crowi', 'security:isPrivateWikiOnly');
+    const wikiMode = this.configManager.getConfig('crowi', 'security:wikiMode');
 
     // return false if private wiki mode
-    if (isPrivateWikiOnly) {
+    if (wikiMode === 'private') {
       return false;
     }
-    // return true if puclic wiki mode
-    if (isPublicWikiOnly) {
+    // return true if public wiki mode
+    if (wikiMode === 'public') {
       return true;
     }
 

+ 4 - 10
src/server/service/config-loader.js

@@ -134,17 +134,11 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    TYPES.NUMBER,
     default: Infinity,
   },
-  PUBLIC_WIKI_ONLY: {
+  WIKI_MODE: {
     ns:      'crowi',
-    key:     'security:isPublicWikiOnly',
-    type:    TYPES.BOOLEAN,
-    default: false,
-  },
-  PRIVATE_WIKI_ONLY: {
-    ns:      'crowi',
-    key:     'security:isPrivateWikiOnly',
-    type:    TYPES.BOOLEAN,
-    default: false,
+    key:     'security:wikiMode',
+    type:    TYPES.STRING,
+    default: undefined,
   },
   SAML_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS: {
     ns:      'crowi',

+ 1 - 2
src/server/views/admin/security.html

@@ -45,9 +45,8 @@
             <div class="col-xs-6">
               <select class="form-control selectpicker" name="settingForm[security:restrictGuestMode]" value="{{ getConfig('crowi', 'security:restrictGuestMode') }}">
                 {% for modeValue, modeLabel in consts.restrictGuestMode %}
-                <option value="{{ t(modeValue) }}" {% if modeValue == getConfig('crowi', 'security:restrictGuestMode') %}selected{% endif %} {% if getConfig('crowi', 'security:disableGuestModeOption') %}disabled{% endif %}>{{ t(modeLabel) }}</option>
+                <option value="{{ t(modeValue) }}" {% if modeValue == getConfig('crowi', 'security:restrictGuestMode') %}selected{% endif %} {% if getConfig('crowi', 'security:wikiMode') %}disabled{% endif %}>{{ t(modeLabel) }}</option>
                 {% endfor %}
-                <option value="{{ getConfig('crowi', 'security:restrictGuestMode') }}" {% if getConfig('crowi', 'security:disableGuestModeOption') %}selected{% endif %} style="display:none;"> Public/Private Wiki Only is Enabled </option>
               </select>
             </div>
           </div>