feat(пополнение): ручки /api/topups, возврат кнопкой, страница результата, финансы и допуск по счёту
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-2
@@ -155,6 +155,12 @@ def provider_chain(username: str) -> list[ProviderProfile]:
|
||||
return [primary, secondary]
|
||||
|
||||
|
||||
def _account_positive(username: str) -> bool:
|
||||
import balance
|
||||
st = balance.state(username)
|
||||
return bool(st) and not st["exhausted"]
|
||||
|
||||
|
||||
def agent_allowed(username: str) -> bool:
|
||||
"""Гейт дорогого агентного пути (Ф1 публичного запуска, docs/PUBLIC_LAUNCH_PLAN.md).
|
||||
|
||||
@@ -194,7 +200,7 @@ def agent_allowed(username: str) -> bool:
|
||||
return False # записи нет — читать её поля нечем (зайка 08.09.2026)
|
||||
paid = db.has_successful_payment(username) and \
|
||||
float(row.get("agent_paid_until") or 0) > time.time()
|
||||
if not (paid or row.get("agent_access")):
|
||||
if not (paid or row.get("agent_access") or _account_positive(username)):
|
||||
return False
|
||||
# C6: блокировка действует НЕМЕДЛЕННО на money-path (JWT живёт 24ч — на подпись не
|
||||
# полагаемся). Нет строки в БД (env-only/удалён) → доступа к дорогому пути нет.
|
||||
@@ -203,7 +209,11 @@ def agent_allowed(username: str) -> bool:
|
||||
if row.get("agent_access"):
|
||||
return True
|
||||
# Оплаченный период (этап 3): сравнение с текущим временем, продление — payments.
|
||||
return float(row.get("agent_paid_until") or 0) > time.time()
|
||||
if float(row.get("agent_paid_until") or 0) > time.time():
|
||||
return True
|
||||
# Счёт в плюсе (28.10.2026): заплативший через пополнение не остаётся без агента в
|
||||
# день, когда саморегистрация откроется с agent_access=0.
|
||||
return _account_positive(username)
|
||||
except Exception: # noqa: BLE001 — fail-closed, см. docstring
|
||||
logging.getLogger("smeta_web").exception("agent_allowed: сбой БД — режем агентный путь")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user