feat: prevent duplicate glossary presets + fix i18n source warning bug
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m5s

- Add template_id column to Glossary model (nullable, indexed)
- Backend: return 409 Conflict if user already imported a template
- Frontend: disable preset cards already imported, show 'Imported' badge
- Fix duplicated text in GlossarySelector source warning (hardcoded FR text removed)
- Complete i18n migration for glossaries page and GlossarySelector
- Add glossaries.presets.alreadyImported key in all 13 locales
This commit is contained in:
2026-06-01 23:39:53 +02:00
parent ce53f0df16
commit 818eac5490
6 changed files with 61 additions and 8 deletions

View File

@@ -58,6 +58,7 @@ def _format_glossary(glossary: Glossary) -> dict:
"name": glossary.name,
"source_language": glossary.source_language,
"target_language": getattr(glossary, "target_language", "multi") or "multi",
"template_id": getattr(glossary, "template_id", None),
"terms": [_format_term(t) for t in glossary.terms] if glossary.terms else [],
"created_at": glossary.created_at.isoformat() if glossary.created_at else None,
"updated_at": glossary.updated_at.isoformat() if glossary.updated_at else None,
@@ -591,13 +592,30 @@ async def import_glossary_template(
)
glossary_name = name or template_data.get("name", template_info.get("name", template_id))
with get_sync_session() as session:
# Check if user already imported this template
existing = (
session.query(Glossary)
.filter_by(user_id=user.id, template_id=template_id)
.first()
)
if existing:
return JSONResponse(
status_code=409,
content={
"error": "TEMPLATE_ALREADY_IMPORTED",
"message": f"You already have a glossary from the '{template_id}' template.",
"data": _format_glossary(existing),
},
)
glossary = Glossary(
user_id=user.id,
name=glossary_name,
source_language=template_info.get("source_lang", template_data.get("source_lang", "fr")),
target_language=template_info.get("target_lang", template_data.get("target_lang", "multi")),
template_id=template_id,
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc),
)