فهرست منبع

Merge pull request #633 from weseek/feat/gc-1100-acl-on-off-environment-variable

gc-1100-acl_enable-environment-setting-add
Yuki Takei 7 سال پیش
والد
کامیت
dab1f66dfd

+ 1 - 0
config/env.dev.js

@@ -9,4 +9,5 @@ module.exports = {
     // 'growi-plugin-pukiwiki-like-linker',
     // 'growi-plugin-pukiwiki-like-linker',
   ],
   ],
   // DEV_HTTPS: true,
   // DEV_HTTPS: true,
+  // PUBLIC_WIKI_ONLY: true,
 };
 };

+ 1 - 0
resource/locales/en-US/translation.json

@@ -298,6 +298,7 @@
 		"Selecting authentication mechanism": "Selecting authentication mechanism",
 		"Selecting authentication mechanism": "Selecting authentication mechanism",
 		"common_authentication": "If you set the basic authentication, common authentication is applied on the whole page.",
 		"common_authentication": "If you set the basic authentication, common authentication is applied on the whole page.",
 		"without_encryption": "Please be noted that your ID and Password will be sent wihtout encryption.",
 		"without_encryption": "Please be noted that your ID and Password will be sent wihtout encryption.",
+		"basic_acl_disable": "Because of Public Wiki  setting, basic authentication can not be used.",
 		"users_without_account": "Users without account is not accessible",
 		"users_without_account": "Users without account is not accessible",
     "example": "Example",
     "example": "Example",
     "restrict_emails": "You can restrict registerable e-mail address.",
     "restrict_emails": "You can restrict registerable e-mail address.",

+ 1 - 0
resource/locales/ja/translation.json

@@ -317,6 +317,7 @@
     "Selecting authentication mechanism": "認証機構選択",
     "Selecting authentication mechanism": "認証機構選択",
     "common_authentication": "Basic認証を設定すると、ページ全体に共通の認証がかかります。",
     "common_authentication": "Basic認証を設定すると、ページ全体に共通の認証がかかります。",
     "without_encryption": "IDとパスワードは暗号化されずに送信されるのでご注意下さい。",
     "without_encryption": "IDとパスワードは暗号化されずに送信されるのでご注意下さい。",
+    "basic_acl_disable": "Public Wiki の設定のため、Basic認証は利用できません。",
     "users_without_account": "アカウントを持たないユーザーはアクセス不可",
     "users_without_account": "アカウントを持たないユーザーはアクセス不可",
     "example": "例",
     "example": "例",
     "restrict_emails": "登録可能なメールアドレスを制限することができます。",
     "restrict_emails": "登録可能なメールアドレスを制限することができます。",

+ 16 - 11
src/client/js/components/SavePageControls.jsx

