Tester l'écran
+Ouvrez cette page sur l'ordinateur relié au projecteur, puis visez l'écran avec votre téléphone depuis le fond de la salle.
+ +Scrutin jetable, effacé au bout de 2 h.
+diff --git a/README.md b/README.md index aa25820..08695eb 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ location / { | `DB_PATH` | `rotatyvote.db` | base SQLite | | `CREATE_PASSWORD` | vide | mot de passe pour créer un scrutin | | `TOKEN_GRACE_MS` | `2500` | tolérance réseau sur un code | +| `MAX_TRIALS` | `50` | essais `/essai` ouverts en même temps | ## Déroulé @@ -66,6 +67,8 @@ location / { 4. Lancer les questions préparées ou en créer en direct. Les téléphones les reçoivent instantanément. 5. Clore, publier les résultats à l'écran, exporter en JSON. +Avant l'AG, `/essai` lance un scrutin jetable sur l'écran à tester : code circulaire à 0,5 s, 5 scans, inscriptions ouvertes. On vise l'écran avec son téléphone depuis le fond de la salle et le compteur d'inscriptions confirme la lecture. Personne ne reçoit le lien d'administration, et l'essai est effacé au bout de 2 h, même sans mot de passe de création. + ## Code circulaire Par défaut, le projecteur affiche un code circulaire : un disque sombre avec le logo au centre, entouré de 4 anneaux de segments qui tournent. Le QR classique reste disponible par scrutin (Inscriptions > Code projeté). diff --git a/rotatyvote/app.py b/rotatyvote/app.py index a84ed67..c37da26 100644 --- a/rotatyvote/app.py +++ b/rotatyvote/app.py @@ -415,6 +415,16 @@ async def create_poll(request: Request): return JSONResponse({"id": pid, "admin_key": admin_key, "screen_key": screen_key}) +async def create_trial(request: Request): + # no password even when creation is locked: a trial only enrolls, nobody gets its admin key + db.purge_trials(config.TRIAL_TTL_MS) + if db.trial_count() >= config.MAX_TRIALS: + return err("too_many_trials", 429) + pid, _, screen_key = db.create_poll("Essai", 500, 5, False, None, 200, 0, "ring", trial=True) + db.update_poll(pid, enrollment_open=1) + return JSONResponse({"id": pid, "screen_key": screen_key}) + + async def admin_get(request: Request): pid = request.path_params["pid"] require_admin(request, pid) @@ -845,10 +855,12 @@ routes = [ Route("/", page("index.html")), Route("/admin/{pid}", page("admin.html")), Route("/screen/{pid}", page("screen.html")), + Route("/essai", page("essai.html")), Route("/v/{pid}", page("vote.html")), Route("/V/{pid}", lambda r: RedirectResponse(f"/v/{r.path_params['pid'].lower()}", status_code=301)), Route("/api/config", public_config, methods=["GET"]), Route("/api/polls", create_poll, methods=["POST"]), + Route("/api/trial", create_trial, methods=["POST"]), Route("/api/polls/{pid}", admin_get, methods=["GET"]), Route("/api/polls/{pid}", admin_patch, methods=["PATCH"]), Route("/api/polls/{pid}/screen-key", admin_rotate_screen_key, methods=["POST"]), diff --git a/rotatyvote/config.py b/rotatyvote/config.py index 3d5aa67..6dc9a32 100644 --- a/rotatyvote/config.py +++ b/rotatyvote/config.py @@ -29,6 +29,10 @@ HEARTBEAT_S = float(os.environ.get("HEARTBEAT_S", "25")) DEFAULT_VOTE_SCANS = 3 MAX_VOTE_SCANS = 5 +# throwaway polls from /essai: deleted after this, and only so many alive at once +TRIAL_TTL_MS = 2 * 3600 * 1000 +MAX_TRIALS = int(os.environ.get("MAX_TRIALS", "50")) + MIN_INTERVAL_MS = 300 MAX_INTERVAL_MS = 5000 MIN_SCANS = 2 diff --git a/rotatyvote/db.py b/rotatyvote/db.py index 6853e3d..698c32c 100644 --- a/rotatyvote/db.py +++ b/rotatyvote/db.py @@ -87,6 +87,7 @@ class DB: ("voters", "via_code", "INTEGER NOT NULL DEFAULT 0"), ("access_codes", "rescue", "INTEGER NOT NULL DEFAULT 0"), ("polls", "code_style", "TEXT NOT NULL DEFAULT 'qr'"), + ("polls", "trial", "INTEGER NOT NULL DEFAULT 0"), ): cols = {r[1] for r in self.c.execute(f"PRAGMA table_info({table})")} if col not in cols: @@ -110,19 +111,34 @@ class DB: def create_poll(self, title, interval_ms, scans_required, require_code, expected, max_voters, vote_scans=0, - code_style="qr"): + code_style="qr", trial=False): pid = new_id() while self.one("SELECT 1 FROM polls WHERE id=?", pid): pid = new_id() admin_key, screen_key = new_key(), new_key() self.c.execute( "INSERT INTO polls(id,title,admin_hash,screen_hash,secret,interval_ms,scans_required," - "require_code,expected,max_voters,vote_scans,code_style,created_at) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)", + "require_code,expected,max_voters,vote_scans,code_style,trial,created_at) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (pid, title, sha(admin_key), sha(screen_key), secrets.token_bytes(32), interval_ms, - scans_required, int(require_code), expected, max_voters, vote_scans, code_style, now_ms()), + scans_required, int(require_code), expected, max_voters, vote_scans, code_style, int(trial), now_ms()), ) return pid, admin_key, screen_key + def purge_trials(self, max_age_ms): + old = [r["id"] for r in self.all("SELECT id FROM polls WHERE trial=1 AND created_at", now_ms() - max_age_ms)] + with self.tx() as c: + for pid in old: + qids = "SELECT id FROM questions WHERE poll_id=?" + c.execute(f"DELETE FROM ballots WHERE question_id IN ({qids})", (pid,)) + c.execute(f"DELETE FROM participation WHERE question_id IN ({qids})", (pid,)) + for table, col in (("questions", "poll_id"), ("voters", "poll_id"), ("access_codes", "poll_id"), + ("polls", "id")): + c.execute(f"DELETE FROM {table} WHERE {col}=?", (pid,)) + return old + + def trial_count(self): + return self.one("SELECT COUNT(*) n FROM polls WHERE trial=1")["n"] + def poll(self, pid): return self.one("SELECT * FROM polls WHERE id=?", pid) diff --git a/static/css/app.css b/static/css/app.css index 8accae0..a00feb7 100644 --- a/static/css/app.css +++ b/static/css/app.css @@ -154,3 +154,4 @@ button:disabled { opacity: .35; cursor: not-allowed; transform: none; } .card { padding: 0; } .code-cell { break-inside: avoid; } } +.center { text-align: center; } diff --git a/static/essai.html b/static/essai.html new file mode 100644 index 0000000..37852d4 --- /dev/null +++ b/static/essai.html @@ -0,0 +1,23 @@ + + +
+ + +Ouvrez cette page sur l'ordinateur relié au projecteur, puis visez l'écran avec votre téléphone depuis le fond de la salle.
+ +Scrutin jetable, effacé au bout de 2 h.
+Tester l'écran et les téléphones avant l'AG