Release v0.1.5

This commit is contained in:
2026-07-07 15:49:06 +02:00
commit c25e81fce9
45 changed files with 667 additions and 0 deletions
@@ -0,0 +1,26 @@
from __future__ import annotations
from govoplan_core.core.access import PrincipalRef, TenantRef, TenantResolver
from govoplan_core.db.session import get_database
from govoplan_tenancy.backend.db.models import Tenant
def _tenant_ref(tenant: Tenant) -> TenantRef:
return TenantRef(
id=tenant.id,
name=tenant.name,
slug=tenant.slug,
status="active" if tenant.is_active else "inactive",
)
class SqlTenantResolver(TenantResolver):
def get_tenant(self, tenant_id: str) -> TenantRef | None:
with get_database().session() as session:
tenant = session.get(Tenant, tenant_id)
return _tenant_ref(tenant) if tenant is not None else None
def current_tenant(self, principal: PrincipalRef) -> TenantRef | None:
if principal.tenant_id is None:
return None
return self.get_tenant(principal.tenant_id)