02db5430eb
Security - Every route now requires a login and refuses ids outside the caller's workspace with 404: plan, leave-wishes, day-overrides and vacation-days were fully anonymous; every other router trusted client-supplied workspace/child/parent ids. Scraper sessions are bound to their owner. - Invitations can no longer be created for a foreign workspace, and a redeemer who is already a member (or a full workspace) is refused. - Production refuses the default JWT secret; API docs are hidden in production; a failed migration aborts startup instead of serving. - Login and register no longer reveal whether an email exists; inactive accounts are rejected; /auth/refresh is rate limited. - The FK scraper writes debug artefacts only when explicitly enabled, logs no scraped values or page text, clears the BankID QR as soon as it is scanned and purges finished sessions after five minutes. - Real FK page captures are removed from the tree (history rewrite follows); the parser tests use a synthetic fixture. Performance and correctness - Plan apply/sync run inside one locked transaction with batched writes instead of one commit per row, so a failure mid-batch leaves nothing half-applied and concurrent syncs no longer corrupt each other. - SQLite runs in WAL mode with a busy timeout; 14 indexes cover the filters that were full scans; argon2 hashing runs off the event loop; responses are gzipped. - Frontend: a 401 now refreshes the token once and retries, so sessions no longer die silently after 15 minutes; every data hook discards stale responses; logout clears state even when the server call fails. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CsXCCcDfmV4Sps4ZQSvNEY
54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
"""HTTP routes for vacation days.
|
|
|
|
Routers stay thin: validate via Pydantic, call the service, map domain errors to
|
|
HTTP. This is the REFERENCE router — copy this shape for other entities.
|
|
"""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, HTTPException, status
|
|
|
|
from app.dependencies import VacationDaysServiceDep, WorkspaceIdDep, WorkspaceScopeDep
|
|
from app.models.vacation_days import VacationDaysCreate, VacationDaysResponse
|
|
from app.utils.errors import NotFoundError, ValidationError
|
|
|
|
router = APIRouter(prefix="/api/vacation-days", tags=["vacation-days"])
|
|
|
|
|
|
@router.post("", response_model=VacationDaysResponse, status_code=status.HTTP_201_CREATED)
|
|
async def upsert_vacation_days(
|
|
payload: VacationDaysCreate, service: VacationDaysServiceDep, scope: WorkspaceScopeDep
|
|
) -> VacationDaysResponse:
|
|
scope.check_workspace(payload.workspace_id)
|
|
await scope.check_member(payload.personal_data_uuid)
|
|
try:
|
|
entity = await service.upsert(
|
|
personal_data_uuid=payload.personal_data_uuid,
|
|
workspace_id=payload.workspace_id,
|
|
year=payload.year,
|
|
total_days=payload.total_days,
|
|
saved_days_in=payload.saved_days_in,
|
|
)
|
|
except ValidationError as exc:
|
|
raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY, str(exc)) from exc
|
|
return VacationDaysResponse.from_entity(entity)
|
|
|
|
|
|
@router.get("/{vacation_days_id}", response_model=VacationDaysResponse)
|
|
async def get_vacation_days(
|
|
vacation_days_id: UUID, service: VacationDaysServiceDep, scope: WorkspaceScopeDep
|
|
) -> VacationDaysResponse:
|
|
try:
|
|
entity = await service.get(vacation_days_id, workspace_id=scope.workspace_id)
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|
|
return VacationDaysResponse.from_entity(entity)
|
|
|
|
|
|
@router.get("/workspace/{workspace_id}", response_model=list[VacationDaysResponse])
|
|
async def list_vacation_days(
|
|
workspace_id: WorkspaceIdDep, service: VacationDaysServiceDep
|
|
) -> list[VacationDaysResponse]:
|
|
entities = await service.list_for_workspace(workspace_id)
|
|
return [VacationDaysResponse.from_entity(e) for e in entities]
|