@@ -42,6 +42,8 @@ class SavePageControls extends React.PureComponent {
   render() {
   render() {
     const { t } = this.props;
     const { t } = this.props;
 
 
+    const config = this.props.crowi.getConfig();
+    const isAclEnabled = config.isAclEnabled;
     const label = this.state.pageId == null ? t('Create') : t('Update');
     const label = this.state.pageId == null ? t('Create') : t('Update');
 
 
     return (
     return (
@@ -56,17 +58,20 @@ class SavePageControls extends React.PureComponent {
               slackChannels={this.props.slackChannels} />
               slackChannels={this.props.slackChannels} />
         </div>
         </div>
 
 
-        <div className="mr-2">
-          <GrantSelector crowi={this.props.crowi}
-              ref={(elem) => {
-                if (this.refs.grantSelector == null) {
-                  this.refs.grantSelector = elem.getWrappedInstance();
-                }
-              }}
-              grant={this.props.grant}
-              grantGroupId={this.props.grantGroupId}
-              grantGroupName={this.props.grantGroupName} />
-        </div>
+
+        {isAclEnabled &&
+          <div className="mr-2">
+            <GrantSelector crowi={this.props.crowi}
+                ref={(elem) => {
+                  if (this.refs.grantSelector == null) {
+                    this.refs.grantSelector = elem.getWrappedInstance();
+                  }
+                }}
+                grant={this.props.grant}
+                grantGroupId={this.props.grantGroupId}
+                grantGroupName={this.props.grantGroupName} />
+          </div>
+        }
 
 
         <button className="btn btn-primary btn-submit" onClick={this.submit}>{label}</button>
         <button className="btn btn-primary btn-submit" onClick={this.submit}>{label}</button>
       </div>
       </div>

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

@@ -338,6 +338,11 @@ module.exports = function(crowi) {
   };
   };
 
 
   configSchema.statics.isGuesstAllowedToRead = function(config) {
   configSchema.statics.isGuesstAllowedToRead = function(config) {
+    // return true if puclic wiki mode
+    if (Config.isPublicWikiOnly(config)) {
+      return true;
+    }
+
     // return false if undefined
     // return false if undefined
     if (undefined === config.crowi || undefined === config.crowi['security:restrictGuestMode']) {
     if (undefined === config.crowi || undefined === config.crowi['security:restrictGuestMode']) {
       return false;
       return false;
@@ -360,6 +365,13 @@ module.exports = function(crowi) {
     const key = 'markdown:isEnabledLinebreaksInComments';
     const key = 'markdown:isEnabledLinebreaksInComments';
     return getValueForMarkdownNS(config, key);
     return getValueForMarkdownNS(config, key);
   };
   };
+  configSchema.statics.isPublicWikiOnly = function(config) {
+    const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
+    if ( publicWikiOnly === 'true' || publicWikiOnly == 1) {
+      return true;
+    }
+    return false;
+  };
 
 
   configSchema.statics.pageBreakSeparator = function(config) {
   configSchema.statics.pageBreakSeparator = function(config) {
     const key = 'markdown:presentation:pageBreakSeparator';
     const key = 'markdown:presentation:pageBreakSeparator';
@@ -592,6 +604,7 @@ module.exports = function(crowi) {
         MATHJAX: env.MATHJAX || null,
         MATHJAX: env.MATHJAX || null,
       },
       },
       recentCreatedLimit: Config.showRecentCreatedNumber(config),
       recentCreatedLimit: Config.showRecentCreatedNumber(config),
+      isAclEnabled: !Config.isPublicWikiOnly(config),
     };
     };
 
 
     return local_config;
     return local_config;

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

@@ -104,7 +104,8 @@ module.exports = function(crowi, app) {
   actions.security = {};
   actions.security = {};
   actions.security.index = function(req, res) {
   actions.security.index = function(req, res) {
     const settingForm = Config.setupCofigFormData('crowi', req.config);
     const settingForm = Config.setupCofigFormData('crowi', req.config);
-    return res.render('admin/security', { settingForm });
+    const isAclEnabled = !Config.isPublicWikiOnly(req.config);
+    return res.render('admin/security', { settingForm, isAclEnabled });
   };
   };
 
 
   // app.get('/admin/markdown'                  , admin.markdown.index);
   // app.get('/admin/markdown'                  , admin.markdown.index);
@@ -669,10 +670,12 @@ module.exports = function(crowi, app) {
   actions.userGroup = {};
   actions.userGroup = {};
   actions.userGroup.index = function(req, res) {
   actions.userGroup.index = function(req, res) {
     var page = parseInt(req.query.page) || 1;
     var page = parseInt(req.query.page) || 1;
+    const isAclEnabled = !Config.isPublicWikiOnly(req.config);
     var renderVar = {
     var renderVar = {
       userGroups: [],
       userGroups: [],
       userGroupRelations: new Map(),
       userGroupRelations: new Map(),
       pager: null,
       pager: null,
+      isAclEnabled,
     };
     };
 
 
     UserGroup.findUserGroupsWithPagination({ page: page })
     UserGroup.findUserGroupsWithPagination({ page: page })
@@ -1030,6 +1033,21 @@ module.exports = function(crowi, app) {
 
 
   actions.api.securitySetting = function(req, res) {
   actions.api.securitySetting = function(req, res) {
     const form = req.form.settingForm;
     const form = req.form.settingForm;
+    const config = crowi.getConfig();
+    const isPublicWikiOnly = Config.isPublicWikiOnly(config);
+    if (isPublicWikiOnly) {
+      const basicName = form['security:basicName'];
+      const basicSecret = form['security:basicSecret'];
+      if (basicName != '' || basicSecret != '') {
+        req.form.errors.push('Public Wikiのため、Basic認証は利用できません。');
+        return res.json({status: false, message: req.form.errors.join('\n')});
+      }
+      const guestMode = form['security:restrictGuestMode'];
+      if ( guestMode == 'Deny' ) {
+        req.form.errors.push('Private Wikiへの設定変更はできません。');
+        return res.json({status: false, message: req.form.errors.join('\n')});
+      }
+    }
 
 
     if (req.form.isValid) {
     if (req.form.isValid) {
       debug('form content', form);
       debug('form content', form);

+ 9 - 4
src/server/views/admin/security.html

@@ -44,16 +44,20 @@
             <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('') }}">
+              <input class="form-control" type="text" name="settingForm[security:basicName]"   value="{{ settingForm['security:basicName']|default('') }}" {% if not isAclEnabled  %}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('') }}">
+              <input class="form-control" type="text" name="settingForm[security:basicSecret]" value="{{ settingForm['security:basicSecret']|default('') }}" {% if not isAclEnabled  %}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">
               <p class="help-block">
-                {{ t("security_setting.common_authentication") }}<br>
-                {{ t("security_setting.without_encryption") }}<br>
+                {% if not isAclEnabled %}
+                  {{ t("security_setting.basic_acl_disable") }}<br>
+                {% else %}
+                  {{ t("security_setting.common_authentication") }}<br>
+                  {{ t("security_setting.without_encryption") }}<br>
+                {% endif %}
               </p>
               </p>
             </div>
             </div>
           </div>
           </div>
@@ -301,6 +305,7 @@
       {
       {
         function showMessage(formId, msg, status) {
         function showMessage(formId, msg, status) {
           $('#' + formId + ' > .alert').remove();
           $('#' + formId + ' > .alert').remove();
+          $('#' + formId ).find('.alert').remove();
 
 
           if (!status) {
           if (!status) {
             status = 'success';
             status = 'success';

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

@@ -33,7 +33,11 @@
 
 
     <div class="col-md-9">
     <div class="col-md-9">
       <p>
       <p>
-        <button  data-toggle="collapse" class="btn btn-default" href="#createGroupForm">新規グループの作成</button>
+        {% if isAclEnabled %}
+          <button  data-toggle="collapse" class="btn btn-default" href="#createGroupForm">新規グループの作成</button>
+        {% else %}
+          現在の設定では新規グループの作成はできません。
+        {% endif %}
       </p>
       </p>
       <form role="form" action="/admin/user-group/create" method="post">
       <form role="form" action="/admin/user-group/create" method="post">
         <div id="createGroupForm" class="collapse">
         <div id="createGroupForm" class="collapse">
@@ -124,13 +128,18 @@
             <td>
             <td>
               <img src="{{ sGroup|picture }}" class="picture img-circle" />
               <img src="{{ sGroup|picture }}" class="picture img-circle" />
             </td>
             </td>
-            <td><a href="{{ sGroupDetailPageUrl }}">{{ sGroup.name | preventXss }}</a></td>
+            {% if isAclEnabled %}
+              <td><a href="{{ sGroupDetailPageUrl }}">{{ sGroup.name | preventXss }}</a></td>
+            {% else %}
+              <td>{{ sGroup.name | preventXss }}</td>
+            {% endif %}
             <td><ul class="list-inline">
             <td><ul class="list-inline">
               {% for relation in userGroupRelations.get(sGroup) %}
               {% for relation in userGroupRelations.get(sGroup) %}
               <li class="list-inline-item badge badge-primary">{{relation.relatedUser.username}}</li>
               <li class="list-inline-item badge badge-primary">{{relation.relatedUser.username}}</li>
               {% endfor %}
               {% endfor %}
             </ul></td>
             </ul></td>
             <td>{{ sGroup.createdAt|date('Y-m-d', sGroup.createdAt.getTimezoneOffset()) }}</td>
             <td>{{ sGroup.createdAt|date('Y-m-d', sGroup.createdAt.getTimezoneOffset()) }}</td>
+            {% if isAclEnabled %}
             <td>
             <td>
               <div class="btn-group admin-group-menu">
               <div class="btn-group admin-group-menu">
                 <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                 <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
@@ -156,6 +165,9 @@
                 </ul>
                 </ul>
               </div>
               </div>
             </td>
             </td>
+            {% else %}
+              <td></td>
+            {% endif %}
           </tr>
           </tr>
           {% endfor %}
           {% endfor %}
         </tbody>
         </tbody>