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

improve external user group sync error handling

Futa Arai 2 лет назад
Родитель
Сommit
7c8b630a0b

+ 1 - 0
apps/app/public/static/locales/en_US/admin.json

@@ -1057,6 +1057,7 @@
     "execute_sync": "Execute Sync",
     "sync": "Sync",
     "invalid_sync_settings": "Invalid sync settings",
+    "update_sync_settings_failed": "Failed to update sync settings",
     "description_form_detail": "Please note that edited value will be overwritten on next sync if description mapper is set in sync settings",
     "only_description_edit_allowed": "Only description can be edited for external user groups",
     "sync_succeeded": "Sync succeeded",

+ 5 - 4
apps/app/public/static/locales/ja_JP/admin.json

@@ -1065,6 +1065,7 @@
     "execute_sync": "同期実行",
     "sync": "同期",
     "invalid_sync_settings": "同期設定に誤りがあります",
+    "update_sync_settings_failed": "同期設定の更新が失敗しました",
     "description_form_detail": "同期設定で「説明」の mapper が設定されている場合、編集内容は再同期によって上書きされることに注意してください",
     "only_description_edit_allowed": "外部グループは説明の編集のみが可能です",
     "sync_succeeded": "同期に成功しました",
@@ -1093,12 +1094,12 @@
       "host_detail": "Keycloak ホスト URL",
       "group_realm": "Group Realm",
       "group_realm_detail": "同期対象のグループがある realm",
-      "group_sync_client_realm": "Admin API を叩くための Client がある Realm",
-      "group_sync_client_realm_detail": "Keycloak admin API を叩くための認証に使う client がある realm",
+      "group_sync_client_realm": "Admin API にリクエストするための client がある realm",
+      "group_sync_client_realm_detail": "Keycloak admin API にリクエストするための認証に使う client がある realm",
       "group_sync_client_id": "Client の ID",
-      "group_sync_client_id_detail": "Keycloak admin API を叩くための認証に使う client の Client ID",
+      "group_sync_client_id_detail": "Keycloak admin API にリクエストするための認証に使う client の Client ID",
       "group_sync_client_secret": "Client の Secret",
-      "group_sync_client_secret_detail": "Keycloak admin API を叩くための認証に使う client の secret",
+      "group_sync_client_secret_detail": "Keycloak admin API にリクエストするための認証に使う client の secret",
       "updated_group_sync_settings": "Keycloak グループ同期設定を更新しました",
       "preserve_deleted_keycloak_groups": "Keycloak から削除されたグループを GROWI に残す",
       "auth_not_set": "同期実行前に、セキュリティ設定で Keycloak を使った OIDC または SAML 認証を設定し、有効にしてください"

+ 1 - 0
apps/app/public/static/locales/zh_CN/admin.json

@@ -1065,6 +1065,7 @@
     "execute_sync": "Execute Sync",
     "sync": "Sync",
     "invalid_sync_settings": "Invalid sync settings",
+    "update_sync_settings_failed": "Failed to update sync settings",
     "description_form_detail": "Please note that edited value will be overwritten on next sync if description mapper is set in sync settings",
     "only_description_edit_allowed": "Only description can be edited for external user groups",
     "sync_succeeded": "Sync succeeded",

+ 1 - 1
apps/app/src/features/external-user-group/client/components/ExternalUserGroup/KeycloakGroupManagement.tsx

@@ -17,7 +17,7 @@ export const KeycloakGroupManagement: FC = () => {
       toastSuccess(t('external_user_group.sync_succeeded'));
     }
     catch (errs) {
-      toastError(t(errs[0]?.message));
+      toastError(t(errs[0]?.code));
     }
   }, [t]);
 

+ 1 - 1
apps/app/src/features/external-user-group/client/components/ExternalUserGroup/LdapGroupSyncSettingsForm.tsx

@@ -38,7 +38,7 @@ export const LdapGroupSyncSettingsForm: FC = () => {
       toastSuccess(t('external_user_group.ldap.updated_group_sync_settings'));
     }
     catch (errs) {
-      toastError(t(errs[0]?.message));
+      toastError(t(errs[0]?.code));
     }
   }, [formValues, t]);
 

+ 20 - 6
apps/app/src/features/external-user-group/server/routes/apiv3/external-user-group.ts

@@ -241,7 +241,9 @@ module.exports = (crowi: Crowi): Router => {
   router.put('/ldap/sync-settings', loginRequiredStrictly, adminRequired, validators.ldapSyncSettings, async(req: AuthorizedRequest, res: ApiV3Response) => {
     const errors = validationResult(req);
     if (!errors.isEmpty()) {
-      return res.apiv3Err('external_user_group.invalid_sync_settings', 400);
+      return res.apiv3Err(
+        new ErrorV3('Invalid sync settings', 'external_user_group.invalid_sync_settings'), 400,
+      );
     }
 
     const params = {
@@ -266,7 +268,9 @@ module.exports = (crowi: Crowi): Router => {
     }
     catch (err) {
       logger.error(err);
-      return res.apiv3Err(err, 500);
+      return res.apiv3Err(
+        new ErrorV3('Sync settings update failed', 'external_user_group.update_sync_settings_failed'), 500,
+      );
     }
   });
 
@@ -274,7 +278,9 @@ module.exports = (crowi: Crowi): Router => {
     async(req: AuthorizedRequest, res: ApiV3Response) => {
       const errors = validationResult(req);
       if (!errors.isEmpty()) {
-        return res.apiv3Err('external_user_group.invalid_sync_settings', 400);
+        return res.apiv3Err(
+          new ErrorV3('Invalid sync settings', 'external_user_group.invalid_sync_settings'), 400,
+        );
       }
 
       const params = {
@@ -294,7 +300,9 @@ module.exports = (crowi: Crowi): Router => {
       }
       catch (err) {
         logger.error(err);
-        return res.apiv3Err(err, 500);
+        return res.apiv3Err(
+          new ErrorV3('Sync settings update failed', 'external_user_group.update_sync_settings_failed'), 500,
+        );
       }
     });
 
@@ -334,7 +342,11 @@ module.exports = (crowi: Crowi): Router => {
     };
 
     const authProviderType = getAuthProviderType();
-    if (authProviderType == null) return res.apiv3Err('external_user_group.keycloak.auth_not_set', 500);
+    if (authProviderType == null) {
+      return res.apiv3Err(
+        new ErrorV3('Authentication using keycloak is not set', 'external_user_group.keycloak.auth_not_set'), 500,
+      );
+    }
 
     try {
       const keycloakUserGroupSyncService = new KeycloakUserGroupSyncService(authProviderType);
@@ -342,7 +354,9 @@ module.exports = (crowi: Crowi): Router => {
     }
     catch (err) {
       logger.error(err);
-      return res.apiv3Err('external_user_group.sync_failed', 500);
+      return res.apiv3Err(
+        new ErrorV3('Sync failed', 'external_user_group.sync_failed'), 500,
+      );
     }
 
     return res.apiv3({}, 204);