2026-11-16 15:03:22 +01:00
|
|
|
"""Admin for the lottery tables (WEB-32): closed rounds, transactions, movements and the audit are read-only;
|
|
|
|
|
reports are managed by changing their status, which is audited."""
|
|
|
|
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
|
from django.db import transaction
|
|
|
|
|
|
|
|
|
|
from . import audit
|
2026-11-16 16:09:36 +01:00
|
|
|
from .models import AuditEntry, ChainTransaction, LotteryConfig, Movement, Participation, Report, Round
|
2026-11-16 15:03:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReadOnlyAdmin(admin.ModelAdmin):
|
|
|
|
|
def has_add_permission(self, request):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def has_change_permission(self, request, obj=None):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Round)
|
|
|
|
|
class RoundAdmin(ReadOnlyAdmin):
|
|
|
|
|
list_display = ("id", "status", "opened_at", "closed_at", "pool_amount_sats")
|
|
|
|
|
list_filter = ("status",)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Participation)
|
|
|
|
|
class ParticipationAdmin(ReadOnlyAdmin):
|
|
|
|
|
list_display = ("id", "round", "user", "status", "bet_amount_sats")
|
|
|
|
|
list_filter = ("status",)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Movement)
|
|
|
|
|
class MovementAdmin(ReadOnlyAdmin):
|
|
|
|
|
list_display = ("id", "user", "kind", "status", "amount_sats", "created_at")
|
|
|
|
|
list_filter = ("kind", "status")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(ChainTransaction)
|
|
|
|
|
class ChainTransactionAdmin(ReadOnlyAdmin):
|
|
|
|
|
list_display = ("id", "kind", "status", "current_txid", "created_at")
|
|
|
|
|
list_filter = ("kind", "status")
|
|
|
|
|
exclude = ("raw_hex",)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(AuditEntry)
|
|
|
|
|
class AuditEntryAdmin(ReadOnlyAdmin):
|
|
|
|
|
list_display = ("created_at", "actor_label", "action", "outcome", "subject_type", "subject_id")
|
|
|
|
|
list_filter = ("action", "outcome")
|
|
|
|
|
search_fields = ("actor_label", "reason")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Report)
|
|
|
|
|
class ReportAdmin(admin.ModelAdmin):
|
|
|
|
|
list_display = ("id", "user", "status", "created_at")
|
|
|
|
|
list_filter = ("status",)
|
|
|
|
|
fields = ("user", "text", "created_at", "status", "status_changed_at")
|
|
|
|
|
readonly_fields = ("user", "text", "created_at", "status_changed_at")
|
|
|
|
|
|
|
|
|
|
def has_add_permission(self, request):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
|
|
|
if not (change and "status" in form.changed_data):
|
|
|
|
|
return
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
|
|
before = form.initial.get("status")
|
|
|
|
|
with transaction.atomic():
|
|
|
|
|
obj.status_changed_at = timezone.now()
|
|
|
|
|
obj.save(update_fields=["status", "status_changed_at"])
|
|
|
|
|
audit.record("report_status_changed", actor=request.user, subject_type="report", subject_id=obj.pk,
|
|
|
|
|
payload={"from": before, "to": obj.status})
|
2026-11-16 16:09:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(LotteryConfig)
|
|
|
|
|
class LotteryConfigAdmin(admin.ModelAdmin):
|
|
|
|
|
"""The operational parameters (DAT-77). The three pause switches are not here: they go through the console's
|
|
|
|
|
commands, which ask for a reason (WEB-43). A change is audited with what changed."""
|
|
|
|
|
|
|
|
|
|
fields = ("fee_address", "bet_amount_sats", "round_duration_seconds", "round_cooldown_seconds",
|
2026-11-16 16:29:08 +01:00
|
|
|
"draw_confirmations", "deposit_confirmations", "max_round_pool_sats", "fee_rate_sat_vb", "rbf_timeout_seconds")
|
2026-11-16 16:09:36 +01:00
|
|
|
|
|
|
|
|
def has_add_permission(self, request):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
|
|
|
changes = {name: [form.initial.get(name), getattr(obj, name)] for name in form.changed_data}
|
|
|
|
|
with transaction.atomic():
|
|
|
|
|
super().save_model(request, obj, form, change)
|
|
|
|
|
if changes:
|
|
|
|
|
audit.record("config_changed", actor=request.user, subject_type="config", subject_id=obj.pk,
|
|
|
|
|
payload={"changed": changes})
|