feat(admin): add subscription history, status override, and statuses constant

Adds four new DB helpers for the admin panel:
- SUBSCRIPTION_STATUSES: tuple of valid subscription statuses
- list_by_user(): retrieve all subscriptions for a user (newest first)
- set_status(): override a subscription's status and updated_at timestamp
- get_subscriber_state(): public wrapper for internal _get_state()

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Colin Maudry
2026-07-03 09:34:09 +02:00
parent 9ea8bee940
commit 0209ec0d5c
2 changed files with 73 additions and 0 deletions
+25
View File
@@ -123,6 +123,27 @@ def get_current(user_id: int) -> sqlite3.Row | None:
)
SUBSCRIPTION_STATUSES = ("active", "trial", "cancelled", "expired", "pending")
def list_by_user(user_id: int) -> list[sqlite3.Row]:
return (
get_conn()
.execute(
"SELECT * FROM subscriptions WHERE user_id = ? ORDER BY id DESC",
(user_id,),
)
.fetchall()
)
def set_status(subscription_id: int, status: str) -> None:
get_conn().execute(
"UPDATE subscriptions SET status = ?, updated_at = ? WHERE id = ?",
(status, _now(), subscription_id),
)
def get_by_handle(subscription_handle: str) -> sqlite3.Row | None:
return (
get_conn()
@@ -210,6 +231,10 @@ def _get_state(user_id: int) -> sqlite3.Row | None:
)
def get_subscriber_state(user_id: int) -> sqlite3.Row | None:
return _get_state(user_id)
def freeze_votes_cursor(user_id: int) -> None:
"""Réactivation après une période sans abonnement : repart de maintenant.