Ideas: add 'won't implement' status with decline/reopen button
This commit is contained in:
@@ -45,7 +45,7 @@ async def list_ideas(
|
||||
ideas.append(idea)
|
||||
def _sort_key(x: dict):
|
||||
s = x.get("status") or "open"
|
||||
order = {"awaiting": 0, "open": 1, "done": 2}
|
||||
order = {"awaiting": 0, "open": 1, "done": 2, "declined": 3}
|
||||
return (order.get(s, 1), -x["vote_count"], -x["created_at"])
|
||||
ideas.sort(key=_sort_key)
|
||||
return JSONResponse({"ideas": ideas})
|
||||
@@ -126,6 +126,28 @@ async def toggle_idea_status(
|
||||
return JSONResponse({"status": idea["status"]})
|
||||
|
||||
|
||||
@router.post("/api/ideas/{idea_id}/decline")
|
||||
async def decline_idea(
|
||||
idea_id: str,
|
||||
bincio_session: Optional[str] = Cookie(default=None),
|
||||
) -> JSONResponse:
|
||||
user = deps._require_user(bincio_session)
|
||||
if not user.is_admin:
|
||||
raise HTTPException(403, "Forbidden")
|
||||
dd = deps._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") == "declined" else "declined"
|
||||
f.seek(0)
|
||||
f.truncate()
|
||||
json.dump(idea, f, ensure_ascii=False, indent=2)
|
||||
return JSONResponse({"status": idea["status"]})
|
||||
|
||||
|
||||
@router.post("/api/ideas/{idea_id}/comment")
|
||||
async def set_idea_comment(
|
||||
idea_id: str,
|
||||
|
||||
Reference in New Issue
Block a user