From 9b9c5248a9834a5dd87dc974ca407c59c62d6d41 Mon Sep 17 00:00:00 2001 From: zhangjingwei Date: Thu, 9 Nov 2023 10:13:40 +0800 Subject: [PATCH] fix: fix user group name check User group names in the domain can not be repeated, update the name check when creating and editing user group Change-Id: I174318b9b3c3dd6639a96a0f45e6d5a9935c06f8 --- src/locales/en.json | 2 +- src/locales/ko-kr.json | 2 +- src/locales/zh-hans.json | 2 +- .../identity/containers/UserGroup/actions/Create.jsx | 11 +++++++++-- .../identity/containers/UserGroup/actions/Edit.jsx | 9 +++++++-- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 48d91321..7e4926c4 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1333,7 +1333,7 @@ "Invalid: Project name can not be chinese": "Invalid: Project name can not be chinese", "Invalid: Project names in the domain can not be repeated": "Invalid: Project names in the domain can not be repeated", "Invalid: Quota value(s) cannot be less than the current usage value(s): { used } used.": "Invalid: Quota value(s) cannot be less than the current usage value(s): { used } used.", - "Invalid: User Group name can not be duplicated": "Invalid: User Group name can not be duplicated", + "Invalid: User Group names in the domain can not be repeated": "Invalid: User Group names in the domain can not be repeated", "Invalid: User names in the domain can not be repeated": "Invalid: User names in the domain can not be repeated", "Ip Address": "Ip Address", "Iran (Islamic Republic of)": "Iran (Islamic Republic of)", diff --git a/src/locales/ko-kr.json b/src/locales/ko-kr.json index 5d1633e4..b5bf09d8 100644 --- a/src/locales/ko-kr.json +++ b/src/locales/ko-kr.json @@ -1333,7 +1333,7 @@ "Invalid: Project name can not be chinese": "잘못됨: 프로젝트 이름은 중국어일 수 없습니다.", "Invalid: Project names in the domain can not be repeated": "유효하지 않음: 도메인의 프로젝트 이름은 반복될 수 없습니다.", "Invalid: Quota value(s) cannot be less than the current usage value(s): { used } used.": "잘못됨: 할당량 값은 현재 사용 값보다 작을 수 없습니다: { used } 사용됨.", - "Invalid: User Group name can not be duplicated": "잘못됨: 사용자 그룹 이름은 중복될 수 없습니다.", + "Invalid: User Group names in the domain can not be repeated": "유효하지 않음: 도메인의 사용자 그룹 이름은 반복될 수 없습니다.", "Invalid: User names in the domain can not be repeated": "유효하지 않음: 도메인의 사용자 이름은 반복될 수 없습니다.", "Ip Address": "IP 주소", "Iran (Islamic Republic of)": "", diff --git a/src/locales/zh-hans.json b/src/locales/zh-hans.json index 43ce0ce9..e2d438b1 100644 --- a/src/locales/zh-hans.json +++ b/src/locales/zh-hans.json @@ -1333,7 +1333,7 @@ "Invalid: Project name can not be chinese": "无效:项目名称不可使用中文", "Invalid: Project names in the domain can not be repeated": "无效:域下的项目名称不能重复", "Invalid: Quota value(s) cannot be less than the current usage value(s): { used } used.": "无效:配额必须大于已使用数量{ used }且为整数", - "Invalid: User Group name can not be duplicated": "无效:用户组名称不可重复", + "Invalid: User Group names in the domain can not be repeated": "无效:域下的用户组名称不能重复", "Invalid: User names in the domain can not be repeated": "无效:域下的用户名称不能重复", "Ip Address": "IP地址", "Iran (Islamic Republic of)": "伊朗", diff --git a/src/pages/identity/containers/UserGroup/actions/Create.jsx b/src/pages/identity/containers/UserGroup/actions/Create.jsx index c727dd58..3ee8f280 100644 --- a/src/pages/identity/containers/UserGroup/actions/Create.jsx +++ b/src/pages/identity/containers/UserGroup/actions/Create.jsx @@ -50,11 +50,17 @@ export class Create extends ModalAction { if (!value) { return Promise.reject(t('Please input')); } + const domainId = this.formRef.current.getFieldValue('domain_id'); + if (!domainId) { + return Promise.resolve(); + } const { list: { data = [] } = {} } = this.store; - const nameUsed = data.find((it) => it.name === value); + const nameUsed = data.find( + (it) => it.name === value && it.domain_id === domainId + ); if (nameUsed) { return Promise.reject( - t('Invalid: User Group name can not be duplicated') + t('Invalid: User Group names in the domain can not be repeated') ); } return Promise.resolve(); @@ -72,6 +78,7 @@ export class Create extends ModalAction { validator: this.checkName, extra: t('User Groups') + t('Name can not be duplicated'), maxLength: 30, + dependencies: ['domain_id'], }, domainFormItem, { diff --git a/src/pages/identity/containers/UserGroup/actions/Edit.jsx b/src/pages/identity/containers/UserGroup/actions/Edit.jsx index 99c31c7b..e6d2ec2b 100644 --- a/src/pages/identity/containers/UserGroup/actions/Edit.jsx +++ b/src/pages/identity/containers/UserGroup/actions/Edit.jsx @@ -47,10 +47,15 @@ export class EditForm extends ModalAction { list: { data }, } = this.store; const { id } = this.item; - const nameUsed = data.find((it) => it.name === value && it.id !== id); + const nameUsed = data.find( + (it) => + it.name === value && + it.id !== id && + it.domain_id === this.item.domain_id + ); if (nameUsed) { return Promise.reject( - t('Invalid: User Group name can not be duplicated') + t('Invalid: User Group names in the domain can not be repeated') ); } return Promise.resolve();