fix: Fix create user in domain list

fix create duplicate name user in domain detail page

Change-Id: Ife379caf4b1da5a88aae6103a55e353cf2c8407a
This commit is contained in:
zhuyue 2021-09-02 10:24:27 +08:00
parent 323396b545
commit e7308d04ac

View File

@ -29,6 +29,7 @@ export class CreateForm extends ModalAction {
this.projectStore = globalProjectStore; this.projectStore = globalProjectStore;
this.roleStore = globalRoleStore; this.roleStore = globalRoleStore;
this.domainStore = globalDomainStore; this.domainStore = globalDomainStore;
this.getAllUser();
this.getUserGroup(); this.getUserGroup();
this.getProject(); this.getProject();
this.getRole(); this.getRole();
@ -39,6 +40,10 @@ export class CreateForm extends ModalAction {
return t('Create User'); return t('Create User');
} }
async getAllUser() {
this.allUser = await this.store.pureFetchList();
}
getUserGroup() { getUserGroup() {
this.userGroupStore.fetchList(); this.userGroupStore.fetchList();
} }
@ -63,6 +68,17 @@ export class CreateForm extends ModalAction {
'identity:list_domains', 'identity:list_domains',
]; ];
checkName = (rule, value) => {
if (!value) {
return Promise.reject(t('Please input'));
}
const nameUsed = this.allUser.find((i) => i.name === value);
if (nameUsed) {
return Promise.reject(t('Invalid: User name can not be duplicated'));
}
return Promise.resolve();
};
static allowed(item, containerProps) { static allowed(item, containerProps) {
const { const {
match: { path }, match: { path },
@ -138,6 +154,7 @@ export class CreateForm extends ModalAction {
name: 'name', name: 'name',
label: t('User Name'), label: t('User Name'),
type: 'input', type: 'input',
validator: this.checkName,
placeholder: t('Please input user name'), placeholder: t('Please input user name'),
required: true, required: true,
}, },
@ -226,8 +243,6 @@ export class CreateForm extends ModalAction {
real_name, real_name,
default_project_id, default_project_id,
}; };
// eslint-disable-next-line no-console
console.log(data);
return this.store.create(data); return this.store.create(data);
}; };
} }