Trial runs itself: first enrolled phone opens a sample vote; split screen fits

This commit is contained in:
2026-08-16 22:38:43 +01:00
parent b0cec39d6e
commit b4a110abe3
4 changed files with 25 additions and 4 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ location / {
4. Lancer les questions préparées ou en créer en direct. Les téléphones les reçoivent instantanément. 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. 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. 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. Dès la première inscription, une question d'essai s'ouvre pour essayer aussi le vote et ses 3 scans de confirmation. 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 ## Code circulaire
+11 -2
View File
@@ -420,7 +420,9 @@ async def create_trial(request: Request):
db.purge_trials(config.TRIAL_TTL_MS) db.purge_trials(config.TRIAL_TTL_MS)
if db.trial_count() >= config.MAX_TRIALS: if db.trial_count() >= config.MAX_TRIALS:
return err("too_many_trials", 429) return err("too_many_trials", 429)
pid, _, screen_key = db.create_poll("Essai", 500, 5, False, None, 200, 0, "ring", trial=True) pid, _, screen_key = db.create_poll("Essai", 500, 5, False, None, 200, config.DEFAULT_VOTE_SCANS, "ring",
trial=True)
db.add_question(pid, "Le vote d'essai fonctionne ?", "single", ["Oui", "Non"], 1, False)
db.update_poll(pid, enrollment_open=1) db.update_poll(pid, enrollment_open=1)
return JSONResponse({"id": pid, "screen_key": screen_key}) return JSONResponse({"id": pid, "screen_key": screen_key})
@@ -582,7 +584,14 @@ def _finish_enroll(pid, att_id, code=None):
resp = JSONResponse({"status": "enrolled"}) resp = JSONResponse({"status": "enrolled"})
set_cookie(resp, voter_cookie(pid), cred, 7 * 24 * 3600) set_cookie(resp, voter_cookie(pid), cred, 7 * 24 * 3600)
resp.delete_cookie(attempt_cookie(pid), path="/") resp.delete_cookie(attempt_cookie(pid), path="/")
hub.refresh(pid) # a trial has no admin: the first enrolled phone opens the sample question so the vote can be tried too
p = db.poll(pid)
if p["trial"] and not p["focus_qid"]:
q = next((q for q in db.questions(pid) if q["state"] == "draft"), None)
if q:
db.set_question(q["id"], state="open")
db.update_poll(pid, focus_qid=q["id"])
hub.refresh(pid, voters=True)
return resp, None return resp, None
+6 -1
View File
@@ -38,7 +38,12 @@ body.screen {
/* enrollment + a question at the same time: qr shrinks to the side */ /* enrollment + a question at the same time: qr shrinks to the side */
.s-main.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 5vw; } .s-main.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 5vw; }
.s-main.split .s-enroll { grid-template-columns: 1fr; justify-items: center; gap: 3vh; } .s-main.split .s-enroll { grid-template-columns: 1fr; justify-items: center; gap: 3vh; }
.s-main.split .qr-wrap { max-height: 52vh; } .s-main.split .s-enroll { grid-template-rows: minmax(0, 1fr) auto; gap: 2vh; height: 100%; }
.s-main.split .qr-wrap { height: 100%; width: auto; max-width: 100%; max-height: none; }
.s-main.split .entry { margin-top: 1.5vh; }
/* the question owns the screen, the ring keeps the room the step list would take */
.s-main.split #qr-steps { display: none; }
.s-main.split .entry canvas { width: clamp(90px, min(10vw, 15vh), 220px); }
.s-main.split .s-steps h2 { font-size: clamp(1.4rem, 2.4vw, 2.6rem); } .s-main.split .s-steps h2 { font-size: clamp(1.4rem, 2.4vw, 2.6rem); }
.s-main.split .s-steps li { font-size: clamp(1rem, 1.5vw, 1.6rem); } .s-main.split .s-steps li { font-size: clamp(1rem, 1.5vw, 1.6rem); }
+7
View File
@@ -678,6 +678,13 @@ def test_trial_enrolls_then_expires(server):
async def run(): async def run():
async with projector(server, p) as next_token: async with projector(server, p) as next_token:
c = await enroll(server, p, next_token) c = await enroll(server, p, next_token)
# nobody can push a question on a trial, the first phone in opens the sample one
me = (await c.get(f"/api/v/{p['id']}/me")).json()
q = next(q for q in me["questions"] if q["state"] == "open")
assert me["vote_scans"] == 3
fresh = [await next_token() for _ in range(3)]
r = await c.post(f"/api/v/{p['id']}/vote", json={"question_id": q["id"], "choices": [0], "presence": fresh})
assert r.status_code == 200, r.text
await c.aclose() await c.aclose()
asyncio.run(run()) asyncio.run(run())