TsuyoshiSuzukief 7 лет назад
Родитель
Сommit
d78eabb735

+ 1 - 3
src/client/js/app.js

@@ -315,7 +315,6 @@ if (savePageControlsElem) {
   const grant = +savePageControlsElem.dataset.grant;
   const grantGroupId = savePageControlsElem.dataset.grantGroup;
   const grantGroupName = savePageControlsElem.dataset.grantGroupName;
-  const acl_enable = savePageControlsElem.dataset.aclEnable == 'true' ? true : false;
   ReactDOM.render(
     <I18nextProvider i18n={i18n}>
       <SavePageControls crowi={crowi} onSubmit={saveWithSubmitButton}
@@ -325,8 +324,7 @@ if (savePageControlsElem) {
             }
           }}
           pageId={pageId} pagePath={pagePath} slackChannels={slackChannels}
-          grant={grant} grantGroupId={grantGroupId} grantGroupName={grantGroupName} acl_enable={acl_enable}
-           />
+          grant={grant} grantGroupId={grantGroupId} grantGroupName={grantGroupName} />
     </I18nextProvider>,
     savePageControlsElem
   );

+ 3 - 4
src/client/js/components/SavePageControls.jsx

@@ -41,8 +41,8 @@ class SavePageControls extends React.PureComponent {
 
   render() {
     const { t } = this.props;
-
-    const acl_enable = this.props.acl_enable;
+    const config = this.props.crowi.getConfig();
+    const aclEnable = config.isEnabledAcl;
     const label = this.state.pageId == null ? t('Create') : t('Update');
 
     return (
@@ -58,7 +58,7 @@ class SavePageControls extends React.PureComponent {
         </div>
 
 
-        {acl_enable &&
+        {aclEnable &&
           <div className="mr-2">
             <GrantSelector crowi={this.props.crowi}
                 ref={(elem) => {
@@ -90,7 +90,6 @@ SavePageControls.propTypes = {
   grant: PropTypes.number,
   grantGroupId: PropTypes.string,
   grantGroupName: PropTypes.string,
-  acl_enable: PropTypes.bool,
 };
 
 export default translate()(SavePageControls);

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

@@ -48,10 +48,6 @@ module.exports = function(crowi) {
    */
   function getDefaultCrowiConfigs() {
     /* eslint-disable key-spacing */
-    let securityRestrictGuestMode = SECURITY_RESTRICT_GUEST_MODE_DENY;
-    if (process.env.ACL_ENABLE) {
-      securityRestrictGuestMode = SECURITY_RESTRICT_GUEST_MODE_READONLY;
-    }
 
     return {
       //'app:installed'     : "0.0.0",
@@ -59,7 +55,7 @@ module.exports = function(crowi) {
 
       'app:fileUpload'    : false,
 
-      'security:restrictGuestMode'      : securityRestrictGuestMode,
+      'security:restrictGuestMode'      : 'Deny',
 
       'security:registrationMode'      : 'Open',
       'security:registrationWhiteList' : [],
@@ -368,6 +364,10 @@ module.exports = function(crowi) {
 
     return config.markdown[key];
   };
+  configSchema.statics.isEnabledAcl = function(config) {
+    const aclEnable = !(process.env.ACL_ENABLE === 'false');
+    return aclEnable;
+  };
 
   configSchema.statics.pageBreakSeparator = function(config) {
     const key = 'markdown:presentation:pageBreakSeparator';
@@ -632,8 +632,10 @@ module.exports = function(crowi) {
         BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,
         HACKMD_URI: env.HACKMD_URI || null,
         MATHJAX: env.MATHJAX || null,
+        ACL_ENABLE: env.ACL_ENABLE || null,
       },
       recentCreatedLimit: Config.showRecentCreatedNumber(config),
+      isEnabledAcl: Config.isEnabledAcl(config),
     };
 
     return local_config;

+ 7 - 6
src/server/routes/admin.js

@@ -104,8 +104,8 @@ module.exports = function(crowi, app) {
   actions.security = {};
   actions.security.index = function(req, res) {
     const settingForm = Config.setupCofigFormData('crowi', req.config);
-    const acl_enable = process.env.ACL_ENABLE == 'true' ? true : false;
-    return res.render('admin/security', { settingForm, acl_enable });
+    const aclEnable = Config.isEnabledAcl(req.config);
+    return res.render('admin/security', { settingForm, aclEnable });
   };
 
   // app.get('/admin/markdown'                  , admin.markdown.index);
@@ -670,12 +670,12 @@ module.exports = function(crowi, app) {
   actions.userGroup = {};
   actions.userGroup.index = function(req, res) {
     var page = parseInt(req.query.page) || 1;
-    const acl_enable = process.env.ACL_ENABLE == 'true' ? true : false;
+    const aclEnable = Config.isEnabledAcl(req.config);
     var renderVar = {
       userGroups: [],
       userGroupRelations: new Map(),
       pager: null,
-      acl_enable,
+      aclEnable,
     };
 
     UserGroup.findUserGroupsWithPagination({ page: page })
@@ -1033,8 +1033,9 @@ module.exports = function(crowi, app) {
 
   actions.api.securitySetting = function(req, res) {
     const form = req.form.settingForm;
-    const acl_enable = process.env.ACL_ENABLE == 'true' ? true : false;
-    if (!acl_enable) {
+    const config = crowi.getConfig();
+    const aclEnable = Config.isEnabledAcl(config);
+    if (!aclEnable) {
       const basicName = form['security:basicName'];
       const basicSecret = form['security:basicSecret'];
       if (basicName != '' || basicSecret != '') {

+ 1 - 2
src/server/views/_form.html

@@ -18,8 +18,7 @@
   <div id="save-page-controls"
     data-grant="{{ page.grant }}"
     data-grant-group="{{ pageRelatedGroup._id.toString() }}"
-    data-grant-group-name="{{ pageRelatedGroup.name }}"
-    data-acl-enable="{{ process.env.ACL_ENABLE}}">
+    data-grant-group-name="{{ pageRelatedGroup.name }}">
   </div>
 
 </div>

+ 3 - 3
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>
             <div class="col-xs-3">
               <label for="">ID</label>
-              <input class="form-control" type="text" name="settingForm[security:basicName]"   value="{{ settingForm['security:basicName']|default('') }}" {% if not acl_enable  %}readonly{% endif%}>
+              <input class="form-control" type="text" name="settingForm[security:basicName]"   value="{{ settingForm['security:basicName']|default('') }}" {% if not aclEnable  %}readonly{% endif%}>
             </div>
             <div class="col-xs-3">
               <label for="">{{ t('Password') }}</label>
-              <input class="form-control" type="text" name="settingForm[security:basicSecret]" value="{{ settingForm['security:basicSecret']|default('') }}" {% if not acl_enable  %}readonly{% endif%}>
+              <input class="form-control" type="text" name="settingForm[security:basicSecret]" value="{{ settingForm['security:basicSecret']|default('') }}" {% if not aclEnable  %}readonly{% endif%}>
             </div>
             <div class="col-xs-offset-3 col-xs-9">
               <p class="help-block">
-                {% if not acl_enable %}
+                {% if not aclEnable %}
                   {{ t("security_setting.basic_acl_disable") }}<br>
                 {% else %}
                   {{ t("security_setting.common_authentication") }}<br>

+ 2 - 2
src/server/views/admin/user-groups.html

@@ -33,7 +33,7 @@
 
     <div class="col-md-9">
       <p>
-        {% if acl_enable %}
+        {% if aclEnable %}
           <button  data-toggle="collapse" class="btn btn-default" href="#createGroupForm">新規グループの作成</button>
         {% else %}
           現在の設定では新規グループの作成はできません。
@@ -135,7 +135,7 @@
               {% endfor %}
             </ul></td>
             <td>{{ sGroup.createdAt|date('Y-m-d', sGroup.createdAt.getTimezoneOffset()) }}</td>
-            {% if acl_enable %}
+            {% if aclEnable %}
             <td>
               <div class="btn-group admin-group-menu">
                 <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">