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

+33 -3
View File
@@ -11,10 +11,11 @@ from django.views.decorators.cache import never_cache
from django.views.decorators.http import require_http_methods, require_POST
from apps.lottery import audit
from apps.lottery.models import Report
from . import throttle
from .client_ip import client_ip
from .forms import LoginForm, PasswordChangeForm, RegisterForm
from .forms import LoginForm, PasswordChangeForm, RegisterForm, ReportForm
from .models import User
BACKEND = "apps.accounts.backends.CaseInsensitiveBackend"
@@ -107,6 +108,35 @@ def logout_view(request):
return redirect(settings.LOGOUT_REDIRECT_URL)
def _profile_context(request, *, form=None, report_form=None) -> dict:
"""Only the signed-in user's own data and reports (WEB-03)."""
return {
"form": form or PasswordChangeForm(request.user),
"report_form": report_form or ReportForm(),
"reports": Report.objects.filter(user=request.user).order_by("-created_at", "-id"),
}
@never_cache
@login_required
@require_POST
def report_view(request):
"""WEB-55: send a problem report. A rejected form does not use the quota; a sent one does."""
key = str(request.user.pk)
wait = throttle.retry_after(throttle.REPORT, key)
form = ReportForm(request.POST)
if wait > 0:
return _too_many(request, "accounts/profile.html", _profile_context(request, report_form=form), wait)
if not form.is_valid():
return render(request, "accounts/profile.html", _profile_context(request, report_form=form), status=400)
with transaction.atomic():
report = Report.objects.create(user=request.user, text=form.cleaned_data["text"])
audit.record("report_submitted", actor=request.user, subject_type="report", subject_id=report.pk)
throttle.record(throttle.REPORT, key)
messages.success(request, "Segnalazione inviata. Ne vedrai lo stato qui sotto.")
return redirect("accounts:profile")
@never_cache
@login_required
@require_http_methods(["GET", "POST"])
@@ -116,7 +146,7 @@ def profile_view(request):
key = str(request.user.pk)
wait = throttle.retry_after(throttle.CHANGE_PASSWORD, key)
if wait > 0:
return _too_many(request, "accounts/profile.html", {"form": form}, wait)
return _too_many(request, "accounts/profile.html", _profile_context(request, form=form), wait)
if form.is_valid():
if not request.user.check_password(form.cleaned_data["current_password"]):
# SEC-54: a stolen session must not be able to guess the password and lock the owner out.
@@ -133,4 +163,4 @@ def profile_view(request):
update_session_auth_hash(request, request.user)
messages.success(request, "Password aggiornata. Le altre sessioni sono state chiuse.")
return redirect("accounts:profile")
return render(request, "accounts/profile.html", {"form": form})
return render(request, "accounts/profile.html", _profile_context(request, form=form))