ideas: add done/reopen status toggle for admins

Admin-only POST /api/ideas/{id}/status toggles status between open and
done. Done ideas are greyed out (opacity 0.55), show a green checkmark,
and sink to the bottom of the list. Admins see done/reopen buttons on
each card.
This commit is contained in:
Davide Scaini
2026-05-13 19:32:30 +02:00
parent 38f2e51788
commit c30a15d295
2 changed files with 66 additions and 11 deletions
+23 -1
View File
@@ -2750,7 +2750,7 @@ async def list_ideas(
idea["vote_count"] = len(votes)
idea["my_vote"] = user.handle in votes
ideas.append(idea)
ideas.sort(key=lambda x: (-x["vote_count"], -x["created_at"]))
ideas.sort(key=lambda x: (x.get("status") == "done", -x["vote_count"], -x["created_at"]))
return JSONResponse({"ideas": ideas})
@@ -2806,6 +2806,28 @@ async def toggle_idea_vote(
return JSONResponse({"voted": voted, "votes": len(votes)})
@app.post("/api/ideas/{idea_id}/status")
async def toggle_idea_status(
idea_id: str,
bincio_session: Optional[str] = Cookie(default=None),
) -> JSONResponse:
user = _require_user(bincio_session)
if not user.is_admin:
raise HTTPException(403, "Forbidden")
dd = _get_data_dir()
path = _ideas_dir(dd) / f"{idea_id}.json"
if not path.exists():
raise HTTPException(404, "Not found")
with open(path, "r+", encoding="utf-8") as f:
_fcntl.flock(f, _fcntl.LOCK_EX)
idea = json.load(f)
idea["status"] = "open" if idea.get("status") == "done" else "done"
f.seek(0)
f.truncate()
json.dump(idea, f, ensure_ascii=False, indent=2)
return JSONResponse({"status": idea["status"]})
@app.delete("/api/ideas/{idea_id}")
async def delete_idea(
idea_id: str,