2
0
Эх сурвалжийг харах

get array registration white list

WESEEK Kaito 6 жил өмнө
parent
commit
cdde29bdf7

+ 25 - 3
src/client/js/components/Admin/Security/LocalSecuritySetting.jsx

@@ -14,13 +14,29 @@ class LocalSecuritySetting extends React.Component {
   constructor(props) {
     super(props);
 
+    this.state = {
+      retrieveError: null,
+    };
     this.putLocalSecuritySetting = this.putLocalSecuritySetting.bind(this);
   }
 
+  async componentDidMount() {
+    const { adminGeneralSecurityContainer } = this.props;
+
+    try {
+      await adminGeneralSecurityContainer.retrieveSecurityData();
+    }
+    catch (err) {
+      toastError(err);
+      this.setState({ retrieveError: err });
+    }
+  }
+
+
   async putLocalSecuritySetting() {
-    const { t } = this.props;
+    const { t, adminGeneralSecurityContainer } = this.props;
     try {
-      await this.props.adminGeneralSecurityContainer.updateLocalSecuritySetting();
+      await adminGeneralSecurityContainer.updateLocalSecuritySetting();
       toastSuccess(t('security_setting.updated_general_security_setting'));
     }
     catch (err) {
@@ -33,7 +49,11 @@ class LocalSecuritySetting extends React.Component {
 
     return (
       <React.Fragment>
-
+        {this.state.retrieveError != null && (
+          <div className="alert alert-danger">
+            <p>{t('Error occurred')} : {this.state.err}</p>
+          </div>
+        )}
         <h2 className="alert-anchor border-bottom">
           { t('security_setting.Local.name') } { t('security_setting.configuration') }
         </h2>
@@ -119,6 +139,8 @@ class LocalSecuritySetting extends React.Component {
                     type="textarea"
                     name="registrationWhiteList"
                     placeholder={adminGeneralSecurityContainer.state.registrationWhiteList}
+                    value={adminGeneralSecurityContainer.state.registrationWhiteList}
+                    onChange={e => adminGeneralSecurityContainer.changeRegistrationWhiteList(e.target.value)}
                   />
                   <p className="help-block small">{ t('security_setting.restrict_emails') }<br />{ t('security_setting.for_instance') }
                     <code>@growi.org</code>{ t('security_setting.only_those') }<br />

+ 12 - 4
src/client/js/services/AdminGeneralSecurityContainer.js

@@ -27,7 +27,7 @@ export default class AdminGeneralSecurityContainer extends Container {
       appSiteUrl: appContainer.config.crowi.url || '',
       isLocalEnabled: true,
       registrationMode: 'open',
-      registrationWhiteList: '',
+      registrationWhiteList: [],
       isLdapEnabled: true,
       isSamlEnabled: true,
       isOidcEnabled: true,
@@ -43,6 +43,7 @@ export default class AdminGeneralSecurityContainer extends Container {
   async retrieveSecurityData() {
     const response = await this.appContainer.apiv3.get('/security-setting/');
     const { generalSetting } = response.data.securityParams;
+    const { localSetting } = response.data.securityParams;
     this.onIsWikiModeForced(generalSetting.wikiMode);
     this.setState({
       currentRestrictGuestMode: generalSetting.restrictGuestMode || 'deny',
@@ -50,9 +51,9 @@ export default class AdminGeneralSecurityContainer extends Container {
       isHideRestrictedByOwner: generalSetting.hideRestrictedByOwner || false,
       isHideRestrictedByGroup: generalSetting.hideRestrictedByGroup || false,
       wikiMode: generalSetting.wikiMode || '',
-      isLocalEnabled: generalSetting.registrationMode || 'true',
-      registrationMode: generalSetting.registrationMode || 'open',
-      registrationWhiteList: generalSetting.registrationWhiteList || '',
+      isLocalEnabled: localSetting.isLocalEnabled || 'true',
+      registrationMode: localSetting.registrationMode || 'open',
+      registrationWhiteList: localSetting.registrationWhiteList || '',
     });
   }
 
@@ -132,6 +133,13 @@ export default class AdminGeneralSecurityContainer extends Container {
     this.setState({ registrationMode: value });
   }
 
+  /**
+   * Change registration white list
+   */
+  changeRegistrationWhiteList(value) {
+    this.setState({ registrationWhiteList: value });
+  }
+
   /**
   * update local security setting
   */

+ 3 - 3
src/server/routes/apiv3/security-setting.js

@@ -22,7 +22,7 @@ const validator = {
   localSetting: [
     body('isLocalEnabled').isBoolean(),
     body('registrationMode').isString(),
-    body('registrationwhiteList').isString(),
+    body('registrationwhiteList').toArray(),
   ],
   googleOAuth: [
     body('googleClientId').isString(),
@@ -93,7 +93,7 @@ const validator = {
  *                type: string
  *                description: type of registrationMode
  *              registrationWhiteList:
- *                type: string
+ *                type: array
  *                desription: type of registrationWhiteList
  *          GitHubOAuthSetting:
  *            type:object
@@ -278,7 +278,7 @@ module.exports = (crowi) => {
    *                    type: string
    *                    description: type of pageDeletionAuthority
    *                  registrationWhiteList:
-   *                    type: string
+   *                    type: array
    *                    description: type of registrationWhiteList
    *        responses:
    *          200: