Candidates: inline rename (fix a name typo without reject + re-add)
A staged candidate could only be renamed by rejecting and re-adding it, which
churns the queue and discards the preview just to fix a typo. Add an inline
Rename on each candidate: a "Rename" pill swaps the name for an input
(Enter saves · Esc cancels), POST /api/admin/candidates/{id}/rename →
sources.rename_candidate(). Empty clears the name (promote then derives one
from the feed host). Preview is preserved; the fixed name carries into promotion.
Tests: test_candidate_rename (rename in place keeps preview, promotes with the
new name, gated + 404). 225 pytest + 11 vitest green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -169,6 +169,24 @@ def test_candidate_deep_preview_and_dedup(tmp_path, monkeypatch):
|
||||
assert tc.post(f"/api/admin/candidates/{cand['id']}/promote", json={}).status_code == 409
|
||||
|
||||
|
||||
def test_candidate_rename(tmp_path, monkeypatch):
|
||||
app, api = _make(tmp_path, monkeypatch, admin_email="boss@x.com")
|
||||
monkeypatch.setattr(api.feeds, "preview_feed", lambda url, **k: {"url": url, "sampled": 3, "accepted": 2})
|
||||
tc = _signin(app, api, "boss@x.com")
|
||||
cand = tc.post("/api/admin/candidates", json={"feed_url": "http://site/feed", "name": "Wrong Naem"}).json()
|
||||
cid = cand["id"]
|
||||
# Fix the typo in place — no reject/re-add, preview is preserved.
|
||||
fixed = tc.post(f"/api/admin/candidates/{cid}/rename", json={"name": "Right Name"}).json()
|
||||
assert fixed["name"] == "Right Name" and fixed["preview"]["accepted"] == 2
|
||||
assert any(c["id"] == cid and c["name"] == "Right Name" for c in tc.get("/api/admin/candidates").json())
|
||||
# The fixed name carries through to promotion.
|
||||
res = tc.post(f"/api/admin/candidates/{cid}/promote", json={}).json()
|
||||
assert res["source"]["name"] == "Right Name"
|
||||
# Gated; unknown id → 404.
|
||||
assert TestClient(app).post(f"/api/admin/candidates/{cid}/rename", json={"name": "x"}).status_code == 401
|
||||
assert tc.post("/api/admin/candidates/99999/rename", json={"name": "x"}).status_code == 404
|
||||
|
||||
|
||||
def test_candidate_reject_and_gating(tmp_path, monkeypatch):
|
||||
app, api = _make(tmp_path, monkeypatch, admin_email="boss@x.com")
|
||||
monkeypatch.setattr(api.feeds, "preview_feed", lambda url, **k: {"url": url, "sampled": 1, "accepted": 0})
|
||||
|
||||
Reference in New Issue
Block a user