Adding ability to edit attachment points on augmented item details

This commit is contained in:
Ian Roddis committed 2026-07-28 22:04:40 -03:00
1 parent 25fccd617f
commit aef60d77be
5 files changed
+83 -37

No files matched your search

+43 -11
View File
@@ -1792,17 +1792,26 @@ async def augmented_part_detail(
if ap is None:
raise HTTPException(status_code=404, detail="Augmented part not found")
can_read_fits = user.is_superuser or "fits:read" in user.permissions
can_read_attachment_points = (
user.is_superuser or "attachment_points:read" in user.permissions
)
ctx = {
"user": user,
"ap": ap,
"scope_info": await scope_info_crud.get_by_augmented_part(
db, augmented_part_id
),
"attachment_points": await attachment_point_crud.list_for_augmented_part(
db, augmented_part_id
),
"can_read_fits": can_read_fits,
"can_read_attachment_points": can_read_attachment_points,
}
if can_read_attachment_points:
ctx.update(
await _augmented_part_ap_ctx(
db,
augmented_part_id,
can_write=_can_write_attachment_points(user),
)
)
if can_read_fits:
ctx.update(
await _augmented_part_fits_ctx(
@@ -1909,7 +1918,13 @@ async def delete_augmented_part(
return Response(status_code=status.HTTP_200_OK)
async def _augmented_part_ap_ctx(db: AsyncSession, augmented_part_id: int) -> dict:
def _can_write_attachment_points(user: User) -> bool:
return user.is_superuser or "attachment_points:write" in user.permissions
async def _augmented_part_ap_ctx(
db: AsyncSession, augmented_part_id: int, *, can_write: bool = True
) -> dict:
return {
"augmented_part_id": augmented_part_id,
"attachment_points_list": await attachment_point_crud.list_for_augmented_part(
@@ -1920,6 +1935,7 @@ async def _augmented_part_ap_ctx(db: AsyncSession, augmented_part_id: int) -> di
"unc_threads": await unc_thread_crud.list_all(db),
"clamp_connections": await clamp_connection_crud.list_all(db),
"static_connections": await static_connection_crud.list_all(db),
"can_write_attachment_points": can_write,
}
@@ -1931,9 +1947,11 @@ async def augmented_part_attachment_points(
request: Request,
augmented_part_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(web_require("attachment_points:read")),
user: User = Depends(web_require("attachment_points:read")),
):
ctx = await _augmented_part_ap_ctx(db, augmented_part_id)
ctx = await _augmented_part_ap_ctx(
db, augmented_part_id, can_write=_can_write_attachment_points(user)
)
return templates.TemplateResponse(
request, "admin/_augmented_part_attachment_points.html", ctx
)
@@ -1976,7 +1994,9 @@ async def create_augmented_part_attachment_point(
"AttachmentPoint", apoint.id, f"part {augmented_part_id}"
),
)
ctx = await _augmented_part_ap_ctx(db, augmented_part_id)
ctx = await _augmented_part_ap_ctx(
db, augmented_part_id, can_write=_can_write_attachment_points(actor)
)
return templates.TemplateResponse(
request, "admin/_augmented_part_attachment_points.html", ctx
)
@@ -2022,13 +2042,18 @@ async def augmented_part_attachment_point_row(
augmented_part_id: int,
attachment_point_id: int,
db: AsyncSession = Depends(get_db),
_: User = Depends(web_require("attachment_points:read")),
user: User = Depends(web_require("attachment_points:read")),
):
apoint = await attachment_point_crud.get(db, attachment_point_id)
if apoint is None:
raise HTTPException(status_code=404, detail="Attachment point not found")
return templates.TemplateResponse(
request, "admin/_augmented_part_ap_row.html", {"apoint": apoint}
request,
"admin/_augmented_part_ap_row.html",
{
"apoint": apoint,
"can_write_attachment_points": _can_write_attachment_points(user),
},
)
@@ -2075,7 +2100,12 @@ async def update_augmented_part_attachment_point(
),
)
return templates.TemplateResponse(
request, "admin/_augmented_part_ap_row.html", {"apoint": apoint}
request,
"admin/_augmented_part_ap_row.html",
{
"apoint": apoint,
"can_write_attachment_points": _can_write_attachment_points(actor),
},
)
@@ -2103,7 +2133,9 @@ async def delete_augmented_part_attachment_point(
"AttachmentPoint", attachment_point_id, f"part {augmented_part_id}"
),
)
ctx = await _augmented_part_ap_ctx(db, augmented_part_id)
ctx = await _augmented_part_ap_ctx(
db, augmented_part_id, can_write=_can_write_attachment_points(actor)
)
return templates.TemplateResponse(
request, "admin/_augmented_part_attachment_points.html", ctx
)