A9: operations console, three pause commands, admin and player reports (WEB-30..32, WEB-40..44, WEB-55, AUD-48)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 15:03:22 +01:00
1 parent 3d1e820564
commit eab141f467
24 files changed
+928 -11

No files matched your search

+11
View File
@@ -698,3 +698,14 @@ nome tra parentesi quadre nel log è il modulo (`app.rounds.scheduler`, ecc.).
*Stato:* implementato (A2) ·
*Codice:* `apps/lottery/audit.py:record`, `apps/lottery/models.py:AuditEntry`, `apps/lottery/migrations/0002_audit_append_only_triggers.py` ·
*Test:* `tests/django/test_models.py::test_an_audit_row_cannot_be_changed_with_raw_sql_either`, `test_the_audit_is_written_in_the_same_transaction_as_the_change`
- **[AUD-48]** **Azioni della console, delle segnalazioni e degli utenti.** Ogni comando di `/ops/` scrive una riga con attore,
motivo (obbligatorio, 5–500 caratteri) e `payload {"command"}`: `pause_after_round_enabled`/`pause_after_round_disabled`,
`new_bets_suspended`/`new_bets_resumed`, `withdrawals_suspended`/`withdrawals_resumed` ([WEB-40](sito-e-app.md),
[WEB-41](sito-e-app.md), [WEB-42](sito-e-app.md)). Un comando negato (giocatore o staff senza il permesso) scrive la stessa
azione con esito `denied` e nessun cambiamento; un comando già nello stato richiesto non scrive nulla. Le segnalazioni scrivono
`report_submitted` (invio) e `report_status_changed` (`payload {"from", "to"}`, da `/admin/`); la modifica di `is_active`,
`is_staff` o `is_superuser` di un utente in `/admin/` scrive `user_changed`.
*Stato:* implementato (A9) ·
*Codice:* `apps/lottery/console.py:run_command`, `apps/lottery/admin.py:ReportAdmin.save_model`, `apps/accounts/admin.py:AccountAdmin.save_model`, `apps/accounts/views.py:report_view` ·
*Test:* `tests/django/test_console.py::test_each_command_switches_only_its_own_flag_and_is_audited`, `test_a_player_cannot_run_a_command_and_the_refusal_is_audited`, `test_changing_a_report_status_in_the_admin_is_audited`, `test_deactivating_a_user_in_the_admin_is_audited`
+2 -2
View File
@@ -4,7 +4,7 @@
## Project status (old stack)
All 10 stages of the original build order are code-complete and unit-tested — 1120 tests, the old stack's under `tests/unit/` and the Django ones under `tests/django/` (`tests/integration/` is an empty package). Beyond them: Docker + Caddy deployment, admin dashboard (`/admin`), static test UI (`/`), pending-inclusive balance display, an SSE push channel layered over the original polling, self-service password change + admin password reset, and the reconciliation/corroboration machinery below.
All 10 stages of the original build order are code-complete and unit-tested — 1156 tests, the old stack's under `tests/unit/` and the Django ones under `tests/django/` (`tests/integration/` is an empty package). Beyond them: Docker + Caddy deployment, admin dashboard (`/admin`), static test UI (`/`), pending-inclusive balance display, an SSE push channel layered over the original polling, self-service password change + admin password reset, and the reconciliation/corroboration machinery below.
Verified on mainnet with real money: registration + address derivation, deposit crediting (at the time, 1-conf; deposits now need `deposit_confirmations`), a real 10 PLM bet (broadcast → confirmed → change credited back), and one full round cycle (close → draw on a real block hash → 70/30 payout with sat math checked against the broadcast tx → confirmation → close → next round auto-opened). **Withdrawal and the RBF bump path have never been exercised against a live broadcast** — unit-tested only.
@@ -30,7 +30,7 @@ PYTHONPATH=. python scripts/decrypt_master_key.py # ops recovery: decrypt+pr
PYTHONPATH=. python scripts/encrypt_master_key.py # ops bootstrap: import an externally-generated xprv (--overwrite to replace)
PYTHONPATH=. python scripts/electrum_smoke_test.py # manual check: connect, handshake, subscribe to headers, print the tip
python -m pytest # all 1120 tests
python -m pytest # all 1156 tests
python -m pytest tests/unit/test_hd.py # one file
python -m pytest tests/unit/test_hd.py::test_derivation_is_deterministic # one test
```
+9 -1
View File
@@ -168,12 +168,15 @@ backend FastAPI (vedi [architettura.md](architettura.md)).
- **[WEB-30]** Ogni operatore ha un account staff individuale; `/ops/` e
`/admin/` richiedono i permessi espliciti, verificati nelle viste e nelle azioni.
*Stato:* implementato (A9): quattro permessi `lottery.view_console`, `pause_after_round`, `suspend_new_bets`, `suspend_withdrawals`; un giocatore o uno staff senza permesso riceve 403, un anonimo è rimandato ad `/accedi/` · *Codice:* `apps/ops/views.py`, `apps/lottery/console.py:can_view`, `can_run` · *Test:* `tests/django/test_console.py::test_a_player_cannot_open_the_console`, `test_staff_without_the_permission_cannot_open_the_console`
- **[WEB-31]** `/ops/` mostra round in corso, prossima scadenza, salute di
Electrum e del worker, operazioni in ritardo, ultima riconciliazione e il
motivo di eventuali pause.
*Stato:* implementato (A9) per round, scadenza, worker (battito scritto a ogni tick, «fermo» oltre 30 s), operazioni in ritardo (in attesa da oltre 10 minuti) e motivo delle pause; Electrum e ultima riconciliazione arrivano con la fase B (la pagina lo dice) · *Codice:* `apps/lottery/console.py:console_state`, `beat`, `late_operations` · *Test:* `tests/django/test_console.py::test_the_worker_tick_leaves_a_heartbeat`, `test_a_silent_worker_is_reported_as_stopped`, `test_operations_pending_for_too_long_are_listed`, `test_the_pause_reason_is_shown_while_it_lasts`
- **[WEB-32]** Django Admin gestisce utenti e segnalazioni; round chiusi,
transazioni e audit sono in sola lettura. Le azioni operative passano dai
servizi della lotteria e registrano attore, data, azione, motivo ed esito.
*Stato:* implementato (A9): round, partecipazioni, movimenti, transazioni e audit senza aggiunta, modifica o cancellazione; l'utente non si cancella, la scheda mostra puntate e movimenti in sola lettura, e un cambio di `is_active`/`is_staff`/`is_superuser` è nell'audit ([AUD-48](audit-log.md)) · *Codice:* `apps/lottery/admin.py`, `apps/accounts/admin.py` · *Test:* `tests/django/test_console.py::test_game_records_are_read_only_in_the_admin`, `test_a_user_page_shows_game_records_and_cannot_delete_the_user`
- **[WEB-33]** Il recupero delle chiavi non è esposto dal pannello web: è una
procedura dedicata fuori dal web.
- **[WEB-34]** La MFA TOTP e il recupero dell'accesso sono requisiti di uscita
@@ -184,15 +187,20 @@ backend FastAPI (vedi [architettura.md](architettura.md)).
- **[WEB-40]** «Pausa dopo il round in corso»: il round attivo continua fino
al pagamento, il successivo resta sospeso.
*Stato:* implementato (A9) · *Codice:* `apps/lottery/console.py:COMMANDS`, `apps/lottery/lifecycle.py:open_new_round_if_needed` · *Test:* `tests/django/test_console.py::test_pausing_after_the_round_stops_the_next_one_from_opening`
- **[WEB-41]** «Sospendi nuove puntate»: comando distinto per gli incidenti;
nessuna nuova puntata, ma le operazioni già inviate restano monitorate.
*Stato:* implementato (A9): la home mostra «Manutenzione» e la puntata è rifiutata dal servizio · *Test:* `tests/django/test_console.py::test_suspending_bets_shows_maintenance_on_the_site_and_refuses_a_bet`
- **[WEB-42]** La sospensione dei prelievi è un comando separato dalle altre due.
*Stato:* implementato (A9) come interruttore separato con il proprio permesso; i prelievi esistono solo dalla fase B, quindi per ora ne cambia solo lo stato · *Test:* `tests/django/test_console.py::test_a_permission_for_one_command_does_not_open_the_others`
- **[WEB-43]** Pausa, ripresa e modifiche critiche richiedono conferma e
motivazione; la console mostra quali operazioni continuano e quali verifiche
servono prima della ripresa. Le pause automatiche si riesaminano dal servizio applicativo.
*Stato:* implementato (A9): la pagina del comando elenca cosa continua e, per la ripresa, le verifiche da fare con lo stato di worker e ritardi; servono motivo e conferma, e un invio ripetuto non rigira l'interruttore · *Test:* `tests/django/test_console.py::test_a_command_needs_a_reason_and_a_confirmation`, `test_the_command_page_says_what_continues_and_what_to_check_before_resuming`, `test_repeating_a_command_changes_nothing_and_adds_no_audit_row`
- **[WEB-44]** Ogni comando operativo è negato a un giocatore e a uno staff
senza il permesso specifico, si riflette sul sito con l'effetto previsto e
compare nell'audit.
*Stato:* implementato (A9): il permesso è controllato nella vista e di nuovo nel servizio, il rifiuto è nell'audit con esito `denied` · *Test:* `tests/django/test_console.py::test_a_player_cannot_run_a_command_and_the_refusal_is_audited`, `test_the_service_itself_refuses_without_the_permission`, `test_a_command_without_the_csrf_token_is_refused`
## 6 · Avvio in locale
@@ -252,4 +260,4 @@ FastAPI, che non è più nel compose.
- **[WEB-55]** **Segnalazioni.** Dal profilo (`/app/profilo/`) l'utente invia una segnalazione di un problema e vede lo stato delle proprie
(aperta, letta, risolta); lo staff le gestisce da `/admin/` ([WEB-32]) cambiandone lo stato, e ogni cambio è nell'audit. Il testo ha
una lunghezza massima e l'invio è limitato per utente ([SEC-55]). Un utente vede solo le proprie segnalazioni ([WEB-03]).
*Stato:* da implementare (A9: modello, sezione del profilo e gestione in `/admin/`).
*Stato:* implementato (A9): massimo 1000 caratteri, 10 invii all'ora per utente (un invio rifiutato dalla validazione non conta); il testo non è modificabile da `/admin/` · *Codice:* `apps/lottery/models.py:Report`, `apps/accounts/views.py:report_view`, `apps/lottery/admin.py:ReportAdmin` · *Test:* `tests/django/test_console.py::test_a_player_sends_a_report_and_sees_its_status`, `test_a_player_sees_only_their_own_reports`, `test_reports_are_limited_per_user`, `test_changing_a_report_status_in_the_admin_is_audited`