Unverified Commit 92322449 authored by Bowen Liang's avatar Bowen Liang Committed by GitHub

fix recreating users' default tenant relations when loading user (#2408)

parent 476eb90a
...@@ -56,17 +56,18 @@ class AccountService: ...@@ -56,17 +56,18 @@ class AccountService:
if account.status in [AccountStatus.BANNED.value, AccountStatus.CLOSED.value]: if account.status in [AccountStatus.BANNED.value, AccountStatus.CLOSED.value]:
raise Forbidden('Account is banned or closed.') 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() current_tenant = TenantAccountJoin.query.filter_by(account_id=account.id, current=True).first()
if current_tenant: if current_tenant:
account.current_tenant_id = current_tenant.tenant_id account.current_tenant_id = current_tenant.tenant_id
account.current_tenant_id = current_tenant.tenant_id
else: else:
account.current_tenant_id = tenant_owner.tenant_id available_tenant = TenantAccountJoin.query.filter_by(account_id=account.id) \
tenant_owner.current = True .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() db.session.commit()
if datetime.utcnow() - account.last_active_at > timedelta(minutes=10): if datetime.utcnow() - account.last_active_at > timedelta(minutes=10):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment