13 Commits
Author SHA1 Message Date
gnilebein 19320f01c4 Merge pull request 'Document Docker image as test-only' (#72) from docs/docker-test-only into main
CI / Deploy / PHP 8.4 (push) Successful in 1m8s
CI / Deploy / PHP 8.5 (push) Successful in 1m9s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 5s
Release / test (push) Successful in 57s
Release / package (push) Successful in 37s
Release / image (push) Successful in 1m37s
Reviewed-on: #72
2026-11-12 23:04:27 +01:00
gnilebeinandClaude Sonnet 5.5 996173edeb Document Docker image as test-only
CI / Deploy / PHP 8.5 (push) Successful in 1m10s
CI / Deploy / PHP 8.4 (push) Successful in 1m11s
CI / Deploy / test (push) Successful in 3s
CI / Deploy / deploy (push) Skipped
The image uses the built-in PHP server and SQLite, so it is not meant for
production. Say so in README, docker-compose.yml and AGENTS.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 23:03:14 +01:00
gnilebein 1d87281855 Merge pull request 'Stop FormHelper from emitting inline validity handlers' (#71) from fix/csp-inline-validity-handlers into main
CI / Deploy / PHP 8.5 (push) Successful in 1m3s
CI / Deploy / PHP 8.4 (push) Successful in 1m4s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 6s
Reviewed-on: #71
2026-11-12 22:58:26 +01:00
gnilebeinandClaude Sonnet 5.5 220227fa86 Stop FormHelper from emitting inline validity handlers
CI / Deploy / PHP 8.5 (push) Successful in 1m7s
CI / Deploy / PHP 8.4 (push) Successful in 1m7s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped
Required fields got generated oninvalid/oninput attributes, which the CSP
blocks and logs on every page and when parsing dashboard fragments.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 22:54:08 +01:00
gnilebein a0f3f9885b Merge pull request 'Fix dashboard buttons posting to the wrong URL' (#70) from fix/dashboard-action-field into main
CI / Deploy / PHP 8.5 (push) Successful in 1m6s
CI / Deploy / PHP 8.4 (push) Successful in 1m7s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 6s
Reviewed-on: #70
2026-11-12 22:44:08 +01:00
gnilebeinandClaude Sonnet 5.5 77d0bfb547 Fix dashboard buttons posting to the wrong URL
CI / Deploy / PHP 8.4 (push) Successful in 1m4s
CI / Deploy / PHP 8.5 (push) Successful in 1m5s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped
Forms with a field named "action" (play, pause) shadow the form.action
property, so the fragment request went to /admin/[object HTMLInputElement].
Read the attribute instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 22:42:03 +01:00
gnilebein ce2627d03a Merge pull request 'Feature/qa prepared questions' (#69) from feature/qa-prepared-questions into main
CI / Deploy / PHP 8.5 (push) Successful in 1m5s
CI / Deploy / PHP 8.4 (push) Successful in 1m5s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 7s
Reviewed-on: #69
2026-11-12 22:37:00 +01:00
gnilebeinandClaude Sonnet 5.5 34d7e20567 Show two answer rows by default for quiz and order slides
CI / Deploy / PHP 8.4 (push) Successful in 1m0s
CI / Deploy / PHP 8.5 (push) Successful in 1m5s
CI / Deploy / test (push) Successful in 2s
CI / Deploy / deploy (push) Skipped
Only two entries are required, so the form no longer offers four empty rows
up front; further rows come via the add button.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 22:34:21 +01:00
gnilebeinandClaude Sonnet 5.5 4b5f9d92a1 Add prepared questions to Q&A slides
The slide form takes questions entered beforehand (e.g. received by mail),
one per line, while collecting. They are stored as regular questions with a
reserved participant hash, synced idempotently, and not counted as participants.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 22:34:12 +01:00
gnilebeinandClaude Sonnet 5.5 76d8bb3170 Require PHP 8.4 in README
PHP 8.3 is no longer listed as supported.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 22:33:49 +01:00
gnilebein 4c33d9fa15 Merge pull request 'Ci/php matrix' (#68) from ci/php-matrix into main
CI / Deploy / PHP 8.4 (push) Successful in 1m4s
CI / Deploy / PHP 8.5 (push) Successful in 1m4s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 6s
Reviewed-on: #68
2026-11-12 10:56:06 +01:00
gnilebeinandClaude Sonnet 5.5 b4d7a48001 Test against PHP 8.4 and 8.5 and require PHP 8.4
CI / Deploy / PHP 8.5 (push) Successful in 1m5s
CI / Deploy / PHP 8.4 (push) Successful in 1m5s
CI / Deploy / test (push) Successful in 0s
CI / Deploy / deploy (push) Skipped
The lock file pins PHPUnit 13 and Symfony 8, which need PHP 8.4. PHP 8.3
is in its last support year, so drop it from the matrix instead of
downgrading the dependencies.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 10:53:48 +01:00
gnilebeinandClaude Sonnet 5.5 5a3880c6e9 Run CI tests against PHP 8.3, 8.4 and 8.5
CI / Deploy / PHP 8.3 (push) Failing after 49s
CI / Deploy / PHP 8.4 (push) Successful in 1m11s
CI / Deploy / PHP 8.5 (push) Successful in 1m13s
CI / Deploy / test (push) Failing after 1s
CI / Deploy / deploy (push) Skipped
Move the test steps into a matrix job and keep a aggregating `test` job so the
branch protection check name stays stable.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 10:46:40 +01:00
15 changed files with 294 additions and 18 deletions

No files matched your search

+21 -2
View File
@@ -32,15 +32,21 @@ on:
branches: ['**'] branches: ['**']
jobs: jobs:
test: # Matrix over the supported PHP versions.
phpunit:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.4', '8.5']
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: '8.5' php-version: ${{ matrix.php }}
extensions: mbstring, intl, pdo_sqlite, sqlite3 extensions: mbstring, intl, pdo_sqlite, sqlite3
coverage: none coverage: none
@@ -53,6 +59,19 @@ jobs:
- name: Coding standard - name: Coding standard
run: vendor/bin/phpcs --warning-severity=0 run: vendor/bin/phpcs --warning-severity=0
# Stable check name required by the branch protection of main: green only if all PHP versions are green.
test:
needs: phpunit
if: always()
runs-on: ubuntu-latest
steps:
- name: All PHP versions passed
run: |
if [ "${{ needs.phpunit.result }}" != "success" ]; then
echo "Matrix result: ${{ needs.phpunit.result }}" >&2
exit 1
fi
deploy: deploy:
needs: test needs: test
# Deactivated until the repository variable DEPLOY_ENABLED is "true". # Deactivated until the repository variable DEPLOY_ENABLED is "true".
+11 -2
View File
@@ -174,6 +174,12 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
(→/←, Klicker) zuerst durch die Fragen, erst danach durch die Folien. Fokuswechsel per `updateAll` ohne `modified`, (→/←, Klicker) zuerst durch die Fragen, erst danach durch die Folien. Fokuswechsel per `updateAll` ohne `modified`,
damit Teilnehmerseiten nicht neu laden. Teilnehmende bekommen nie `results`, sondern `qa` aus `PollStateService::qaState()`. damit Teilnehmerseiten nicht neu laden. Teilnehmende bekommen nie `results`, sondern `qa` aus `PollStateService::qaState()`.
Zurücksetzen startet wieder bei `collect`. Zurücksetzen startet wieder bei `collect`.
**Vorab eingereichte Fragen** (z. B. per Mail): Textarea `prepared_text` im Folienformular (eine Frage pro Zeile, höchstens
`QaService::MAX_PREPARED`), nur in `collect` sichtbar/änderbar. `QaService::syncPrepared()` gleicht sie idempotent ab (gleiche Texte
behalten ihre id, entfernte verschwinden samt Upvotes, von Teilnehmenden schon gestellte werden nicht doppelt angelegt). Gespeichert
als normale Fragen mit `participant_hash = VoteService::PREPARED_HASH` (kein gültiger HMAC → niemand kann sie bearbeiten/löschen,
jeder darf sie unterstützen); sie zählen nicht als Teilnehmende. Zurücksetzen löscht sie wie alle Antworten, Duplizieren kopiert sie nicht.
Tests: `QaPreparedTest.php`.
Eigene Fragen bearbeiten/löschen (`vote=edit|delete` + `question_id`, `VoteService::editQuestion()`) nur in `collect`: Eigene Fragen bearbeiten/löschen (`vote=edit|delete` + `question_id`, `VoteService::editQuestion()`) nur in `collect`:
danach könnten Upvotes bzw. die Besprechung an einem anderen Text hängen. Bearbeiten prüft Dubletten ohne die eigene Frage, danach könnten Upvotes bzw. die Besprechung an einem anderen Text hängen. Bearbeiten prüft Dubletten ohne die eigene Frage,
Löschen entfernt auch übrig gebliebene Upvotes (Presenter von `vote` zurück nach `collect`). Im JS hält `qaEditing` das Löschen entfernt auch übrig gebliebene Upvotes (Presenter von `vote` zurück nach `collect`). Im JS hält `qaEditing` das
@@ -333,7 +339,9 @@ Kein WebSocket: Presenter (`/admin/{token}/state`) und Teilnehmende (`/p/{code}/
Deploy erfolgt über Git (Remote: Gitea) mit `.gitea/workflows/ci.yml`: Deploy erfolgt über Git (Remote: Gitea) mit `.gitea/workflows/ci.yml`:
- Job `test` (PHPUnit + phpcs) läuft bei jedem Push auf jeden Branch. `main` ist per Branch-Schutz - Job `phpunit` (PHPUnit + phpcs) läuft bei jedem Push auf jeden Branch, als Matrix gegen PHP 8.4 und 8.5.
Der Sammel-Job `test` ist nur grün, wenn alle Matrix-Läufe grün sind, und bleibt der Check, den der Branch-Schutz
verlangt (so muss dort bei neuen PHP-Versionen nichts angepasst werden). `main` ist per Branch-Schutz
in Gitea gesperrt: kein direkter Push, Merge nur per PR und nur mit grünem Status-Check des Jobs `test`. in Gitea gesperrt: kein direkter Push, Merge nur per PR und nur mit grünem Status-Check des Jobs `test`.
- Job `deploy` läuft nur bei Push auf `main`, nur bei grünen Tests und **nur wenn die Repo-Variable - Job `deploy` läuft nur bei Push auf `main`, nur bei grünen Tests und **nur wenn die Repo-Variable
`DEPLOY_ENABLED=true` gesetzt ist** (standardmäßig deaktiviert). Er verbindet sich per SSH `DEPLOY_ENABLED=true` gesetzt ist** (standardmäßig deaktiviert). Er verbindet sich per SSH
@@ -344,7 +352,8 @@ Deploy erfolgt über Git (Remote: Gitea) mit `.gitea/workflows/ci.yml`:
- Benötigte Variablen/Secrets sind im Kopf der Workflow-Datei dokumentiert. Zugangsdaten nur als - Benötigte Variablen/Secrets sind im Kopf der Workflow-Datei dokumentiert. Zugangsdaten nur als
Gitea-Secret, nie ins Repo. Gitea-Secret, nie ins Repo.
**Container (Docker):** `Dockerfile` (`php:8.5-cli-alpine`, Multi-Stage mit Composer) startet über **Container (Docker) – nur für Testzwecke, nicht für den Produktivbetrieb geeignet** (eingebauter PHP-Server, SQLite; das steht
auch in der README und darf dort nicht als „empfohlen“ oder produktionstauglich erscheinen): `Dockerfile` (`php:8.5-cli-alpine`, Multi-Stage mit Composer) startet über
`docker/entrypoint.sh` den eingebauten Server (`bin/cake server -H 0.0.0.0 -p 8765`, `PHP_CLI_SERVER_WORKERS=8`, `docker/entrypoint.sh` den eingebauten Server (`bin/cake server -H 0.0.0.0 -p 8765`, `PHP_CLI_SERVER_WORKERS=8`,
sonst bedient er nur einen Request gleichzeitig). Code in `/app`, SQLite in Volume `/data` sonst bedient er nur einen Request gleichzeitig). Code in `/app`, SQLite in Volume `/data`
(`DATABASE_URL=sqlite:////data/plenario.sqlite`), Konfiguration nur per Umgebungsvariablen (`config/.env.example`). (`DATABASE_URL=sqlite:////data/plenario.sqlite`), Konfiguration nur per Umgebungsvariablen (`config/.env.example`).
+7 -3
View File
@@ -15,7 +15,7 @@ Der Name ist ein Wortspiel aus zwei Teilen:
Dazu passt auch der Gedanke dahinter: Ergebnisse gehören auf die Bühne und nicht auf die Geräte der Teilnehmenden. Dazu passt auch der Gedanke dahinter: Ergebnisse gehören auf die Bühne und nicht auf die Geräte der Teilnehmenden.
Basiert auf **CakePHP 5.4** (PHP 8.3 oder neuer, das automatische Deployment verlangt 8.4), Basiert auf **CakePHP 5.4** (PHP 8.4 oder neuer),
läuft lokal mit **SQLite**, ohne Build-Schritt fürs Frontend. läuft lokal mit **SQLite**, ohne Build-Schritt fürs Frontend.
## Inhalt ## Inhalt
@@ -76,7 +76,7 @@ Wichtige Tasten im Präsentationsmodus: `←` / `→` Folie wechseln, `P` Pause,
## Lokal starten (Entwicklung) ## Lokal starten (Entwicklung)
Voraussetzungen: PHP 8.3+ mit den Erweiterungen `intl`, `mbstring`, `openssl`, `pdo_sqlite`, `curl` Voraussetzungen: PHP 8.4+ mit den Erweiterungen `intl`, `mbstring`, `openssl`, `pdo_sqlite`, `curl`
sowie [Composer](https://getcomposer.org/). sowie [Composer](https://getcomposer.org/).
```bash ```bash
@@ -136,6 +136,10 @@ openssl rand -hex 32
## Deployment mit Docker ## Deployment mit Docker
> **Nur für Testzwecke.** Das Docker-Image ist zum Ausprobieren und für Tests gedacht und **nicht für den
> Produktionsbetrieb geeignet**: Es nutzt den eingebauten PHP-Server (kein Webserver wie Apache oder nginx mit PHP-FPM)
> und SQLite in einem Volume. Für den echten Betrieb siehe [Deployment ohne Docker](#deployment-ohne-docker).
Das [Dockerfile](Dockerfile) baut ein schlankes Image (`php:8.5-cli-alpine`, Multi-Stage mit Composer). Das [Dockerfile](Dockerfile) baut ein schlankes Image (`php:8.5-cli-alpine`, Multi-Stage mit Composer).
Der eingebaute PHP-Server läuft mit 8 Workern auf Port **8765**, die SQLite-Datenbank liegt im Volume `/data`. Der eingebaute PHP-Server läuft mit 8 Workern auf Port **8765**, die SQLite-Datenbank liegt im Volume `/data`.
Beim Start laufen die Migrationen automatisch (idempotent, mehrfaches Starten ist unproblematisch). Beim Start laufen die Migrationen automatisch (idempotent, mehrfaches Starten ist unproblematisch).
@@ -158,7 +162,7 @@ docker run -d --name plenario -p 8765:8765 -v plenario-data:/data \
gitea.gnilebein.de/gnilebein/plenario:latest gitea.gnilebein.de/gnilebein/plenario:latest
``` ```
### Empfohlen: Docker Compose ### Docker Compose
1. Eine `.env` neben der [docker-compose.yml](docker-compose.yml) anlegen (Vorlage: [config/.env.example](config/.env.example)): 1. Eine `.env` neben der [docker-compose.yml](docker-compose.yml) anlegen (Vorlage: [config/.env.example](config/.env.example)):
+1 -1
View File
@@ -5,7 +5,7 @@
"type": "project", "type": "project",
"homepage": "https://cakephp.org", "homepage": "https://cakephp.org",
"require": { "require": {
"php": ">=8.2", "php": ">=8.4",
"cakephp/cakephp": "5.4.*", "cakephp/cakephp": "5.4.*",
"cakephp/migrations": "^5.0", "cakephp/migrations": "^5.0",
"cakephp/plugin-installer": "^2.0", "cakephp/plugin-installer": "^2.0",
Generated
+2 -2
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "ddccb2d95917b222589d74cc89a09235", "content-hash": "d1039a47e3b46af459f914d1ea67c437",
"packages": [ "packages": [
{ {
"name": "cakephp/cakephp", "name": "cakephp/cakephp",
@@ -6893,7 +6893,7 @@
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": ">=8.2" "php": ">=8.4"
}, },
"platform-dev": {}, "platform-dev": {},
"plugin-api-version": "2.11.0" "plugin-api-version": "2.11.0"
+1
View File
@@ -1,3 +1,4 @@
# FOR TESTING ONLY - not suitable for production (built-in PHP server, SQLite).
# Example: docker compose up -d # Example: docker compose up -d
# Put it behind a TLS reverse proxy that sets X-Forwarded-Proto; APP_FULL_BASE_URL = public URL. # Put it behind a TLS reverse proxy that sets X-Forwarded-Proto; APP_FULL_BASE_URL = public URL.
services: services:
+11 -2
View File
@@ -48,11 +48,13 @@ class SlidesController extends AdminAppController
$optionsText = $type === Slide::TYPE_CHOICE ? "\n" : ''; $optionsText = $type === Slide::TYPE_CHOICE ? "\n" : '';
$quizOptions = []; $quizOptions = [];
$orderOptions = []; $orderOptions = [];
$preparedText = '';
if ($this->request->is('post')) { if ($this->request->is('post')) {
$optionsText = (string)$this->request->getData('options_text', ''); $optionsText = (string)$this->request->getData('options_text', '');
$quizOptions = $this->postedQuizOptions(); $quizOptions = $this->postedQuizOptions();
$orderOptions = $this->postedOrderOptions(); $orderOptions = $this->postedOrderOptions();
$preparedText = (string)$this->request->getData('prepared_text', '');
if ($this->saveSlide($slide, $optionsText)) { if ($this->saveSlide($slide, $optionsText)) {
$this->Flash->success(__('Folie angelegt.')); $this->Flash->success(__('Folie angelegt.'));
@@ -60,7 +62,7 @@ class SlidesController extends AdminAppController
} }
} }
$this->set(compact('slide', 'optionsText', 'quizOptions', 'orderOptions')); $this->set(compact('slide', 'optionsText', 'quizOptions', 'orderOptions', 'preparedText'));
$this->render('form'); $this->render('form');
return null; return null;
@@ -76,11 +78,13 @@ class SlidesController extends AdminAppController
$optionsText = implode("\n", array_map(fn($o) => $o->label, $slide->slide_options ?? [])); $optionsText = implode("\n", array_map(fn($o) => $o->label, $slide->slide_options ?? []));
$quizOptions = array_map(fn($o) => ['label' => $o->label, 'correct' => $o->is_correct], $slide->slide_options ?? []); $quizOptions = array_map(fn($o) => ['label' => $o->label, 'correct' => $o->is_correct], $slide->slide_options ?? []);
$orderOptions = array_map(fn($o) => $o->label, $slide->slide_options ?? []); $orderOptions = array_map(fn($o) => $o->label, $slide->slide_options ?? []);
$preparedText = $slide->isQa() ? implode("\n", (new QaService())->preparedQuestions($slide)) : '';
if ($this->request->is(['post', 'put', 'patch'])) { if ($this->request->is(['post', 'put', 'patch'])) {
$optionsText = (string)$this->request->getData('options_text', ''); $optionsText = (string)$this->request->getData('options_text', '');
$quizOptions = $this->postedQuizOptions(); $quizOptions = $this->postedQuizOptions();
$orderOptions = $this->postedOrderOptions(); $orderOptions = $this->postedOrderOptions();
$preparedText = (string)$this->request->getData('prepared_text', $preparedText);
if ($this->saveSlide($slide, $optionsText)) { if ($this->saveSlide($slide, $optionsText)) {
$this->Flash->success(__('Folie gespeichert.')); $this->Flash->success(__('Folie gespeichert.'));
@@ -89,7 +93,7 @@ class SlidesController extends AdminAppController
} }
$hasResponses = $this->Slides->Responses->exists(['slide_id' => $slide->id]); $hasResponses = $this->Slides->Responses->exists(['slide_id' => $slide->id]);
$this->set(compact('slide', 'optionsText', 'quizOptions', 'orderOptions', 'hasResponses')); $this->set(compact('slide', 'optionsText', 'quizOptions', 'orderOptions', 'preparedText', 'hasResponses'));
$this->render('form'); $this->render('form');
return null; return null;
@@ -334,6 +338,11 @@ class SlidesController extends AdminAppController
if ($slide->type === Slide::TYPE_CHOICE || $slide->isQuiz() || $slide->isOrder()) { if ($slide->type === Slide::TYPE_CHOICE || $slide->isQuiz() || $slide->isOrder()) {
$this->Slides->syncOptions($slide, $labels, $correct); $this->Slides->syncOptions($slide, $labels, $correct);
} }
// Without the field (stage no longer "collect") the prepared questions stay untouched.
$prepared = $this->request->getData('prepared_text');
if ($slide->isQa() && is_string($prepared)) {
(new QaService())->syncPrepared($slide, QaService::parsePrepared($prepared));
}
if ($slide->isQa() && $slide->qaStage() === Slide::QA_VOTE && !$slide->hasQaUpvotes()) { if ($slide->isQa() && $slide->qaStage() === Slide::QA_VOTE && !$slide->hasQaUpvotes()) {
// Upvotes were switched off while voting: continue with the discussion. // Upvotes were switched off while voting: continue with the discussion.
(new QaService())->setStage($slide, Slide::QA_DISCUSS); (new QaService())->setStage($slide, Slide::QA_DISCUSS);
+2 -2
View File
@@ -165,7 +165,7 @@ class ResponsesTable extends Table
{ {
$row = $this->find() $row = $this->find()
->select(['n' => $this->find()->func()->count('DISTINCT participant_hash')]) ->select(['n' => $this->find()->func()->count('DISTINCT participant_hash')])
->where(['slide_id' => $slideId]) ->where(['slide_id' => $slideId, 'participant_hash !=' => VoteService::PREPARED_HASH])
->disableHydration() ->disableHydration()
->first(); ->first();
@@ -186,7 +186,7 @@ class ResponsesTable extends Table
'n' => $this->find()->func()->count('DISTINCT Responses.participant_hash'), 'n' => $this->find()->func()->count('DISTINCT Responses.participant_hash'),
]) ])
->innerJoinWith('Slides') ->innerJoinWith('Slides')
->where(['Slides.poll_id' => $pollId]) ->where(['Slides.poll_id' => $pollId, 'Responses.participant_hash !=' => VoteService::PREPARED_HASH])
->groupBy(['Responses.slide_id']) ->groupBy(['Responses.slide_id'])
->disableHydration() ->disableHydration()
->all(); ->all();
+92
View File
@@ -27,6 +27,9 @@ class QaService
{ {
use LocatorAwareTrait; use LocatorAwareTrait;
/** Maximum number of questions the admin can prepare per slide. */
public const MAX_PREPARED = 50;
protected SlidesTable $Slides; protected SlidesTable $Slides;
protected ResponsesTable $Responses; protected ResponsesTable $Responses;
@@ -44,6 +47,95 @@ class QaService
$this->Responses = $responses; $this->Responses = $responses;
} }
/**
* Texts of the questions the admin entered beforehand, in entry order.
*
* @param \App\Model\Entity\Slide $slide Q&A slide
* @return list<string>
*/
public function preparedQuestions(Slide $slide): array
{
$rows = $this->Responses->questionsOf($slide->id)
->select(['text_value'])
->where(['Responses.participant_hash' => VoteService::PREPARED_HASH])
->orderBy(['Responses.id' => 'ASC'])
->disableHydration()
->all();
return array_values(array_map(fn($row) => (string)$row['text_value'], $rows->toArray()));
}
/**
* Textarea (one question per line) into clean question texts: whitespace collapsed,
* cut to the maximum length, duplicates (case-insensitive) and empty lines dropped.
*
* @param string $raw Textarea content
* @return list<string>
*/
public static function parsePrepared(string $raw): array
{
$texts = [];
foreach (preg_split('/\R/', $raw) ?: [] as $line) {
$text = mb_substr(trim((string)preg_replace('/\s+/u', ' ', $line)), 0, VoteService::MAX_TEXT_LENGTH);
if ($text !== '') {
$texts[mb_strtolower($text)] ??= $text;
}
}
return array_slice(array_values($texts), 0, self::MAX_PREPARED);
}
/**
* Makes the prepared questions of a slide match `$texts`: unchanged ones keep their id, removed
* ones disappear (with leftover upvotes), new ones are added. Questions already asked by
* participants are not added twice. Only allowed while collecting: later, upvotes and the
* discussion hang on the existing questions. Idempotent.
*
* @param \App\Model\Entity\Slide $slide Q&A slide
* @param list<string> $texts Clean texts, see parsePrepared()
* @return void
*/
public function syncPrepared(Slide $slide, array $texts): void
{
if ($slide->qaStage() !== Slide::QA_COLLECT) {
return;
}
$wanted = [];
foreach ($texts as $text) {
$wanted[mb_strtolower($text)] = $text;
}
$existing = [];
$rows = $this->Responses->questionsOf($slide->id)
->select(['id', 'text_value', 'participant_hash'])
->orderBy(['Responses.id' => 'ASC'])
->disableHydration()
->all();
foreach ($rows as $row) {
$key = mb_strtolower((string)$row['text_value']);
if ($row['participant_hash'] !== VoteService::PREPARED_HASH) {
// Asked by a participant already.
unset($wanted[$key]);
continue;
}
if (isset($wanted[$key]) && !isset($existing[$key])) {
$existing[$key] = true;
unset($wanted[$key]);
continue;
}
$this->Responses->deleteAll(['slide_id' => $slide->id, 'parent_id' => $row['id']]);
$this->Responses->deleteAll(['id' => $row['id']]);
}
foreach ($wanted as $text) {
$this->Responses->saveOrFail($this->Responses->newEntity([
'slide_id' => $slide->id,
'participant_hash' => VoteService::PREPARED_HASH,
'text_value' => $text,
]));
}
}
/** /**
* Questions of a slide, most upvoted first (ties: oldest first). * Questions of a slide, most upvoted first (ties: oldest first).
* *
+6
View File
@@ -49,6 +49,12 @@ class VoteService
public const MAX_TEXT_LENGTH = 500; public const MAX_TEXT_LENGTH = 500;
public const MAX_QA_QUESTIONS = 10; public const MAX_QA_QUESTIONS = 10;
/**
* participant_hash of questions entered by the admin beforehand (e.g. received by mail).
* Not a hex HMAC, so no participant can ever own, edit or delete them.
*/
public const PREPARED_HASH = 'prepared';
/** /**
* Word cloud: terms per request and terms a participant may name or upvote per slide. * Word cloud: terms per request and terms a participant may name or upvote per slide.
*/ */
+2
View File
@@ -38,5 +38,7 @@ class AppView extends View
public function initialize(): void public function initialize(): void
{ {
$this->addHelper('Format'); $this->addHelper('Format');
// No generated oninvalid/oninput handlers: the CSP blocks inline event handlers.
$this->addHelper('Form', ['autoSetCustomValidity' => false]);
} }
} }
+11 -3
View File
@@ -10,6 +10,7 @@
* @var string $optionsText * @var string $optionsText
* @var list<array{label: string, correct: bool}> $quizOptions * @var list<array{label: string, correct: bool}> $quizOptions
* @var list<string> $orderOptions Ordering slide: labels in the correct order * @var list<string> $orderOptions Ordering slide: labels in the correct order
* @var string $preparedText Q&A slide: questions entered beforehand, one per line
* @var bool|null $hasResponses * @var bool|null $hasResponses
*/ */
@@ -213,8 +214,8 @@ $optionsError = $slide->getError('options_text');
<?php elseif ($slide->type === 'quiz') : <?php elseif ($slide->type === 'quiz') :
$quizError = $slide->getError('quiz_options'); $quizError = $slide->getError('quiz_options');
$rows = $quizOptions; $rows = $quizOptions;
// Always offer a few empty rows (more via "Antwort hinzufügen" with JS). // Offer the two required rows (more via "Antwort hinzufügen" with JS), plus one spare when editing.
$rowCount = min(\App\Model\Table\SlidesTable::MAX_QUIZ_OPTIONS, max(4, count($rows) + 1)); $rowCount = min(\App\Model\Table\SlidesTable::MAX_QUIZ_OPTIONS, max(2, count($rows) + 1));
$rows = array_pad($rows, $rowCount, ['label' => '', 'correct' => false]); $rows = array_pad($rows, $rowCount, ['label' => '', 'correct' => false]);
?> ?>
<fieldset class="quiz-options<?= $quizError ? ' error' : '' ?>" data-quiz-options <fieldset class="quiz-options<?= $quizError ? ' error' : '' ?>" data-quiz-options
@@ -265,7 +266,7 @@ $optionsError = $slide->getError('options_text');
<?php elseif ($slide->isOrder()) : <?php elseif ($slide->isOrder()) :
$orderError = $slide->getError('order_options'); $orderError = $slide->getError('order_options');
$max = \App\Model\Table\SlidesTable::MAX_ORDER_OPTIONS; $max = \App\Model\Table\SlidesTable::MAX_ORDER_OPTIONS;
$rows = array_pad($orderOptions, min($max, max(4, count($orderOptions) + 1)), ''); $rows = array_pad($orderOptions, min($max, max(2, count($orderOptions) + 1)), '');
?> ?>
<fieldset class="order-options<?= $orderError ? ' error' : '' ?>" data-order-options data-max="<?= $max ?>" <fieldset class="order-options<?= $orderError ? ' error' : '' ?>" data-order-options data-max="<?= $max ?>"
aria-describedby="order-options-hint<?= $orderError ? ' order-options-error' : '' ?>"> aria-describedby="order-options-hint<?= $orderError ? ' order-options-error' : '' ?>">
@@ -330,6 +331,13 @@ $optionsError = $slide->getError('options_text');
'aria-describedby' => 'qa-self-upvote-hint', 'aria-describedby' => 'qa-self-upvote-hint',
]) ?> ]) ?>
<p class="hint" id="qa-self-upvote-hint"><?= __('Sinnvoll, wenn ihr Themen priorisiert („Was besprechen wir heute?“). Bei normalen Fragerunden lieber aus: Sonst landen oft die Fragen derjenigen vorn, die alle Stimmen sich selbst geben.') ?></p> <p class="hint" id="qa-self-upvote-hint"><?= __('Sinnvoll, wenn ihr Themen priorisiert („Was besprechen wir heute?“). Bei normalen Fragerunden lieber aus: Sonst landen oft die Fragen derjenigen vorn, die alle Stimmen sich selbst geben.') ?></p>
<?php if ($slide->qaStage() === \App\Model\Entity\Slide::QA_COLLECT) : ?>
<div class="input textarea">
<label for="prepared-text"><?= __('Vorab eingereichte Fragen (optional, eine pro Zeile, max. {0})', \App\Service\QaService::MAX_PREPARED) ?></label>
<textarea id="prepared-text" name="prepared_text" rows="5" aria-describedby="prepared-hint"><?= h($preparedText) ?></textarea>
<p class="hint" id="prepared-hint"><?= __('Z. B. Fragen, die dich vorab per E-Mail erreicht haben. Sie erscheinen wie Fragen der Teilnehmenden, ohne dass jemand sie bearbeiten kann. Gleiche Fragen werden nur einmal aufgenommen. Zeilen, die du hier entfernst, verschwinden wieder.') ?></p>
</div>
<?php endif; ?>
<p class="hint"><?= __('Ablauf in der Präsentation: 1. Fragen sammeln, 2. abstimmen, 3. besprechen – die Frage mit den meisten Upvotes zuerst. Ohne Upvotes entfällt Schritt 2. Du schaltest die Schritte selbst weiter.') ?></p> <p class="hint"><?= __('Ablauf in der Präsentation: 1. Fragen sammeln, 2. abstimmen, 3. besprechen – die Frage mit den meisten Upvotes zuerst. Ohne Upvotes entfällt Schritt 2. Du schaltest die Schritte selbst weiter.') ?></p>
<?php endif; ?> <?php endif; ?>
@@ -64,6 +64,8 @@ class AdminFragmentTest extends TestCase
$this->assertResponseNotContains('onclick='); $this->assertResponseNotContains('onclick=');
$this->assertResponseContains('data-confirm='); $this->assertResponseContains('data-confirm=');
// Required fields (settings form) must not get generated oninvalid/oninput handlers, the CSP blocks them.
$this->assertDoesNotMatchRegularExpression('/\son[a-z]+="/', (string)$this->_response->getBody());
} }
public function testSlideFormFragmentIsTheDialogContent(): void public function testSlideFormFragmentIsTheDialogContent(): void
@@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Service\PollStateService;
use App\Service\QaService;
use App\Service\VoteService;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* Questions the admin enters beforehand on a Q&A slide (textarea `prepared_text`).
*/
class QaPreparedTest extends TestCase
{
use IntegrationTestTrait;
use PlenarioTestTrait;
/**
* @var list<string>
*/
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
protected function setUp(): void
{
parent::setUp();
$this->enableCsrfToken();
}
public function testParsePreparedCleansLines(): void
{
$texts = QaService::parsePrepared(" Wann geht's los? \n\nwann geht's LOS?\r\nZweite Frage");
$this->assertSame(["Wann geht's los?", 'Zweite Frage'], $texts);
}
public function testCreatingSlideStoresPreparedQuestions(): void
{
[$poll, $token] = $this->createPoll();
$this->post("/admin/$token/slides/add", [
'type' => Slide::TYPE_QA,
'question' => 'Fragen',
'prepared_text' => "Frage A\nFrage B",
]);
$this->assertRedirect();
$slide = $this->slidesTable()->listForPoll($poll->id)[0];
$this->assertSame(['Frage A', 'Frage B'], (new QaService())->preparedQuestions($slide));
}
public function testEditSyncsAndIsIdempotent(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_QA);
$url = "/admin/$token/slides/{$slide->id}/edit";
$data = ['question' => 'Fragen', 'prepared_text' => "Frage A\nFrage B"];
$this->post($url, $data);
$responses = TableRegistry::getTableLocator()->get('Responses');
$ids = $responses->find()->where(['slide_id' => $slide->id])->all()->extract('id')->toList();
$this->assertCount(2, $ids);
$this->post($url, $data);
$this->assertSame($ids, $responses->find()->where(['slide_id' => $slide->id])->all()->extract('id')->toList());
$this->post($url, ['prepared_text' => "Frage B\nFrage C"] + $data);
$this->assertSame(['Frage B', 'Frage C'], (new QaService())->preparedQuestions($slide));
}
public function testParticipantQuestionsAreKeptAndNotDuplicated(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_QA);
$poll = $this->goLive($poll, $slide);
$hash = VoteService::participantHash(str_repeat('a', 32), $poll->id);
(new VoteService())->submit($poll, $slide, $hash, ['question' => 'Eigene Frage']);
$this->post("/admin/$token/slides/{$slide->id}/edit", [
'question' => 'Fragen',
'prepared_text' => "eigene frage\nVorab",
]);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => 'Fragen', 'prepared_text' => '']);
$responses = TableRegistry::getTableLocator()->get('Responses');
$this->assertSame(
['Eigene Frage'],
$responses->find()->where(['slide_id' => $slide->id])->all()->extract('text_value')->toList(),
);
}
public function testPreparedQuestionsAppearForParticipantsButNotAsOwn(): void
{
[$poll] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_QA);
(new QaService())->syncPrepared($slide, ['Vorab']);
$poll = $this->goLive($poll, $slide);
$slide = $this->slidesTable()->get($slide->id);
$hash = VoteService::participantHash(str_repeat('b', 32), $poll->id);
$qa = (new PollStateService())->qaState($slide, $hash);
$this->assertCount(1, $qa['questions']);
$this->assertSame([], $qa['mine']);
$this->assertSame(0, TableRegistry::getTableLocator()->get('Responses')->countParticipants($slide->id));
}
public function testNotChangedOutsideCollectStage(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_QA);
(new QaService())->syncPrepared($slide, ['Vorab']);
(new QaService())->setStage($slide, Slide::QA_VOTE);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => 'Fragen', 'prepared_text' => '']);
$this->assertSame(['Vorab'], (new QaService())->preparedQuestions($slide));
}
}
+2 -1
View File
@@ -2721,7 +2721,8 @@
if (submitter) { if (submitter) {
submitter.disabled = true; submitter.disabled = true;
} }
Fragments.request(form.action, { method: 'POST', body: new FormData(form) }) // getAttribute: forms with a field named "action" (play/pause buttons) shadow the form.action property.
Fragments.request(form.getAttribute('action'), { method: 'POST', body: new FormData(form) })
.then(function (doc) { return handle(doc, source); }) .then(function (doc) { return handle(doc, source); })
.catch(function () { .catch(function () {
form.removeAttribute('aria-busy'); form.removeAttribute('aria-busy');