Trial runs itself: first enrolled phone opens a sample vote; split screen fits
This commit is contained in:
+11
-2
@@ -420,7 +420,9 @@ async def create_trial(request: Request):
|
||||
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)
|
||||
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)
|
||||
return JSONResponse({"id": pid, "screen_key": screen_key})
|
||||
|
||||
@@ -582,7 +584,14 @@ def _finish_enroll(pid, att_id, code=None):
|
||||
resp = JSONResponse({"status": "enrolled"})
|
||||
set_cookie(resp, voter_cookie(pid), cred, 7 * 24 * 3600)
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user