Moderation: Foto-Freigabe repariert (rasse_id join, delegate an wiki-API), SW by-v364

This commit is contained in:
rene 2026-04-25 09:41:56 +02:00
parent d603b7bae1
commit 034f7ef21f
3 changed files with 42 additions and 61 deletions

View file

@ -170,22 +170,20 @@ async def mod_patch_user(uid: int, data: dict, user=Depends(require_moderator)):
@router.get("/fotos")
async def mod_fotos(user=Depends(require_moderator)):
with db() as conn:
try:
rows = conn.execute("""
SELECT s.id, s.rasse_slug, s.foto_url, s.created_at,
COALESCE(s.rights_confirmed, 0) AS rights_confirmed,
u.name AS user_name,
r.name AS rasse_name, r.foto_url AS aktuell_foto
FROM wiki_foto_submissions s
LEFT JOIN users u ON u.id=s.user_id
LEFT JOIN wiki_rassen r ON r.slug=s.rasse_slug
WHERE s.status='pending'
ORDER BY s.created_at ASC
LIMIT 50
""").fetchall()
return [dict(r) for r in rows]
except Exception:
return []
rows = conn.execute("""
SELECT s.id, s.foto_url, s.created_at,
COALESCE(s.rights_confirmed, 0) AS rights_confirmed,
u.name AS user_name,
r.name AS rasse_name, r.slug AS rasse_slug,
r.foto_url AS aktuell_foto
FROM wiki_foto_submissions s
LEFT JOIN users u ON u.id = s.user_id
LEFT JOIN wiki_rassen r ON r.id = s.rasse_id
WHERE s.status = 'pending'
ORDER BY s.created_at ASC
LIMIT 50
""").fetchall()
return [dict(r) for r in rows]
# ------------------------------------------------------------------
@ -193,32 +191,10 @@ async def mod_fotos(user=Depends(require_moderator)):
# ------------------------------------------------------------------
@router.patch("/fotos/{foto_id}")
async def mod_foto_action(foto_id: int, data: dict, user=Depends(require_moderator)):
action = data.get("action")
if action not in ("approve", "reject"):
raise HTTPException(400, "action muss 'approve' oder 'reject' sein.")
with db() as conn:
sub = conn.execute(
"SELECT id, rasse_slug, foto_url FROM wiki_foto_submissions WHERE id=?",
(foto_id,)
).fetchone()
if not sub:
raise HTTPException(404, "Einreichung nicht gefunden.")
if action == "approve":
conn.execute(
"UPDATE wiki_foto_submissions SET status='approved' WHERE id=?",
(foto_id,)
)
conn.execute(
"UPDATE wiki_rassen SET foto_url=? WHERE slug=?",
(sub["foto_url"], sub["rasse_slug"])
)
else:
reason = data.get("reject_reason", "Nicht geeignet.")
conn.execute(
"UPDATE wiki_foto_submissions SET status='rejected', reject_reason=? WHERE id=?",
(reason, foto_id)
)
return {"ok": True}
"""Delegiert an die wiki-Route — dort ist die vollständige Logik (inkl. Datei-Kopie)."""
from routes.wiki import review_submission, ReviewModel
model = ReviewModel(
action=data.get("action", ""),
reject_reason=data.get("reject_reason", ""),
)
return await review_submission(foto_id, model, user)