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
111 lines
3.8 KiB
Python
111 lines
3.8 KiB
Python
"""HTTP routes for planned leave days (calendar planning)."""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, HTTPException, Query, status
|
|
|
|
from app.dependencies import PlanningServiceDep, WorkspaceIdDep, WorkspaceScopeDep
|
|
from app.models.planned_leave import (
|
|
PlannedLeaveDayCreate,
|
|
PlannedLeaveDayResponse,
|
|
PlannedLeaveDayUpdate,
|
|
)
|
|
from app.utils.errors import NotFoundError, ValidationError
|
|
|
|
router = APIRouter(prefix="/api/planned-days", tags=["planned-days"])
|
|
|
|
|
|
def _to_response(day) -> PlannedLeaveDayResponse:
|
|
return PlannedLeaveDayResponse.from_entity(day)
|
|
|
|
|
|
@router.post("", response_model=PlannedLeaveDayResponse, status_code=status.HTTP_201_CREATED)
|
|
async def create_planned_day(
|
|
payload: PlannedLeaveDayCreate,
|
|
service: PlanningServiceDep,
|
|
scope: WorkspaceScopeDep,
|
|
) -> PlannedLeaveDayResponse:
|
|
scope.check_workspace(payload.workspace_id)
|
|
await scope.check_child(payload.child_id)
|
|
await scope.check_member(payload.parent_personal_data_uuid)
|
|
try:
|
|
day = await service.add_planned_day(
|
|
workspace_id=payload.workspace_id,
|
|
child_id=payload.child_id,
|
|
parent_personal_data_uuid=payload.parent_personal_data_uuid,
|
|
date=payload.date,
|
|
day_type=payload.day_type,
|
|
is_dubbeldag=payload.is_dubbeldag,
|
|
wish_id=payload.wish_id,
|
|
is_pinned=payload.is_pinned,
|
|
)
|
|
return _to_response(day)
|
|
except ValidationError as exc:
|
|
raise HTTPException(status.HTTP_422_UNPROCESSABLE_ENTITY, str(exc)) from exc
|
|
|
|
|
|
@router.get("", response_model=list[PlannedLeaveDayResponse])
|
|
async def list_planned_days(
|
|
service: PlanningServiceDep,
|
|
scope: WorkspaceScopeDep,
|
|
child_id: UUID = Query(...),
|
|
) -> list[PlannedLeaveDayResponse]:
|
|
await scope.check_child(child_id)
|
|
days = await service.list_by_child(child_id)
|
|
return [_to_response(d) for d in days]
|
|
|
|
|
|
@router.get("/{planned_leave_day_id}", response_model=PlannedLeaveDayResponse)
|
|
async def get_planned_day(
|
|
planned_leave_day_id: UUID,
|
|
service: PlanningServiceDep,
|
|
scope: WorkspaceScopeDep,
|
|
) -> PlannedLeaveDayResponse:
|
|
try:
|
|
day = await service.get(planned_leave_day_id, workspace_id=scope.workspace_id)
|
|
return _to_response(day)
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|
|
|
|
|
|
@router.get("/workspace/{workspace_id}", response_model=list[PlannedLeaveDayResponse])
|
|
async def list_planned_days_by_workspace(
|
|
workspace_id: WorkspaceIdDep,
|
|
service: PlanningServiceDep,
|
|
) -> list[PlannedLeaveDayResponse]:
|
|
days = await service.list_by_workspace(workspace_id)
|
|
return [_to_response(d) for d in days]
|
|
|
|
|
|
@router.put("/{planned_leave_day_id}", response_model=PlannedLeaveDayResponse)
|
|
async def update_planned_day(
|
|
planned_leave_day_id: UUID,
|
|
payload: PlannedLeaveDayUpdate,
|
|
service: PlanningServiceDep,
|
|
scope: WorkspaceScopeDep,
|
|
) -> PlannedLeaveDayResponse:
|
|
try:
|
|
day = await service.update(
|
|
planned_leave_day_id,
|
|
day_type=payload.day_type,
|
|
is_dubbeldag=payload.is_dubbeldag,
|
|
wish_id=payload.wish_id,
|
|
is_pinned=payload.is_pinned,
|
|
workspace_id=scope.workspace_id,
|
|
)
|
|
return _to_response(day)
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|
|
|
|
|
|
@router.delete("/{planned_leave_day_id}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_planned_day(
|
|
planned_leave_day_id: UUID,
|
|
service: PlanningServiceDep,
|
|
scope: WorkspaceScopeDep,
|
|
) -> None:
|
|
try:
|
|
await service.remove_planned_day(planned_leave_day_id, workspace_id=scope.workspace_id)
|
|
except NotFoundError as exc:
|
|
raise HTTPException(status.HTTP_404_NOT_FOUND, str(exc)) from exc
|