admin felület különválasztva
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"""
|
||||
Szótárak és katalógusok végpontjai.
|
||||
- GET /dictionaries/cost-categories: Költségkategóriák lekérése visibility szerint szűrve
|
||||
(P0 3D Capability Matrix: filtered by resolved org capabilities)
|
||||
- CRUD /dictionaries/insurance-providers: Biztosítók katalógusa
|
||||
"""
|
||||
import logging
|
||||
@@ -17,6 +18,7 @@ from app.schemas.fleet_finance import (
|
||||
InsuranceProviderCreate,
|
||||
InsuranceProviderUpdate,
|
||||
)
|
||||
from app.services.capability_service import resolve_org_capabilities
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -31,7 +33,21 @@ async def list_cost_categories(
|
||||
"""
|
||||
Költségkategóriák lekérése hierarchikus struktúrában.
|
||||
Opcionálisan szűrhető visibility alapján (pl. ha a frontend csak a 'b2c' és 'both' kategóriákat akarja).
|
||||
|
||||
P0 3D Capability Matrix:
|
||||
- Resolves the active organization's capability matrix.
|
||||
- If the user is SUPERADMIN (Fast-Pass), all categories are returned.
|
||||
- Otherwise, categories with a required_feature are only included
|
||||
if the resolved capabilities have that feature set to True.
|
||||
"""
|
||||
# ── Determine active organization ──
|
||||
active_org_id: Optional[int] = None
|
||||
if hasattr(current_user, "active_organization_id") and current_user.active_organization_id:
|
||||
active_org_id = current_user.active_organization_id
|
||||
|
||||
# ── Resolve capabilities ──
|
||||
resolved_caps = await resolve_org_capabilities(current_user, active_org_id, db)
|
||||
|
||||
stmt = select(CostCategory).order_by(CostCategory.name)
|
||||
|
||||
if visibility:
|
||||
@@ -46,6 +62,14 @@ async def list_cost_categories(
|
||||
result = await db.execute(stmt)
|
||||
categories = result.scalars().all()
|
||||
|
||||
# ── P0 3D Capability Matrix: filter by required_feature ──
|
||||
is_superadmin = resolved_caps.get("_is_superadmin", False)
|
||||
if not is_superadmin:
|
||||
categories = [
|
||||
cat for cat in categories
|
||||
if not cat.required_feature or resolved_caps.get(cat.required_feature) is True
|
||||
]
|
||||
|
||||
# Hierarchikus struktúra építése
|
||||
category_map = {}
|
||||
root_categories = []
|
||||
@@ -60,6 +84,8 @@ async def list_cost_categories(
|
||||
"visibility": cat.visibility,
|
||||
"accounting_code": cat.accounting_code,
|
||||
"is_system": cat.is_system,
|
||||
"min_tier": cat.min_tier,
|
||||
"required_feature": cat.required_feature,
|
||||
"children": [],
|
||||
}
|
||||
category_map[cat.id] = cat_dict
|
||||
|
||||
Reference in New Issue
Block a user