ideas: add inline edit for own ideas (author + admin)

This commit is contained in:
Davide Scaini
2026-05-13 19:52:25 +02:00
parent aa1c0b38c0
commit b9a21e8bcc
2 changed files with 124 additions and 27 deletions
+28
View File
@@ -2828,6 +2828,34 @@ async def toggle_idea_status(
return JSONResponse({"status": idea["status"]})
@app.patch("/api/ideas/{idea_id}")
async def edit_idea(
idea_id: str,
data: IdeaBody,
bincio_session: Optional[str] = Cookie(default=None),
) -> JSONResponse:
user = _require_user(bincio_session)
dd = _get_data_dir()
path = _ideas_dir(dd) / f"{idea_id}.json"
if not path.exists():
raise HTTPException(404, "Not found")
title = data.title.strip()[:200]
body = data.body.strip()[:2000]
if not title:
raise HTTPException(400, "Title required")
with open(path, "r+", encoding="utf-8") as f:
_fcntl.flock(f, _fcntl.LOCK_EX)
idea = json.load(f)
if not user.is_admin and idea.get("author") != user.handle:
raise HTTPException(403, "Forbidden")
idea["title"] = title
idea["body"] = body
f.seek(0)
f.truncate()
json.dump(idea, f, ensure_ascii=False, indent=2)
return JSONResponse({"ok": True, "title": title, "body": body})
@app.delete("/api/ideas/{idea_id}")
async def delete_idea(
idea_id: str,