Просмотр исходного кода

Merge branch 'call-api-security-general-setting' into call-api-local-security-setting

# Conflicts:
#	src/client/js/services/AdminGeneralSecurityContainer.js
WESEEK Kaito 6 лет назад
Родитель
Сommit
3c272e8518

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

@@ -442,7 +442,7 @@
 
   "security_setting": {
     "Guest Users Access": "ゲストユーザーのアクセス",
-    "Fixed by env var": "環境変数 <code>%s=%s</code> により固定されています。",
+    "Fixed by env var": "環境変数 <code>{{forcewikimode}}={{wikimode}}</code> により固定されています。",
     "Register limitation": "登録の制限",
     "Register limitation desc": "新しいユーザーを登録する方法を制限します.",
     "The whitelist of registration permission E-mail address": "登録許可メールアドレスの<br>ホワイトリスト",

+ 29 - 4
src/client/js/components/Admin/Security/SecuritySetting.jsx

@@ -14,9 +14,24 @@ class SecuritySetting extends React.Component {
   constructor(props) {
     super(props);
 
+    this.state = {
+      retrieveError: null,
+    };
     this.putSecuritySetting = this.putSecuritySetting.bind(this);
   }
 
+  async componentDidMount() {
+    const { adminGeneralSecurityContainer } = this.props;
+
+    try {
+      await adminGeneralSecurityContainer.retrieveSecurityData();
+    }
+    catch (err) {
+      toastError(err);
+      this.setState({ retrieveError: err });
+    }
+  }
+
   async putSecuritySetting() {
     const { t } = this.props;
     try {
@@ -32,10 +47,19 @@ class SecuritySetting extends React.Component {
     const { t, adminGeneralSecurityContainer } = this.props;
     const helpPageListingByOwner = { __html: t('security_setting.page_listing_1') };
     const helpPageListingByGroup = { __html: t('security_setting.page_listing_2') };
+    // eslint-disable-next-line max-len
+    const helpForceWikiMode = { __html: t('security_setting.Fixed by env var', { forcewikimode: 'FORCE_WIKI_MODE' }, { wikimode: adminGeneralSecurityContainer.state.wikiMode }) };
+
+
     return (
       <React.Fragment>
         <fieldset>
           <legend className="alert-anchor">{ t('security_settings') }</legend>
+          {this.state.retrieveError != null && (
+            <div className="alert alert-danger">
+              <p>{t('Error occurred')} : {this.state.err}</p>
+            </div>
+          )}
           {/* TODO adjust layout */}
           <div className="row mb-5">
             <strong className="col-xs-3 text-right"> { t('security_setting.Guest Users Access') } </strong>
@@ -80,11 +104,12 @@ class SecuritySetting extends React.Component {
           </div>
           {adminGeneralSecurityContainer.state.isWikiModeForced && (
             <div className="row mb-5">
-              <div className="col-xs-6">
-                <p className="alert alert-warning mt-2">
+              <div className="col-xs-3 text-right" />
+              <div className="col-xs-9 text-left">
+                <p className="alert alert-warning mt-2 text-left">
                   <i className="icon-exclamation icon-fw">
-                  </i><b>FIXED</b>
-                  { t('security_setting.Fixed by env var', 'FORCE_WIKI_MODE') }<br></br>
+                  </i><b>FIXED</b><br />
+                  { <b dangerouslySetInnerHTML={helpForceWikiMode} /> }
                 </p>
               </div>
             </div>

+ 19 - 16
src/client/js/services/AdminGeneralSecurityContainer.js

@@ -17,8 +17,8 @@ export default class AdminGeneralSecurityContainer extends Container {
     this.appContainer = appContainer;
 
     this.state = {
-      // TODO GW-583 set value
       isWikiModeForced: false,
+      wikiMode: '',
       currentRestrictGuestMode: 'deny',
       currentPageCompleteDeletionAuthority: 'anyone',
       isHideRestrictedByOwner: true,
@@ -37,25 +37,19 @@ export default class AdminGeneralSecurityContainer extends Container {
       isTwitterOAuthEnabled: true,
     };
 
-    this.init();
-
-    this.switchIsLocalEnabled = this.switchIsLocalEnabled.bind(this);
-    this.changeRegistrationMode = this.changeRegistrationMode.bind(this);
-    this.changeRestrictGuestMode = this.changeRestrictGuestMode.bind(this);
-    this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
-    this.switchIsHideRestrictedByGroup = this.switchIsHideRestrictedByGroup.bind(this);
-    this.switchIsHideRestrictedByOwner = this.switchIsHideRestrictedByOwner.bind(this);
-    this.changePageCompleteDeletionAuthority = this.changePageCompleteDeletionAuthority.bind(this);
+    this.onIsWikiModeForced = this.onIsWikiModeForced.bind(this);
   }
 
-  async init() {
-    // TODO GW-583 fetch config value with api
+  async retrieveSecurityData() {
     const response = await this.appContainer.apiv3.get('/security-setting/');
-    const { localSetting } = response.data.securityParams;
+    const { generalSetting } = response.data.securityParams;
+    this.onIsWikiModeForced(generalSetting.wikiMode);
     this.setState({
-      isLocalEnabled: localSetting.LocalEnabledParams.isLocalEnabled,
-      registrationMode: localSetting.ModeParams.registrationMode,
-      registrationWhiteList: localSetting.WhiteListParams.registrationWhiteList,
+      currentRestrictGuestMode: generalSetting.restrictGuestMode || 'deny',
+      currentPageCompleteDeletionAuthority: generalSetting.pageCompleteDeletionAuthority || 'anyone',
+      isHideRestrictedByOwner: generalSetting.hideRestrictedByOwner || false,
+      isHideRestrictedByGroup: generalSetting.hideRestrictedByGroup || false,
+      wikiMode: generalSetting.wikiMode || '',
     });
   }
 
@@ -95,6 +89,15 @@ export default class AdminGeneralSecurityContainer extends Container {
     this.setState({ isHideRestrictedByGroup:  !this.state.isHideRestrictedByGroup });
   }
 
+  onIsWikiModeForced() {
+    if (this.state.wikiMode === 'private') {
+      this.setState({ isWikiModeForced: true });
+    }
+    else {
+      this.setState({ isWikiModeForced: false });
+    }
+  }
+
 
   /**
    * Update restrictGuestMode

+ 18 - 2
src/server/routes/apiv3/security-setting.js

@@ -69,6 +69,12 @@ const validator = {
  *                  pageCompleteDeletionAuthority:
  *                    type: string
  *                    description: type of pageDeletionAuthority
+ *              WikiModeParams:
+ *                type: object
+ *                properties:
+ *                  wikiMode:
+ *                    type: string
+ *                    description: type of wikiMode
  *              Function:
  *                type: object
  *                properties:
@@ -150,6 +156,13 @@ module.exports = (crowi) => {
   router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => {
 
     const securityParams = {
+      generalSetting: {
+        restrictGuestMode: await crowi.configManager.getConfig('crowi', 'security:restrictGuestMode'),
+        pageCompleteDeletionAuthority: await crowi.configManager.getConfig('crowi', 'security:pageCompleteDeletionAuthority'),
+        hideRestrictedByOwner: await crowi.configManager.getConfig('crowi', 'security:list-policy:hideRestrictedByOwner'),
+        hideRestrictedByGroup: await crowi.configManager.getConfig('crowi', 'security:list-policy:hideRestrictedByGroup'),
+        wikiMode: await crowi.configManager.getConfig('crowi', 'security:wikiMode'),
+      },
       generalAuth: {
         isGoogleOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-google:isEnabled'),
         isGithubOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-github:isEnabled'),
@@ -176,7 +189,6 @@ module.exports = (crowi) => {
         registrationwhiteList: await crowi.configManager.getConfig('crowi', 'security:registrationWhiteList'),
       },
     };
-
     return res.apiv3({ securityParams });
   });
 
@@ -223,7 +235,11 @@ module.exports = (crowi) => {
       'security:list-policy:hideRestrictedByOwner': req.body.hideRestrictedByOwner,
       'security:list-policy:hideRestrictedByGroup': req.body.hideRestrictedByGroup,
     };
-
+    const wikiMode = await crowi.configManager.getConfig('crowi', 'security:wikiMode');
+    if (wikiMode === 'private') {
+      logger.debug('security:restrictGuestMode will not be changed because wiki mode is forced to set');
+      delete requestParams['security:restrictGuestMode'];
+    }
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
       const securitySettingParams = {