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:
1 parent
3d1e820564
commit
eab141f467
24 files changed
+928
-11
No files matched your search
@@ -0,0 +1,27 @@
|
||||
{% extends "web/base.html" %}
|
||||
{% block title %}{{ title }} · PLM Lottery{% endblock %}
|
||||
{% block content %}
|
||||
<h1>{{ title }}</h1>
|
||||
<section class="card narrow">
|
||||
<h2>Cosa continua</h2>
|
||||
<ul>{% for line in cmd.continues %}<li>{{ line }}</li>{% endfor %}</ul>
|
||||
{% if not enable %}
|
||||
<h2>Verifiche prima della ripresa</h2>
|
||||
<ul>{% for line in cmd.before_resume %}<li>{{ line }}</li>{% endfor %}</ul>
|
||||
<p class="hint">
|
||||
Stato ora: worker {% if worker_alive %}attivo{% else %}<strong>fermo</strong>{% endif %},
|
||||
operazioni in ritardo: {{ late_total }}.
|
||||
</p>
|
||||
{% endif %}
|
||||
<form method="post" novalidate>
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="enable" value="{% if enable %}1{% else %}0{% endif %}">
|
||||
{% if error %}<p class="message error" role="alert">{{ error }}</p>{% endif %}
|
||||
<label for="reason">Motivo (resta nell'audit)</label>
|
||||
<textarea id="reason" name="reason" rows="3" maxlength="500" required>{{ reason_text }}</textarea>
|
||||
<p><label><input type="checkbox" name="confirm" value="1"> Ho letto cosa comporta e confermo.</label></p>
|
||||
<button class="button" type="submit">{{ title }}</button>
|
||||
<a class="button secondary" href="{% url 'ops:dashboard' %}">Annulla</a>
|
||||
</form>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,56 @@
|
||||
{% extends "web/base.html" %}
|
||||
{% block title %}Console operativa · PLM Lottery{% endblock %}
|
||||
{% block content %}
|
||||
<h1>Console operativa</h1>
|
||||
|
||||
<section class="card" aria-labelledby="stato">
|
||||
<h2 id="stato">Stato</h2>
|
||||
<dl class="facts">
|
||||
<dt>Round in corso</dt>
|
||||
<dd>{% if round %}n. {{ round.pk }} · {{ round.get_status_display }}{% else %}nessuno{% endif %}</dd>
|
||||
<dt>Prossima scadenza</dt>
|
||||
<dd>{% if round and round.status == "open" %}{{ deadline|date:"H:i:s" }} UTC{% else %}—{% endif %}</dd>
|
||||
<dt>Worker</dt>
|
||||
<dd>
|
||||
{% if worker_alive %}attivo · ultimo battito {{ worker_seen_at|time:"H:i:s" }} UTC
|
||||
{% elif worker_seen_at %}<strong>fermo</strong> · ultimo battito {{ worker_seen_at|date:"j F H:i:s" }} UTC
|
||||
{% else %}<strong>mai avviato</strong>{% endif %}
|
||||
</dd>
|
||||
<dt>Catena</dt>
|
||||
<dd>{% if backend == "simulated" %}simulata (fase A): nessun nodo Electrum da controllare{% else %}Electrum: controllo non ancora disponibile{% endif %}</dd>
|
||||
<dt>Ultima riconciliazione</dt>
|
||||
<dd>non ancora disponibile (arriva con la fase B)</dd>
|
||||
<dt>Operazioni in ritardo</dt>
|
||||
<dd>
|
||||
{% if late_total %}
|
||||
<strong>{{ late_total }}</strong>:
|
||||
{{ late.pending_bets }} puntate in attesa, {{ late.pending_movements }} movimenti in attesa,
|
||||
{{ late.pending_transactions }} transazioni in attesa{% if late.overdue_rounds %}, il round oltre la scadenza{% endif %}
|
||||
{% else %}nessuna{% endif %}
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="card" aria-labelledby="comandi">
|
||||
<h2 id="comandi">Pause</h2>
|
||||
<ul class="plain">
|
||||
{% for item in commands %}
|
||||
<li>
|
||||
<strong>{{ item.command.title_on }}</strong> — {% if item.on %}<strong>attiva</strong>{% else %}non attiva{% endif %}
|
||||
{% if item.reason %}<br><span class="hint">Dal {{ item.reason.created_at|date:"j F H:i" }} UTC, {{ item.reason.actor_label }}: {{ item.reason.reason }}</span>{% endif %}
|
||||
<br>
|
||||
{% if item.allowed %}
|
||||
<a class="button small{% if item.on %} secondary{% endif %}" href="{% url 'ops:command' item.command.key %}">{{ item.title }}…</a>
|
||||
{% else %}
|
||||
<span class="hint">Non hai il permesso per questo comando.</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Altri strumenti</h2>
|
||||
<p><a href="/admin/">Amministrazione: utenti, segnalazioni, audit</a></p>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,9 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = "ops"
|
||||
urlpatterns = [
|
||||
path("ops/", views.dashboard, name="dashboard"),
|
||||
path("ops/<slug:key>/", views.command, name="command"),
|
||||
]
|
||||
@@ -0,0 +1,76 @@
|
||||
"""The operations console (WEB-30..33, WEB-40..44, roadmap A9). Every view and every action checks the
|
||||
specific permission; being logged in, or being staff, is not enough."""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.views import redirect_to_login
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.http import Http404
|
||||
from django.shortcuts import redirect, render
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
from apps.lottery import console
|
||||
from apps.lottery.models import LotteryConfig
|
||||
|
||||
|
||||
def _gate(request, allowed: bool):
|
||||
"""Anonymous visitors go to sign-in; anyone signed in without the permission gets 403."""
|
||||
if not request.user.is_authenticated:
|
||||
return redirect_to_login(request.get_full_path(), "/accedi/")
|
||||
if not allowed:
|
||||
raise PermissionDenied
|
||||
return None
|
||||
|
||||
|
||||
@never_cache
|
||||
@require_http_methods(["GET"])
|
||||
def dashboard(request):
|
||||
if (denied := _gate(request, console.can_view(request.user))) is not None:
|
||||
return denied
|
||||
state = console.console_state()
|
||||
commands = [
|
||||
{"command": c, "on": console.is_on(c, state["config"]), "title": console.title(c, state["config"]),
|
||||
"allowed": console.can_run(request.user, c), "reason": state["pause_reasons"][c.key]}
|
||||
for c in console.COMMANDS.values()
|
||||
]
|
||||
return render(request, "ops/dashboard.html", {**state, "commands": commands})
|
||||
|
||||
|
||||
@never_cache
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def command(request, key: str):
|
||||
cmd = console.COMMANDS.get(key)
|
||||
if cmd is None:
|
||||
raise Http404
|
||||
if request.user.is_authenticated and not (console.can_view(request.user) and console.can_run(request.user, cmd)):
|
||||
if request.method == "POST":
|
||||
try:
|
||||
console.run_command(request.user, cmd, True, "") # refuses, and records the refusal in the audit
|
||||
except PermissionDenied:
|
||||
pass
|
||||
raise PermissionDenied
|
||||
if (denied := _gate(request, True)) is not None:
|
||||
return denied
|
||||
config = LotteryConfig.get()
|
||||
enable = not console.is_on(cmd, config)
|
||||
state = console.console_state()
|
||||
context = {"cmd": cmd, "enable": enable, "title": console.title(cmd, config), **state, "reason_text": ""}
|
||||
if request.method == "POST":
|
||||
# The page was rendered for one direction; a stale form must not flip the switch back.
|
||||
wanted = request.POST.get("enable") == "1"
|
||||
reason = request.POST.get("reason", "")
|
||||
context["reason_text"] = reason
|
||||
if request.POST.get("confirm") != "1":
|
||||
context["error"] = "Conferma di aver letto cosa comporta."
|
||||
else:
|
||||
try:
|
||||
changed = console.run_command(request.user, cmd, wanted, reason)
|
||||
except ValidationError as error:
|
||||
context["error"] = error.messages[0]
|
||||
else:
|
||||
if changed:
|
||||
messages.success(request, f"Comando eseguito: {cmd.title_on if wanted else cmd.title_off}.")
|
||||
else:
|
||||
messages.info(request, "Il comando era già nello stato richiesto: nulla è cambiato.")
|
||||
return redirect("ops:dashboard")
|
||||
return render(request, "ops/command.html", context)
|
||||
Reference in new issue
Block a user