From 663f8a26659e4328a068a11dc0f8300e5ea32d0c Mon Sep 17 00:00:00 2001 From: zhangjingwei Date: Thu, 9 Nov 2023 09:55:17 +0800 Subject: [PATCH] fix: fix username check User names in the domain can not be repeated, check the name check when creating and editing user Change-Id: I2cc2f6c800d85619cb9f3ca12e2e4b7d93c52125 --- src/locales/en.json | 2 +- src/locales/ko-kr.json | 2 +- src/locales/zh-hans.json | 2 +- .../identity/containers/User/actions/Create.jsx | 13 +++++++++++-- src/pages/identity/containers/User/actions/Edit.jsx | 11 +++++++++-- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index 65cebd1f..48d91321 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1334,7 +1334,7 @@ "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 name can not be duplicated": "Invalid: User name can not be duplicated", + "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)", "Iraq": "Iraq", diff --git a/src/locales/ko-kr.json b/src/locales/ko-kr.json index 93d0a9ed..5d1633e4 100644 --- a/src/locales/ko-kr.json +++ b/src/locales/ko-kr.json @@ -1334,7 +1334,7 @@ "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 name can not be duplicated": "잘못됨: 사용자 이름은 중복될 수 없습니다.", + "Invalid: User names in the domain can not be repeated": "유효하지 않음: 도메인의 사용자 이름은 반복될 수 없습니다.", "Ip Address": "IP 주소", "Iran (Islamic Republic of)": "", "Iraq": "", diff --git a/src/locales/zh-hans.json b/src/locales/zh-hans.json index 7467b478..43ce0ce9 100644 --- a/src/locales/zh-hans.json +++ b/src/locales/zh-hans.json @@ -1334,7 +1334,7 @@ "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 name can not be duplicated": "无效:用户名称不可重复", + "Invalid: User names in the domain can not be repeated": "无效:域下的用户名称不能重复", "Ip Address": "IP地址", "Iran (Islamic Republic of)": "伊朗", "Iraq": "伊拉克", diff --git a/src/pages/identity/containers/User/actions/Create.jsx b/src/pages/identity/containers/User/actions/Create.jsx index 1dde4333..c8afd0bc 100644 --- a/src/pages/identity/containers/User/actions/Create.jsx +++ b/src/pages/identity/containers/User/actions/Create.jsx @@ -221,12 +221,20 @@ export class Create extends FormAction { 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.filter((it) => it.name === value); + const nameUsed = data.filter( + (it) => it.name === value && it.domain_id === domainId + ); if (nameUsed[0]) { - return Promise.reject(t('Invalid: User name can not be duplicated')); + return Promise.reject( + t('Invalid: User names in the domain can not be repeated') + ); } return Promise.resolve(); }; @@ -261,6 +269,7 @@ export class Create extends FormAction { required: true, ...cols, maxLength: 30, + dependencies: ['domain_id'], }, { name: 'email', diff --git a/src/pages/identity/containers/User/actions/Edit.jsx b/src/pages/identity/containers/User/actions/Edit.jsx index fa814edb..8c73a98a 100644 --- a/src/pages/identity/containers/User/actions/Edit.jsx +++ b/src/pages/identity/containers/User/actions/Edit.jsx @@ -67,9 +67,16 @@ 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 name can not be duplicated')); + return Promise.reject( + t('Invalid: User names in the domain can not be repeated') + ); } return Promise.resolve(); };