feat(#357): custom_field_definitions generisch — W4b-Muster (422/403-Entity-Checks, {items,total}-Shape, ACL-Fix), zentrale Helper, Plural-Ableitungs-Fix

This commit is contained in:
Agent Zero
2026-08-29 01:27:24 +02:00
parent 36dd7c5101
commit b5036a1fc0
8 changed files with 442 additions and 71 deletions
+6 -28
View File
@@ -18,37 +18,15 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.core.db import get_db
from app.deps import get_current_user
from app.models.saved_view import SavedView
from app.services.entity_permission_service import (
check_entity_read_permission as _check_entity_read,
)
from app.services.entity_permission_service import (
validate_entity_type as _validate_entity_type,
)
router = APIRouter(prefix="/api/v1/saved-views", tags=["saved-views"])
VALID_ENTITY_TYPES = None # Dynamic — validated against ENTITY_MODELS at runtime
def _validate_entity_type(entity_type: str) -> None:
"""Validate entity_type against ENTITY_MODELS. Raises HTTPException if invalid."""
from app.services.entity_permission_service import ENTITY_MODELS
if entity_type not in ENTITY_MODELS:
from fastapi import HTTPException
valid = sorted(ENTITY_MODELS.keys())
raise HTTPException(422, detail={
"detail": f"Invalid entity_type: {entity_type}",
"code": "invalid_entity_type",
"valid_types": valid,
})
def _check_entity_read(current_user: dict, entity_type: str) -> None:
"""Check that the user has read permission for the entity type."""
from app.core.permissions import check_permission
from app.services.entity_permission_service import get_entity_read_permission
perm = get_entity_read_permission(entity_type)
if not check_permission(current_user, perm):
raise HTTPException(403, detail={
"detail": f"Permission '{perm}' required",
"code": "forbidden",
})
class SavedViewCreate(BaseModel):
"""Schema for creating a saved view."""