فهرست منبع

adjust validation

itizawa 6 سال پیش
والد
کامیت
1901928786

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

@@ -117,7 +117,7 @@ class GitHubSecurityManagement extends React.Component {
                   className="form-control"
                   className="form-control"
                   type="text"
                   type="text"
                   name="githubClientId"
                   name="githubClientId"
-                  value={adminGitHubSecurityContainer.state.githubClientId}
+                  value={adminGitHubSecurityContainer.state.githubClientId ||''}
                   onChange={e => adminGitHubSecurityContainer.changeGitHubClientId(e.target.value)}
                   onChange={e => adminGitHubSecurityContainer.changeGitHubClientId(e.target.value)}
                 />
                 />
                 <p className="help-block">
                 <p className="help-block">
@@ -133,7 +133,7 @@ class GitHubSecurityManagement extends React.Component {
                   className="form-control"
                   className="form-control"
                   type="text"
                   type="text"
                   name="githubClientSecret"
                   name="githubClientSecret"
-                  defaultValue={adminGitHubSecurityContainer.state.githubClientSecret}
+                  defaultValue={adminGitHubSecurityContainer.state.githubClientSecret ||''}
                   onChange={e => adminGitHubSecurityContainer.changeGitHubClientSecret(e.target.value)}
                   onChange={e => adminGitHubSecurityContainer.changeGitHubClientSecret(e.target.value)}
                 />
                 />
                 <p className="help-block">
                 <p className="help-block">
@@ -148,7 +148,7 @@ class GitHubSecurityManagement extends React.Component {
                   <input
                   <input
                     id="bindByUserNameGitHub"
                     id="bindByUserNameGitHub"
                     type="checkbox"
                     type="checkbox"
-                    checked={adminGitHubSecurityContainer.state.isSameUsernameTreatedAsIdenticalUser}
+                    checked={adminGitHubSecurityContainer.state.isSameUsernameTreatedAsIdenticalUser || false}
                     onChange={() => { adminGitHubSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }}
                     onChange={() => { adminGitHubSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }}
                   />
                   />
                   <label
                   <label

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

@@ -117,7 +117,7 @@ class GoogleSecurityManagement extends React.Component {
                   className="form-control"
                   className="form-control"
                   type="text"
                   type="text"
                   name="googleClientId"
                   name="googleClientId"
-                  defaultValue={adminGoogleSecurityContainer.state.googleClientId}
+                  defaultValue={adminGoogleSecurityContainer.state.googleClientId || ''}
                   onChange={e => adminGoogleSecurityContainer.changeGoogleClientId(e.target.value)}
                   onChange={e => adminGoogleSecurityContainer.changeGoogleClientId(e.target.value)}
                 />
                 />
                 <p className="help-block">
                 <p className="help-block">
@@ -133,7 +133,7 @@ class GoogleSecurityManagement extends React.Component {
                   className="form-control"
                   className="form-control"
                   type="text"
                   type="text"
                   name="googleClientSecret"
                   name="googleClientSecret"
-                  defaultValue={adminGoogleSecurityContainer.state.googleClientSecret}
+                  defaultValue={adminGoogleSecurityContainer.state.googleClientSecret || ''}
                   onChange={e => adminGoogleSecurityContainer.changeGoogleClientSecret(e.target.value)}
                   onChange={e => adminGoogleSecurityContainer.changeGoogleClientSecret(e.target.value)}
                 />
                 />
                 <p className="help-block">
                 <p className="help-block">
@@ -148,7 +148,7 @@ class GoogleSecurityManagement extends React.Component {
                   <input
                   <input
                     id="bindByUserNameGoogle"
                     id="bindByUserNameGoogle"
                     type="checkbox"
                     type="checkbox"
-                    checked={adminGoogleSecurityContainer.state.isSameUsernameTreatedAsIdenticalUser}
+                    checked={adminGoogleSecurityContainer.state.isSameUsernameTreatedAsIdenticalUser || false}
                     onChange={() => { adminGoogleSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }}
                     onChange={() => { adminGoogleSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }}
                   />
                   />
                   <label
                   <label

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

@@ -117,7 +117,7 @@ class TwitterSecurityManagement extends React.Component {
                   className="form-control"
                   className="form-control"
                   type="text"
                   type="text"
                   name="TwitterConsumerId"
                   name="TwitterConsumerId"
-                  defaultValue={adminTwitterSecurityContainer.state.twitterConsumerKey}
+                  defaultValue={adminTwitterSecurityContainer.state.twitterConsumerKey || ''}
                   onChange={e => adminTwitterSecurityContainer.changeTwitterConsumerKey(e.target.value)}
                   onChange={e => adminTwitterSecurityContainer.changeTwitterConsumerKey(e.target.value)}
                 />
                 />
                 <p className="help-block">
                 <p className="help-block">
@@ -133,7 +133,7 @@ class TwitterSecurityManagement extends React.Component {
                   className="form-control"
                   className="form-control"
                   type="text"
                   type="text"
                   name="TwitterConsumerSecret"
                   name="TwitterConsumerSecret"
-                  defaultValue={adminTwitterSecurityContainer.state.twitterConsumerSecret}
+                  defaultValue={adminTwitterSecurityContainer.state.twitterConsumerSecret || ''}
                   onChange={e => adminTwitterSecurityContainer.changeTwitterConsumerSecret(e.target.value)}
                   onChange={e => adminTwitterSecurityContainer.changeTwitterConsumerSecret(e.target.value)}
                 />
                 />
                 <p className="help-block">
                 <p className="help-block">
@@ -148,7 +148,7 @@ class TwitterSecurityManagement extends React.Component {
                   <input
                   <input
                     id="bindByUserNameTwitter"
                     id="bindByUserNameTwitter"
                     type="checkbox"
                     type="checkbox"
-                    checked={adminTwitterSecurityContainer.state.isSameUsernameTreatedAsIdenticalUser}
+                    checked={adminTwitterSecurityContainer.state.isSameUsernameTreatedAsIdenticalUser || false}
                     onChange={() => { adminTwitterSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }}
                     onChange={() => { adminTwitterSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }}
                   />
                   />
                   <label
                   <label

+ 1 - 1
src/client/js/services/AdminGitHubSecurityContainer.js

@@ -20,7 +20,7 @@ export default class AdminGitHubSecurityContainer extends Container {
       appSiteUrl: urljoin(pathUtils.removeTrailingSlash(appContainer.config.crowi.url), '/passport/github/callback'),
       appSiteUrl: urljoin(pathUtils.removeTrailingSlash(appContainer.config.crowi.url), '/passport/github/callback'),
       githubClientId: '',
       githubClientId: '',
       githubClientSecret: '',
       githubClientSecret: '',
-      isSameUsernameTreatedAsIdenticalUser: true,
+      isSameUsernameTreatedAsIdenticalUser: false,
     };
     };
 
 
   }
   }

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

@@ -21,11 +21,11 @@ const validator = {
     body('pageCompleteDeletionAuthority').isString().isIn([
     body('pageCompleteDeletionAuthority').isString().isIn([
       'anyOne', 'adminOnly', 'adminAndAuthor',
       'anyOne', 'adminOnly', 'adminAndAuthor',
     ]),
     ]),
-    body('hideRestrictedByOwner').isBoolean(),
-    body('hideRestrictedByGroup').isBoolean(),
+    body('hideRestrictedByOwner').if((value, { req }) => req.body.hideRestrictedByOwner).isBoolean(),
+    body('hideRestrictedByGroup').if((value, { req }) => req.body.hideRestrictedByGroup).isBoolean(),
   ],
   ],
   authenticationSetting: [
   authenticationSetting: [
-    body('isEnabled').isBoolean(),
+    body('isEnabled').if((value, { req }) => req.body.isEnabled).isBoolean(),
     body('authId').isString().isIn([
     body('authId').isString().isIn([
       'local', 'ldap', 'saml', 'oidc', 'basic', 'google', 'github', 'twitter',
       'local', 'ldap', 'saml', 'oidc', 'basic', 'google', 'github', 'twitter',
     ]),
     ]),
@@ -34,57 +34,57 @@ const validator = {
     body('registrationMode').isString().isIn([
     body('registrationMode').isString().isIn([
       'Open', 'Restricted', 'Closed',
       'Open', 'Restricted', 'Closed',
     ]),
     ]),
-    body('registrationWhiteList').isArray(),
+    body('registrationWhiteList').if((value, { req }) => req.body.registrationWhiteList).isArray(),
   ],
   ],
   ldapAuth: [
   ldapAuth: [
-    body('serverUrl').isString(),
-    body('isUserBind').isBoolean(),
-    body('ldapBindDN').isString(),
-    body('ldapBindDNPassword').isString(),
-    body('ldapSearchFilter').isString(),
-    body('ldapAttrMapUsername').isString(),
-    body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
-    body('ldapAttrMapMail').isString(),
-    body('ldapAttrMapName').isString(),
-    body('ldapGroupSearchBase').isString(),
-    body('ldapGroupSearchFilter').isString(),
-    body('ldapGroupDnProperty').isString(),
+    body('serverUrl').if((value, { req }) => req.body.serverUrl).isString(),
+    body('isUserBind').if((value, { req }) => req.body.isUserBind).isBoolean(),
+    body('ldapBindDN').if((value, { req }) => req.body.ldapBindDN).isString(),
+    body('ldapBindDNPassword').if((value, { req }) => req.body.ldapBindDNPassword).isString(),
+    body('ldapSearchFilter').if((value, { req }) => req.body.ldapSearchFilter).isString(),
+    body('ldapAttrMapUsername').if((value, { req }) => req.body.ldapAttrMapUsername).isString(),
+    body('isSameUsernameTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameUsernameTreatedAsIdenticalUser).isBoolean(),
+    body('ldapAttrMapMail').if((value, { req }) => req.body.ldapAttrMapMail).isString(),
+    body('ldapAttrMapName').if((value, { req }) => req.body.ldapAttrMapName).isString(),
+    body('ldapGroupSearchBase').if((value, { req }) => req.body.ldapGroupSearchBase).isString(),
+    body('ldapGroupSearchFilter').if((value, { req }) => req.body.ldapGroupSearchFilter).isString(),
+    body('ldapGroupDnProperty').if((value, { req }) => req.body.ldapGroupDnProperty).isString(),
   ],
   ],
   samlAuth: [
   samlAuth: [
-    body('samlEntryPoint').isString(),
-    body('samlIssuer').isString(),
-    body('samlCert').isString(),
-    body('samlAttrMapId').isString(),
-    body('samlAttrMapUserName').isString(),
-    body('samlAttrMapMail').isString(),
-    body('samlAttrMapFirstName').isString(),
-    body('samlAttrMapLastName').isString(),
-    body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
-    body('isSameEmailTreatedAsIdenticalUser').isBoolean(),
+    body('samlEntryPoint').if((value, { req }) => req.body.samlEntryPoint).isString(),
+    body('samlIssuer').if((value, { req }) => req.body.samlIssuer).isString(),
+    body('samlCert').if((value, { req }) => req.body.samlCert).isString(),
+    body('samlAttrMapId').if((value, { req }) => req.body.samlAttrMapId).isString(),
+    body('samlAttrMapUserName').if((value, { req }) => req.body.samlAttrMapUserName).isString(),
+    body('samlAttrMapMail').if((value, { req }) => req.body.samlAttrMapMail).isString(),
+    body('samlAttrMapFirstName').if((value, { req }) => req.body.samlAttrMapFirstName).isString(),
+    body('samlAttrMapLastName').if((value, { req }) => req.body.samlAttrMapLastName).isString(),
+    body('isSameUsernameTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameUsernameTreatedAsIdenticalUser).isBoolean(),
+    body('isSameEmailTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameEmailTreatedAsIdenticalUser).isBoolean(),
   ],
   ],
   oidcAuth: [
   oidcAuth: [
-    body('oidcProviderName').isString(),
-    body('oidcIssuerHost').isString(),
-    body('oidcClientId').isString(),
-    body('oidcClientSecret').isString(),
-    body('oidcAttrMapId').isString(),
-    body('oidcAttrMapUserName').isString(),
-    body('oidcAttrMapEmail').isString(),
-    body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
-    body('isSameEmailTreatedAsIdenticalUser').isBoolean(),
+    body('oidcProviderName').if((value, { req }) => req.body.oidcProviderName).isString(),
+    body('oidcIssuerHost').if((value, { req }) => req.body.oidcIssuerHost).isString(),
+    body('oidcClientId').if((value, { req }) => req.body.oidcClientId).isString(),
+    body('oidcClientSecret').if((value, { req }) => req.body.oidcClientSecret).isString(),
+    body('oidcAttrMapId').if((value, { req }) => req.body.oidcAttrMapId).isString(),
+    body('oidcAttrMapUserName').if((value, { req }) => req.body.oidcAttrMapUserName).isString(),
+    body('oidcAttrMapEmail').if((value, { req }) => req.body.oidcAttrMapEmail).isString(),
+    body('isSameUsernameTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameUsernameTreatedAsIdenticalUser).isBoolean(),
+    body('isSameEmailTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameEmailTreatedAsIdenticalUser).isBoolean(),
   ],
   ],
   basicAuth: [
   basicAuth: [
-    body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
+    body('isSameUsernameTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameUsernameTreatedAsIdenticalUser).isBoolean(),
   ],
   ],
   googleOAuth: [
   googleOAuth: [
-    body('googleClientId').isString(),
-    body('googleClientSecret').isString(),
-    body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
+    body('googleClientId').if((value, { req }) => req.body.googleClientId).isString(),
+    body('googleClientSecret').if((value, { req }) => req.body.googleClientSecret).isString(),
+    body('isSameUsernameTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameUsernameTreatedAsIdenticalUser).isBoolean(),
   ],
   ],
   githubOAuth: [
   githubOAuth: [
-    body('githubClientId').isString(),
-    body('githubClientSecret').isString(),
-    body('isSameUsernameTreatedAsIdenticalUser').isBoolean(),
+    body('githubClientId').if((value, { req }) => req.body.githubClientId).isString(),
+    body('githubClientSecret').if((value, { req }) => req.body.githubClientSecret).isString(),
+    body('isSameUsernameTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameUsernameTreatedAsIdenticalUser).isBoolean(),
   ],
   ],
   twitterOAuth: [
   twitterOAuth: [
     body('twitterConsumerKey').if((value, { req }) => req.body.twitterConsumerKey).isString(),
     body('twitterConsumerKey').if((value, { req }) => req.body.twitterConsumerKey).isString(),