From 26850801fd0677f156a8a5f41db1874c0e0f63eb Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 20 Jul 2026 23:13:45 +0000 Subject: [PATCH] Fix Bug 1: Set UserTenant.role_id in create_user and sync in update_user --- app/services/user_service.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/services/user_service.py b/app/services/user_service.py index 8e8656b..c0c1f89 100644 --- a/app/services/user_service.py +++ b/app/services/user_service.py @@ -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