diff --git a/app/api/v1/integrare_router.py b/app/api/v1/integrare_router.py index 1629cbf..d0ba372 100644 --- a/app/api/v1/integrare_router.py +++ b/app/api/v1/integrare_router.py @@ -21,6 +21,7 @@ from ...auth import _extract_key, account_for_key, resolve_account_id from ...config import get_settings from ...db import get_connection from ...mapping import account_or_default +from ...rar_env import rar_env_efectiv router = APIRouter(prefix="/v1", tags=["integrare"]) @@ -35,7 +36,8 @@ def ping( Intoarce: account_id — contul rezolvat din cheie (sau 1 in dev fara cheie) - mediu — "test" / "prod" (settings.rar_env) + mediu — mediul RAR efectiv al contului ("test"/"prod"), + nu ancora globala settings.rar_env autentificat_cu_cheie — True daca cererea a venit cu o cheie API reala valida are_creds_rar — True daca contul are creds RAR stocate pe cel putin un mediu (test sau prod) are_creds_test — True daca contul are creds RAR pentru mediul Testare @@ -62,7 +64,8 @@ def ping( conn = get_connection() try: row = conn.execute( - "SELECT rar_creds_test_enc, rar_creds_prod_enc FROM accounts WHERE id=?", (aid,) + "SELECT rar_test_enabled, rar_prod_enabled, rar_creds_test_enc, " + "rar_creds_prod_enc, rar_env_default FROM accounts WHERE id=?", (aid,) ).fetchone() finally: conn.close() @@ -71,9 +74,15 @@ def ping( are_creds_prod = bool(row and row["rar_creds_prod_enc"]) are_creds_rar = are_creds_test or are_creds_prod + # mediu = mediul RAR EFECTIV al contului (REQ-DEFAULT), nu ancora globala + # settings.rar_env: un cont cu doar creds de test trebuie sa raporteze "test" + # chiar daca serverul ruleaza global pe "prod". Fallback pe ancora globala doar + # cand contul nu are niciun mediu disponibil (rar_env_efectiv -> None). + mediu_efectiv = (rar_env_efectiv(row) if row else None) or settings.rar_env + return JSONResponse({ "account_id": aid, - "mediu": settings.rar_env, + "mediu": mediu_efectiv, "autentificat_cu_cheie": autentificat_cu_cheie, "are_creds_rar": are_creds_rar, "are_creds_test": are_creds_test,