From 30ecf63e297e3e21f59aaf231ffc9180163ddcd8 Mon Sep 17 00:00:00 2001 From: Michael Woods Date: Fri, 26 Dec 2025 14:48:26 -0500 Subject: [PATCH] Bulletin delete usually working. One bulletin won't delete.. --- packetserver/http/routers/bulletins.py | 42 ++++++++++++++++++- .../http/templates/bulletin_detail.html | 26 ++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/packetserver/http/routers/bulletins.py b/packetserver/http/routers/bulletins.py index e99c7b2..a795621 100644 --- a/packetserver/http/routers/bulletins.py +++ b/packetserver/http/routers/bulletins.py @@ -6,6 +6,7 @@ from datetime import datetime import transaction from persistent.list import PersistentList from ZODB.Connection import Connection +import logging from packetserver.http.database import DbDependency from ..dependencies import get_current_http_user @@ -185,4 +186,43 @@ async def bulletin_detail_page( return templates.TemplateResponse( "bulletin_detail.html", {"request": request, "bulletin": bulletin, "current_user": current_user.username} - ) \ No newline at end of file + ) + +@router.delete("/bulletins/{bid}", status_code=204) +async def delete_bulletin( + bid: int, + db: DbDependency, + current_user: HttpUser = Depends(get_current_http_user) +): + username = current_user.username + + try: + with db.transaction() as conn: + root = conn.root() + bulletins_list: PersistentList = root.get("bulletins", PersistentList()) + + # Find the bulletin + bulletin_to_delete = None + for b in bulletins_list: + if b.id == bid: + bulletin_to_delete = b + break + + if not bulletin_to_delete: + raise HTTPException(status_code=404, detail="Bulletin not found") + + if bulletin_to_delete.author != username: + raise HTTPException(status_code=403, detail="Not authorized to delete this bulletin") + + # Remove it + bulletins_list.remove(bulletin_to_delete) + + logging.info(f"User {username} deleted bulletin {bid}") + + except HTTPException: + raise + except Exception as e: + logging.error(f"Bulletin delete failed for {username} on {bid}: {e}") + raise HTTPException(status_code=500, detail="Failed to delete bulletin") + + return None # 204 No Content \ No newline at end of file diff --git a/packetserver/http/templates/bulletin_detail.html b/packetserver/http/templates/bulletin_detail.html index 6391208..f7e2fd2 100644 --- a/packetserver/http/templates/bulletin_detail.html +++ b/packetserver/http/templates/bulletin_detail.html @@ -15,5 +15,31 @@ ← All Bulletins | Dashboard
Once you delete a bulletin, there is no going back. Please be certain.