Adding AugmentedItem notes

This commit is contained in:
Ian Roddis committed 2026-07-31 09:12:41 -03:00
1 parent 30a13644ce
commit 34679d53e8
10 files changed
+254 -12

No files matched your search

+44 -1
View File
@@ -19,6 +19,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
from app.crud import audit as audit_crud
from app.crud import augmented_part as augmented_part_crud
from app.crud import augmented_part_note as augmented_part_note_crud
from app.crud import imported_part as imported_part_crud
from app.crud import imported_part_config as imported_part_config_crud
from app.crud import iso_thread as iso_thread_crud
@@ -1803,6 +1804,9 @@ async def augmented_part_detail(
),
"can_read_fits": can_read_fits,
"can_read_attachment_points": can_read_attachment_points,
"augmented_part_id": augmented_part_id,
"notes": ap.notes,
"can_write_notes": _can_write_augmented_part_notes(user),
}
if can_read_attachment_points:
ctx.update(
@@ -2333,7 +2337,9 @@ async def create_augmented_part_fit(
resource_type="Fit",
resource_id=fit.id,
description=audit_crud.describe_create(
"Fit", fit.id, f"attachment points {ap_a.id}↔{ap_b.id} ({label.value})"
"Fit",
fit.id,
f"attachment points {ap_a.id}↔{ap_b.id} ({label.value})",
),
)
if note.strip():
@@ -2464,6 +2470,43 @@ async def recompute_all_fits(
)
# --- Augmented Part Notes -------------------------------------------------
def _can_write_augmented_part_notes(user: User) -> bool:
return user.is_superuser or "augmented_parts:write" in user.permissions
@router.post(
"/augmented-parts/{augmented_part_id}/notes",
response_class=HTMLResponse,
)
async def create_augmented_part_note(
request: Request,
augmented_part_id: int,
body: str = Form(...),
db: AsyncSession = Depends(get_db),
actor: User = Depends(web_require("augmented_parts:write")),
):
ap = await augmented_part_crud.get(db, augmented_part_id)
if ap is None:
raise HTTPException(status_code=404, detail="Augmented part not found")
if body.strip():
await augmented_part_note_crud.create(
db, augmented_part=ap, author=actor, body=body.strip()
)
await db.refresh(ap, attribute_names=["notes"])
return templates.TemplateResponse(
request,
"admin/_augmented_part_notes.html",
{
"augmented_part_id": augmented_part_id,
"notes": ap.notes,
"can_write_notes": _can_write_augmented_part_notes(actor),
},
)
# --- Part Colours ------------------------------------------------------------