Fix Bug 1: Set UserTenant.role_id in create_user and sync in update_user
This commit is contained in:
@@ -100,6 +100,7 @@ class UserService:
|
||||
user_id=user.id,
|
||||
tenant_id=tenant_id,
|
||||
is_default=True,
|
||||
role_id=role_id,
|
||||
)
|
||||
db.add(ut)
|
||||
await db.flush()
|
||||
@@ -135,6 +136,15 @@ class UserService:
|
||||
user.role = role
|
||||
if role_id is not _UNSET:
|
||||
user.role_id = role_id
|
||||
# Sync UserTenant.role_id so resolve_permissions picks up the change
|
||||
ut_q = select(UserTenant).where(
|
||||
UserTenant.user_id == user_id,
|
||||
UserTenant.tenant_id == tenant_id,
|
||||
)
|
||||
ut_result = await db.execute(ut_q)
|
||||
user_tenant = ut_result.scalar_one_or_none()
|
||||
if user_tenant:
|
||||
user_tenant.role_id = role_id
|
||||
if is_active is not None:
|
||||
user.is_active = is_active
|
||||
|
||||
|
||||
Reference in New Issue
Block a user