TorbatYar/backend/shared-lib/shared/auth/roles.py
Mortezakoohjani 800b0ba2c5 Deploy TorbatYar for torbatyar.ir with nginx multi-tenant routing.
Wire production domain, CORS for tenant subdomains, celery volume mounts, and nginx reverse proxy configs for apex, API, identity, auth, and wildcard tenants.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-21 21:43:33 +03:30

25 lines
734 B
Python

"""نقش‌های استاندارد پلتفرم (هماهنگ با Keycloak realm)."""
from __future__ import annotations
import enum
from shared.security import CurrentUser
class PlatformRole(str, enum.Enum):
PLATFORM_ADMIN = "platform_admin"
TENANT_ADMIN = "tenant_admin"
TENANT_MEMBER = "tenant_member"
PENDING_TENANT_ADMIN = "pending_tenant_admin"
USER = "user"
SERVICE_ACCOUNT = "service_account"
def has_role(user: CurrentUser, role: str | PlatformRole) -> bool:
role_value = role.value if isinstance(role, PlatformRole) else role
return role_value in user.roles
def has_any_role(user: CurrentUser, *roles: str | PlatformRole) -> bool:
return any(has_role(user, r) for r in roles)