解决新建用户没有关联角色时,会关联所有角色BUG。

Signed-off-by: liujian8670 <10318920+liujian8670@user.noreply.gitee.com>
This commit is contained in:
liujian8670 2023-04-23 04:07:01 +00:00 committed by Gitee
parent e9492b2ca4
commit 7763b4b595
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -63,9 +63,10 @@ class UserDal(DalBase):
data.password = self.model.get_password_hash(password)
data.avatar = data.avatar if data.avatar else settings.DEFAULT_AVATAR
obj = self.model(**data.dict(exclude={'role_ids'}))
roles = await RoleDal(self.db).get_datas(limit=0, id=("in", data.role_ids), v_return_objs=True)
for role in roles:
obj.roles.append(role)
if data.role_ids:
roles = await RoleDal(self.db).get_datas(limit=0, id=("in", data.role_ids), v_return_objs=True)
for role in roles:
obj.roles.append(role)
await self.flush(obj)
return await self.out_dict(obj, v_options, v_return_obj, v_schema)