Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(documents): validate design_id on creation — reject nonexistent designs with 404

slmingol9a60b99cc609
diff --git a/backend/app/api/routes/documents.py b/backend/app/api/routes/documents.py
index a91521a..9d8b96b 100644
--- a/backend/app/api/routes/documents.py
+++ b/backend/app/api/routes/documents.py
@@ -23,7 +23,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.api.deps import get_current_user
from app.db.database import get_db
-from app.db.models import Document, DocumentRevision, Edge, InventoryDevice, Node, Rack, RackDevice
+from app.db.models import Design, Document, DocumentRevision, Edge, InventoryDevice, Node, Rack, RackDevice
from app.schemas.documents import (
BacklinkHit,
CoverageResponse,
@@ -520,6 +520,7 @@ async def create_document(
for link, model, what in (
(body.device_id, InventoryDevice, "Device"),
(body.node_id, Node, "Node"),
+ (body.design_id, Design, "Design"),
):
if link and not await db.get(model, link):
raise HTTPException(404, f"{what} not found")
diff --git a/backend/tests/test_documents.py b/backend/tests/test_documents.py
index f0bbcf6..7d228da 100644
--- a/backend/tests/test_documents.py
+++ b/backend/tests/test_documents.py
@@ -131,6 +131,15 @@ async def test_create_rejects_a_device_that_does_not_exist(client: AsyncClient,
assert res.status_code == 404
+async def test_create_rejects_a_design_that_does_not_exist(client: AsyncClient, headers: dict):
+ res = await client.post(
+ "/api/v1/documents",
+ json={"title": "X", "kind": "design", "design_id": str(uuid.uuid4())},
+ headers=headers,
+ )
+ assert res.status_code == 404
+
+
async def test_a_device_gets_at_most_one_document(client: AsyncClient, headers: dict):
device = await _device(client, headers)
body = {"title": "nas", "kind": "device", "device_id": device["id"]}