chore: use TenantAccountRole instead of TenantAccountJoinRole (#15514)

Co-authored-by: 刘江波 <jiangbo721@163.com>
This commit is contained in:
jiangbo721
2025-03-12 12:56:30 +08:00
committed by GitHub
parent 545e5cbcd6
commit 0415cc209d
4 changed files with 8 additions and 20 deletions

View File

@@ -28,7 +28,6 @@ from models.account import (
AccountStatus,
Tenant,
TenantAccountJoin,
TenantAccountJoinRole,
TenantAccountRole,
TenantStatus,
)
@@ -625,8 +624,8 @@ class TenantService:
@staticmethod
def create_tenant_member(tenant: Tenant, account: Account, role: str = "normal") -> TenantAccountJoin:
"""Create tenant member"""
if role == TenantAccountJoinRole.OWNER.value:
if TenantService.has_roles(tenant, [TenantAccountJoinRole.OWNER]):
if role == TenantAccountRole.OWNER.value:
if TenantService.has_roles(tenant, [TenantAccountRole.OWNER]):
logging.error(f"Tenant {tenant.id} has already an owner.")
raise Exception("Tenant already has an owner.")
@@ -734,10 +733,10 @@ class TenantService:
return updated_accounts
@staticmethod
def has_roles(tenant: Tenant, roles: list[TenantAccountJoinRole]) -> bool:
def has_roles(tenant: Tenant, roles: list[TenantAccountRole]) -> bool:
"""Check if user has any of the given roles for a tenant"""
if not all(isinstance(role, TenantAccountJoinRole) for role in roles):
raise ValueError("all roles must be TenantAccountJoinRole")
if not all(isinstance(role, TenantAccountRole) for role in roles):
raise ValueError("all roles must be TenantAccountRole")
return (
db.session.query(TenantAccountJoin)
@@ -749,7 +748,7 @@ class TenantService:
)
@staticmethod
def get_user_role(account: Account, tenant: Tenant) -> Optional[TenantAccountJoinRole]:
def get_user_role(account: Account, tenant: Tenant) -> Optional[TenantAccountRole]:
"""Get the role of the current account for a given tenant"""
join = (
db.session.query(TenantAccountJoin)