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:
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user