|
@@ -8,7 +8,7 @@ from typing import Any, Optional
|
|
|
|
|
|
from flask import current_app
|
|
from flask import current_app
|
|
from sqlalchemy import func
|
|
from sqlalchemy import func
|
|
-from werkzeug.exceptions import Forbidden
|
|
+from werkzeug.exceptions import Unauthorized
|
|
|
|
|
|
from constants.languages import language_timezone_mapping, languages
|
|
from constants.languages import language_timezone_mapping, languages
|
|
from events.tenant_event import tenant_was_created
|
|
from events.tenant_event import tenant_was_created
|
|
@@ -44,7 +44,7 @@ class AccountService:
|
|
return None
|
|
return None
|
|
|
|
|
|
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 Unauthorized("Account is banned or closed.")
|
|
|
|
|
|
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:
|
|
@@ -255,7 +255,7 @@ class TenantService:
|
|
"""Get account join tenants"""
|
|
"""Get account join tenants"""
|
|
return db.session.query(Tenant).join(
|
|
return db.session.query(Tenant).join(
|
|
TenantAccountJoin, Tenant.id == TenantAccountJoin.tenant_id
|
|
TenantAccountJoin, Tenant.id == TenantAccountJoin.tenant_id
|
|
- ).filter(TenantAccountJoin.account_id == account.id).all()
|
|
+ ).filter(TenantAccountJoin.account_id == account.id, Tenant.status == TenantStatus.NORMAL).all()
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def get_current_tenant_by_account(account: Account):
|
|
def get_current_tenant_by_account(account: Account):
|
|
@@ -279,7 +279,12 @@ class TenantService:
|
|
if tenant_id is None:
|
|
if tenant_id is None:
|
|
raise ValueError("Tenant ID must be provided.")
|
|
raise ValueError("Tenant ID must be provided.")
|
|
|
|
|
|
- tenant_account_join = TenantAccountJoin.query.filter_by(account_id=account.id, tenant_id=tenant_id).first()
|
|
+ tenant_account_join = db.session.query(TenantAccountJoin).join(Tenant, TenantAccountJoin.tenant_id == Tenant.id).filter(
|
|
|
|
+ TenantAccountJoin.account_id == account.id,
|
|
|
|
+ TenantAccountJoin.tenant_id == tenant_id,
|
|
|
|
+ Tenant.status == TenantStatus.NORMAL,
|
|
|
|
+ ).first()
|
|
|
|
+
|
|
if not tenant_account_join:
|
|
if not tenant_account_join:
|
|
raise AccountNotLinkTenantError("Tenant not found or account is not a member of the tenant.")
|
|
raise AccountNotLinkTenantError("Tenant not found or account is not a member of the tenant.")
|
|
else:
|
|
else:
|