fix(translate): enforce Pro feature gating for glossary, custom_prompt and prompt_id
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m40s

This commit is contained in:
2026-06-14 18:40:45 +02:00
parent f05399aeba
commit cb8ce697d2

View File

@@ -573,13 +573,28 @@ async def translate_document_v1(
if prompt_id in ("null", "undefined", ""): prompt_id = None
if file_url in ("null", "undefined", ""): file_url = None
# Story 3.12 / Bugfix: If user is on the free tier, they might have stale Pro features
# Story 3.12 / Bugfix: If user is on the free tier, they might have stale Pro features
# in their frontend localStorage (e.g., they downgraded, or switched accounts).
# Instead of hard-blocking the translation, we simply strip the Pro features.
# These features require a paid plan.
if tier == "free":
glossary_id = None
custom_prompt = None
prompt_id = None
if glossary_id:
raise TranslateEndpointError(
code=TranslateEndpointError.PRO_FEATURE_REQUIRED,
message="Glossaries are reserved for Pro users.",
details={"feature": "glossary_id", "tier": tier},
)
if custom_prompt:
raise TranslateEndpointError(
code=TranslateEndpointError.PRO_FEATURE_REQUIRED,
message="Custom prompts are reserved for Pro users.",
details={"feature": "custom_prompt", "tier": tier},
)
if prompt_id:
raise TranslateEndpointError(
code=TranslateEndpointError.PRO_FEATURE_REQUIRED,
message="Saved prompts are reserved for Pro users.",
details={"feature": "prompt_id", "tier": tier},
)
if file_url:
if tier == "free":