diff --git a/rotatyvote/app.py b/rotatyvote/app.py index a6b416b..697c5e3 100644 --- a/rotatyvote/app.py +++ b/rotatyvote/app.py @@ -856,7 +856,8 @@ async def ws_voter(ws: WebSocket): CSP = ("default-src 'self'; script-src 'self'; worker-src 'self' blob:; style-src 'self'; " "img-src 'self' data: blob:; media-src 'self' blob: mediastream:; connect-src 'self' ws: wss:; " - "frame-ancestors 'none'; base-uri 'none'; form-action 'self'; object-src 'none'") + # same origin only: the duplicated-screen page shows the admin page in a side panel + "frame-ancestors 'self'; base-uri 'none'; form-action 'self'; object-src 'none'") class SecurityHeaders: @@ -875,7 +876,7 @@ class SecurityHeaders: (b"content-security-policy", CSP.encode()), (b"referrer-policy", b"no-referrer"), (b"x-content-type-options", b"nosniff"), - (b"x-frame-options", b"DENY"), + (b"x-frame-options", b"SAMEORIGIN"), (b"permissions-policy", b"camera=(self), microphone=(), geolocation=()"), ] if not path.startswith("/static/vendor/"): @@ -911,6 +912,8 @@ routes = [ Route("/", page("index.html")), Route("/admin/{pid}", page("admin.html")), Route("/screen/{pid}", page("screen.html")), + # duplicated screen: the projector view with the admin in a drawer, opened with the admin key + Route("/present/{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)), diff --git a/static/admin.html b/static/admin.html index d09e91c..f82f726 100644 --- a/static/admin.html +++ b/static/admin.html @@ -116,6 +116,10 @@
Lien projecteurRévoque le précédent
+
+
Écran dupliquéProjection et gestion sur le même écran
+ Ouvrir +
RésultatsBulletins anonymes et décomptes
diff --git a/static/css/app.css b/static/css/app.css index 0753efb..c165c7a 100644 --- a/static/css/app.css +++ b/static/css/app.css @@ -184,3 +184,5 @@ details.advanced { margin-top: 14px; } details.advanced summary { font-size: .82rem; color: var(--ink-3); cursor: pointer; width: fit-content; padding: 4px 0; } details.advanced summary:hover { color: var(--ink-2); } details.advanced[open] summary { color: var(--ink-2); } +.mode-title { font-size: 1.05rem; margin: 22px 0 2px; } +.mode-title + .hint { margin: 0 0 8px; } diff --git a/static/css/screen.css b/static/css/screen.css index 4e923cf..6b61d8a 100644 --- a/static/css/screen.css +++ b/static/css/screen.css @@ -142,3 +142,16 @@ body.entry-q-on { --dock-qr: clamp(160px, min(46vh, 30vw), 520px); } .s-main > section, .entry, #focus.enter *, #voters.bump { animation: none !important; } .turnout .progress > div { transition: none; } } + +/* duplicated screen: the admin slides in over the projection, the room sees it while it's open */ +.ctl { + position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(480px, 94vw); display: grid; grid-template-rows: auto 1fr; + background: var(--bg); box-shadow: -12px 0 40px rgba(28, 32, 54, .18); translate: 105% 0; transition: translate .35s cubic-bezier(.2, .7, .2, 1); +} +.ctl.open { translate: 0 0; } +.ctl-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; font: 700 1rem var(--round); } +.ctl iframe { width: 100%; height: 100%; border: 0; background: var(--bg); } +/* the manage button stays reachable in full screen, faint until hovered */ +:fullscreen .s-tools .ctl-btn { display: inline-flex; opacity: .3; } +:fullscreen .s-tools .ctl-btn:hover, :fullscreen .s-tools .ctl-btn:focus-visible { opacity: 1; } +@media (prefers-reduced-motion: reduce) { .ctl { transition: none; } } diff --git a/static/index.html b/static/index.html index 5fed75f..b757cd8 100644 --- a/static/index.html +++ b/static/index.html @@ -75,6 +75,8 @@ diff --git a/static/js/admin.js b/static/js/admin.js index 127d405..3685ab0 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -321,3 +321,6 @@ liveSocket(`/ws/${pid}/admin`, { c.textContent = "Reconnexion…"; }, }); + +// duplicated screen: the projector view with this admin in a drawer, same admin key +$("#open-present").href = `/present/${pid}#${encodeURIComponent(key)}`; diff --git a/static/js/index.js b/static/js/index.js index 9a2142a..595e08e 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -28,6 +28,7 @@ $("#form").addEventListener("submit", async (e) => { $("#screen-link").value = screen; $("#go-admin").href = admin; $("#go-screen").href = screen; + $("#go-present").href = `${location.origin}/present/${res.id}#${res.admin_key}`; $("#create").hidden = true; $("#try-link").hidden = true; $("#done").hidden = false; diff --git a/static/js/screen.js b/static/js/screen.js index fc73de2..a2bd55f 100644 --- a/static/js/screen.js +++ b/static/js/screen.js @@ -2,7 +2,9 @@ import { $, h, pollId, takeKey, liveSocket, drawQR, resultsView, pct } from "./c import { render as drawRing, DISC } from "./ringcode.js"; const pid = pollId(); -const key = takeKey(`rv_screen_${pid}`); +// /present/: duplicated screen, the laptop shows what the projector shows. admin key, admin in a drawer +const present = location.pathname.startsWith("/present/"); +const key = takeKey(present ? `rv_present_${pid}` : `rv_screen_${pid}`); let st = null; let qr = null; // current code message, qr or ring let raf = 0; @@ -224,3 +226,23 @@ liveSocket(`/ws/${pid}/screen`, { if (s !== "online") { qr = null; const cv = $("#qr"); cv.getContext("2d").clearRect(0, 0, cv.width, cv.height); } }, }); + +if (present) { + const btn = h("button", { class: "small ctl-btn", type: "button", "aria-expanded": "false" }, "Gérer"); + const close = h("button", { class: "small", type: "button" }, "Fermer"); + const drawer = h("aside", { class: "ctl", "aria-label": "Gestion du scrutin" }, + h("div", { class: "ctl-head" }, h("b", {}, "Gestion"), close)); + document.body.append(drawer); + $(".s-tools").prepend(btn); + const toggle = (open) => { + // the admin page loads on first open only, and keeps its state when the drawer closes + if (open && !drawer.querySelector("iframe")) { + drawer.append(h("iframe", { src: `/admin/${pid}#${encodeURIComponent(key)}`, title: "Administration" })); + } + drawer.classList.toggle("open", open); + btn.setAttribute("aria-expanded", String(open)); + }; + btn.addEventListener("click", () => toggle(!drawer.classList.contains("open"))); + close.addEventListener("click", () => toggle(false)); + document.addEventListener("keydown", (e) => { if (e.key === "Escape") toggle(false); }); +} diff --git a/tests/test_e2e.py b/tests/test_e2e.py index dbad40b..1c82dc6 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -734,3 +734,20 @@ def test_hand_added_votes(server): await a.aclose() asyncio.run(run()) + + +def test_duplicated_screen_page(server): + p = create(server) + admin(server, p, "PATCH", "", json={"enrollment_open": True}) + r = httpx.get(f"{server['base']}/present/{p['id']}", verify=server["verify"]) + assert r.status_code == 200 + # the admin page may only be framed by the site itself (duplicated screen drawer) + assert r.headers["x-frame-options"] == "SAMEORIGIN" and "frame-ancestors 'self'" in r.headers["content-security-policy"] + assert httpx.get(f"{server['base']}/present/nopenope", verify=server["verify"]).status_code == 404 + + async def run(): + # the duplicated screen talks to the projector socket with the admin key + async with projector(server, p, key=p["admin_key"]) as next_token: + assert (await next_token()) is not None + + asyncio.run(run())