fix(relecture): un travail vide ou oublie restait affiche et impossible a retirer
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m29s

Un travail echoue ou expire cote serveur restait dans « Traductions
recentes » : sa page de relecture n'affichait rien (0 segments) avec une
erreur brute non traduite, et aucune suppression n'existait.

- serveur : nouvelle route DELETE /api/v1/translations/{job_id} —
  retire le travail de la memoire et de Redis, supprime ses segments de
  relecture ; idempotente (200 meme si le serveur avait deja oublie le
  travail) ; refuse les travaux en cours (annuler d'abord) ; proprietaire
  seul (404 pour le travail d'autrui, sans reveler son existence)
- interface : bouton corbeille sur chaque ligne des traductions recentes
  (deux clics pour confirmer) qui nettoie la liste locale ET le serveur ;
  l'historique serveur ne liste plus les travaux non termines
- page de relecture : message d'erreur traduit (fini le message brut) et
  etat « rien a relire » explicite avec explication
- libelles ajoutes dans les 13 langues de l'interface
- 5 tests backend nouveaux (tests/test_delete_translation_history.py)
This commit is contained in:
2026-09-01 21:22:05 +02:00
parent b3b5454f6f
commit 2abd0c0b26
21 changed files with 380 additions and 27 deletions

View File

@@ -71,7 +71,7 @@ from utils.file_handler import FileHandler
from middleware.metrics import record_translation, record_file_size
from services.progress_tracker import ProgressTracker
from services.storage_tracker import storage_tracker
from core.redis import set_job_status_async, get_job_status_async
from core.redis import set_job_status_async, get_job_status_async, delete_job_status_async
from services.glossary_service import get_glossary_terms, validate_glossary_access, build_full_prompt
from services.prompt_service import get_prompt_content, validate_prompt_access
from utils.exceptions import GlossaryNotFoundError, PromptNotFoundError
@@ -2257,6 +2257,92 @@ async def cancel_translation(
return {"data": {"id": job_id, "status": "cancelled"}, "meta": {}}
@router_v1.delete(
"/translations/{job_id}",
responses={
200: {"description": "Job removed from the user's history (idempotent)"},
401: {"description": "Authentication required"},
404: {"description": "Job belongs to another user"},
409: {"description": "Job is queued or processing — cancel it first"},
},
)
async def delete_translation(
job_id: str,
current_user: Optional[Any] = Depends(get_authenticated_user),
):
"""
Remove a translation job from the user's history.
Deletes the in-memory job record, its Redis status key and its stored
review segments. Idempotent: a job the server has already forgotten
(retention expiry, restart) still returns 200 so the client can clean
its own list. Only the owner may delete — the share token does not
grant deletion rights. Files on disk are left to the TTL cleanup.
"""
if current_user is None:
return JSONResponse(
status_code=401,
content={"error": "AUTH_REQUIRED", "message": "Authentication required."},
)
user_id = str(getattr(current_user, "id", ""))
job = _translation_jobs.get(job_id)
if not job:
job = await get_job_status_async(job_id)
if job:
# Do not reveal whether someone else's job exists: same 404 body.
if str(job.get("user_id", "")) != user_id:
return JSONResponse(
status_code=404,
content={
"error": "NOT_FOUND",
"message": "Translation job not found.",
"details": {"job_id": job_id},
},
)
if job.get("status") in ("queued", "processing"):
return JSONResponse(
status_code=409,
content={
"error": "JOB_IN_PROGRESS",
"message": "Cancel the job before deleting it.",
"details": {"job_id": job_id, "status": job.get("status")},
},
)
_translation_jobs.pop(job_id, None)
await delete_job_status_async(job_id)
def _delete_segments():
from database.connection import get_sync_session
from database.models import TranslationSegment
with get_sync_session() as session:
deleted = (
session.query(TranslationSegment)
.filter(TranslationSegment.job_id == job_id)
.delete()
)
session.commit()
return deleted
segments_deleted = 0
try:
segments_deleted = await asyncio.to_thread(_delete_segments)
except Exception as seg_err:
logger.warning(f"Job {job_id}: segment deletion failed: {seg_err}")
logger.info(
f"Job {job_id}: deleted from history by user "
f"(segments removed: {segments_deleted})"
)
return {
"data": {"id": job_id, "deleted": True, "segments_removed": segments_deleted},
"meta": {},
}
@router_v1.get("/translate/health")
async def translate_health():
"""Health check for translation endpoint."""