mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-19 16:39:13 +08:00
fix recreating users' default tenant relations when loading user (#2408)
This commit is contained in:
parent
476eb90a90
commit
9232244920
@ -56,17 +56,18 @@ class AccountService:
|
||||
if account.status in [AccountStatus.BANNED.value, AccountStatus.CLOSED.value]:
|
||||
raise Forbidden('Account is banned or closed.')
|
||||
|
||||
# init owner's tenant
|
||||
tenant_owner = TenantAccountJoin.query.filter_by(account_id=account.id, role='owner').first()
|
||||
if not tenant_owner:
|
||||
_create_tenant_for_account(account)
|
||||
|
||||
current_tenant = TenantAccountJoin.query.filter_by(account_id=account.id, current=True).first()
|
||||
if current_tenant:
|
||||
account.current_tenant_id = current_tenant.tenant_id
|
||||
account.current_tenant_id = current_tenant.tenant_id
|
||||
else:
|
||||
account.current_tenant_id = tenant_owner.tenant_id
|
||||
tenant_owner.current = True
|
||||
available_tenant = TenantAccountJoin.query.filter_by(account_id=account.id) \
|
||||
.order_by(TenantAccountJoin.id.asc()).first()
|
||||
if not available_tenant:
|
||||
raise Forbidden('No available tenant for the user.')
|
||||
|
||||
account.current_tenant_id = available_tenant.tenant_id
|
||||
available_tenant.current = True
|
||||
db.session.commit()
|
||||
|
||||
if datetime.utcnow() - account.last_active_at > timedelta(minutes=10):
|
||||
|
Loading…
x
Reference in New Issue
Block a user