fix: update valify rules about whether enabled auth plugin in create/… (#512)
* fix: update valify rules about whether enabled auth plugin in create/update a consumer
* fix: use PLUGIN_MAPPER_SOURCE as the souce of auth plugin
diff --git a/src/pages/Consumer/Create.tsx b/src/pages/Consumer/Create.tsx
index bc6e995..f6ca8ae 100644
--- a/src/pages/Consumer/Create.tsx
+++ b/src/pages/Consumer/Create.tsx
@@ -18,7 +18,7 @@
import { PageContainer } from '@ant-design/pro-layout';
import { Card, Steps, notification, Form } from 'antd';
import { history, useIntl } from 'umi';
-import { PluginPage, PluginPageType } from '@api7-dashboard/plugin';
+import { PluginPage, PluginPageType, PLUGIN_MAPPER_SOURCE } from '@api7-dashboard/plugin';
import ActionBar from '@/components/ActionBar';
@@ -68,8 +68,14 @@
setStep(nextStep);
});
} else if (nextStep === 3) {
- const isValid = Object.keys(plugins).some((name) => name.includes('auth'));
- if (!isValid) {
+ const authPluginNames = Object.keys(PLUGIN_MAPPER_SOURCE).filter(
+ (pluginName) => PLUGIN_MAPPER_SOURCE[pluginName].category === 'Authentication',
+ );
+ const currentAuthPlugin = Object.keys(plugins).filter((plugin) =>
+ authPluginNames.includes(plugin),
+ );
+ const currentAuthPluginLen = currentAuthPlugin.length;
+ if (currentAuthPluginLen > 1 || currentAuthPluginLen === 0) {
notification.warning({
message: formatMessage({ id: 'consumer.create.enable.authentication.plugin' }),
});
diff --git a/src/pages/Consumer/locales/en-US.ts b/src/pages/Consumer/locales/en-US.ts
index a1f49a4..6e2ecf5 100644
--- a/src/pages/Consumer/locales/en-US.ts
+++ b/src/pages/Consumer/locales/en-US.ts
@@ -16,7 +16,8 @@
*/
export default {
'consumer.step.username': 'Username',
- 'consumer.step.username.rule': 'Maximum length is 100, only letters, numbers and _ are supported, and can only begin with letters',
+ 'consumer.step.username.rule':
+ 'Maximum length is 100, only letters, numbers and _ are supported, and can only begin with letters',
'consumer.step.username.unique': 'Username should be unique',
'consumer.step.input.username': 'Please input username',
'consumer.step.description': 'Description',
@@ -25,7 +26,7 @@
'consumer.create.edit': 'Edit',
'consumer.create.create': 'Create',
'consumer.create.success': 'Success',
- 'consumer.create.enable.authentication.plugin': 'Please enable at least one authentication plugin',
+ 'consumer.create.enable.authentication.plugin': 'Please enable one authentication plugin',
'consumer.create.basic.information': 'Basic Information',
'consumer.create.plugin.config': 'Plugin Config',
'consumer.create.preview': 'Preview',
diff --git a/src/pages/Consumer/locales/zh-CN.ts b/src/pages/Consumer/locales/zh-CN.ts
index 6cd4042..005fd0f 100644
--- a/src/pages/Consumer/locales/zh-CN.ts
+++ b/src/pages/Consumer/locales/zh-CN.ts
@@ -25,7 +25,7 @@
'consumer.create.edit': '编辑',
'consumer.create.create': '创建',
'consumer.create.success': '成功',
- 'consumer.create.enable.authentication.plugin': '请启用至少一种身份认证类插件',
+ 'consumer.create.enable.authentication.plugin': '请启用一种身份认证类插件',
'consumer.create.basic.information': '基础信息',
'consumer.create.plugin.config': '插件配置',
'consumer.create.preview': '预览',