itizawa 6 лет назад
Родитель
Сommit
c4ddb28b2a

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

@@ -123,14 +123,14 @@ export default class AdminGeneralSecurityContainer extends Container {
   /**
    * Switch authentication
    */
-  async switchAuthentication(auth) {
-    const isEnabled = !this.state[`is${auth}Enabled`];
+  async switchAuthentication(stateVariableName, authId) {
+    const isEnabled = !this.state[stateVariableName];
     try {
       await this.appContainer.apiv3.put('/security-setting/authentication/enabled', {
         isEnabled,
-        auth,
+        authId,
       });
-      this.setState({ [`is${auth}Enabled`]: isEnabled });
+      this.setState({ [stateVariableName]: isEnabled });
     }
     catch (err) {
       toastError(err);
@@ -141,7 +141,7 @@ export default class AdminGeneralSecurityContainer extends Container {
    * Switch local enabled
    */
   async switchIsLocalEnabled() {
-    this.switchAuthentication('Local');
+    this.switchAuthentication('isLocalEnabled', 'local');
   }
 
   /**
@@ -177,49 +177,49 @@ export default class AdminGeneralSecurityContainer extends Container {
    * Switch LDAP enabled
    */
   async switchIsLdapEnabled() {
-    this.switchAuthentication('Ldap');
+    this.switchAuthentication('isLdapEnabled', 'ldap');
   }
 
   /**
    * Switch SAML enabled
    */
   async switchIsSamlEnabled() {
-    this.switchAuthentication('Saml');
+    this.switchAuthentication('isSamlEnabled', 'saml');
   }
 
   /**
    * Switch Oidc enabled
    */
   async switchIsOidcEnabled() {
-    this.switchAuthentication('Oidc');
+    this.switchAuthentication('isOidcEnabled', 'oidc');
   }
 
   /**
    * Switch Basic enabled
    */
   async switchIsBasicEnabled() {
-    this.switchAuthentication('Basic');
+    this.switchAuthentication('isBasicEnabled', 'basic');
   }
 
   /**
    * Switch GoogleOAuth enabled
    */
   async switchIsGoogleOAuthEnabled() {
-    this.switchAuthentication('Google');
+    this.switchAuthentication('isGoogleEnabled', 'google');
   }
 
   /**
    * Switch GithubOAuth enabled
    */
   async switchIsGithubOAuthEnabled() {
-    this.switchAuthentication('GitHub');
+    this.switchAuthentication('isGitHubEnabled', 'github');
   }
 
   /**
    * Switch TwitterOAuth enabled
    */
   async switchIsTwitterOAuthEnabled() {
-    this.switchAuthentication('Twitter');
+    this.switchAuthentication('isTwitterEnabled', 'twitter');
   }
 
 }

+ 7 - 8
src/server/routes/apiv3/security-setting.js

@@ -22,8 +22,8 @@ const validator = {
   ],
   authenticationSetting: [
     body('isEnabled').isBoolean(),
-    body('auth').isString().isIn([
-      'Local', 'Ldap', 'Saml', 'Oidc', 'Basic', 'Google', 'GitHub', 'Twitter',
+    body('authId').isString().isIn([
+      'local', 'ldap', 'saml', 'oidc', 'basic', 'google', 'gitHub', 'twitter',
     ]),
   ],
   localSetting: [
@@ -427,26 +427,25 @@ module.exports = (crowi) => {
    *                  description: updated param
    */
   router.put('/authentication/enabled', loginRequiredStrictly, adminRequired, csrf, validator.authenticationSetting, ApiV3FormValidator, async(req, res) => {
-    const { isEnabled, auth } = req.body;
-    const authLowerCase = auth.toLowerCase();
+    const { isEnabled, authId } = req.body;
 
     let setupStrategies = await crowi.passportService.getSetupStrategies();
 
     // Reflect request param
-    setupStrategies = setupStrategies.filter(strategy => strategy !== `passport-${authLowerCase}`);
+    setupStrategies = setupStrategies.filter(strategy => strategy !== authId);
 
     if (setupStrategies.length === 0) {
       return res.apiv3Err(new ErrorV3('Can not turn everything off'));
     }
 
-    const enableParams = { [`security:passport-${authLowerCase}:isEnabled`]: isEnabled };
+    const enableParams = { [`security:passport-${authId}:isEnabled`]: isEnabled };
 
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', enableParams);
 
-      await crowi.passportService.setupStrategyByAuth(auth);
+      await crowi.passportService.setupStrategyById(authId);
 
-      const responseParams = { [`security:passport-${authLowerCase}:isEnabled`]: await crowi.configManager.getConfig('crowi', `security:passport-${authLowerCase}:isEnabled`) };
+      const responseParams = { [`security:passport-${authId}:isEnabled`]: await crowi.configManager.getConfig('crowi', `security:passport-${authId}:isEnabled`) };
 
       return res.apiv3({ responseParams });
     }