fix: Resolve issue with adding user to tenants
This commit is contained in:
parent
9a2a84905c
commit
12785e31ea
1 changed files with 12 additions and 16 deletions
|
|
@ -48,22 +48,18 @@ async def add_user_to_tenant(
|
||||||
message="Only tenant owner can add other users to organization."
|
message="Only tenant owner can add other users to organization."
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
if set_active_tenant:
|
||||||
try:
|
user.tenant_id = tenant_id
|
||||||
# Add association directly to the association table
|
|
||||||
create_user_tenant_statement = insert(UserTenant).values(
|
|
||||||
user_id=user_id, tenant_id=tenant_id
|
|
||||||
)
|
|
||||||
await session.execute(create_user_tenant_statement)
|
|
||||||
except IntegrityError:
|
|
||||||
raise EntityAlreadyExistsError(message="User is already part of group.")
|
|
||||||
|
|
||||||
if set_active_tenant:
|
|
||||||
user.tenant_id = tenant_id
|
|
||||||
|
|
||||||
await session.merge(user)
|
await session.merge(user)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
except IntegrityError:
|
|
||||||
raise EntityAlreadyExistsError(
|
try:
|
||||||
message="User is already part of a tenant. Only one tenant can be assigned to user."
|
# Add association directly to the association table
|
||||||
|
create_user_tenant_statement = insert(UserTenant).values(
|
||||||
|
user_id=user_id, tenant_id=tenant_id
|
||||||
)
|
)
|
||||||
|
await session.execute(create_user_tenant_statement)
|
||||||
|
await session.commit()
|
||||||
|
|
||||||
|
except IntegrityError:
|
||||||
|
raise EntityAlreadyExistsError(message="User is already part of group.")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue