mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
fix: unique_tenant_account_join
This commit is contained in:
parent
91d3e43b11
commit
01d1caecf7
|
@ -421,9 +421,14 @@ class TenantService:
|
|||
if TenantService.has_roles(tenant, [TenantAccountJoinRole.OWNER]):
|
||||
logging.error(f"Tenant {tenant.id} has already an owner.")
|
||||
raise Exception("Tenant already has an owner.")
|
||||
|
||||
ta = db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
||||
if ta:
|
||||
ta.role = role
|
||||
else:
|
||||
ta = TenantAccountJoin(tenant_id=tenant.id, account_id=account.id, role=role)
|
||||
db.session.add(ta)
|
||||
|
||||
ta = TenantAccountJoin(tenant_id=tenant.id, account_id=account.id, role=role)
|
||||
db.session.add(ta)
|
||||
db.session.commit()
|
||||
return ta
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user