Merge pull request 'Add anonymous feedback option for open questions' (#13) from feature/private-feedback into main
CI / Deploy / test (push) Successful in 49s
CI / Deploy / deploy (push) Successful in 3s

Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
gnilebein committed 2026-11-07 16:30:08 +01:00
commit ae5dd22ff9
14 files changed
+312 -14

No files matched your search

+6 -1
View File
@@ -55,7 +55,7 @@ src/
HomeController Startseite, Anlegen (/create), Bestätigung, Join, Recover
AdminAppController Basis für /admin/{token}: löst Poll über Token-Hash auf (404 sonst), setzt Privacy-Header
AdminController Dashboard, Settings, Present, State-JSON, Control, QR, CSV-Export, Token rotieren, Löschen
SlidesController Folien-CRUD, Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen,
SlidesController Folien-CRUD, Antworten offener Fragen (`answers`), Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen,
YouTube-Link prüfen (`youtubeCheck`, JSON)
ParticipateController /p/{code}: Ansicht, State-JSON, Abstimmen; anonymes Cookie plenario_pid
EmbedController /e/{key}/{id}: eine Folie zum Einbetten (z. B. Canva), activate/heartbeat/pause/control
@@ -153,6 +153,11 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
ist die Berechtigung, siehe `Application::middleware()`) und erlauben Framing per CSP `frame-ancestors`
(`EMBED_FRAME_ANCESTORS`); alle anderen Seiten bleiben `X-Frame-Options: SAMEORIGIN`.
- **Anonymes Feedback** (offene Frage mit Setting `private`, `Slide::isPrivate()`): Antworttexte erscheinen **nie** im
Presenter-/Embed-JSON (`results.answers` leer, nur `participants`) und nie bei Teilnehmenden (keine `results`,
unabhängig von `show_results_to_participants`). Lesen nur in der Verwaltung (`slides:answers`,
`ResultsService::answers()`) und im CSV-Export.
### Neuen Folientyp hinzufügen (Checkliste)
1. Konstante + Label + Beschreibung + `DEFAULT_SETTINGS` in `src/Model/Entity/Slide.php`
+2
View File
@@ -81,6 +81,8 @@ return function (RouteBuilder $routes): void {
->setPatterns($token)->setMethods(['POST']);
$admin->connect('/slides/youtube-check', 'Slides::youtubeCheck', ['_name' => 'slides:youtube-check'])
->setPatterns($token)->setMethods(['POST']);
$admin->connect('/slides/{id}/answers', 'Slides::answers', ['_name' => 'slides:answers'])
->setPatterns($token)->setPass(['id']);
$admin->connect('/slides/{id}/reset', 'Slides::reset', ['_name' => 'slides:reset'])
->setPatterns($token)->setPass(['id'])->setMethods(['POST']);
});
+17
View File
@@ -6,6 +6,7 @@ namespace App\Controller;
use App\Model\Entity\Slide;
use App\Model\Table\SlidesTable;
use App\Service\QaService;
use App\Service\ResultsService;
use App\Service\YouTubeService;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Response;
@@ -158,6 +159,22 @@ class SlidesController extends AdminAppController
return $this->redirect($this->adminUrl());
}
/**
* All answers of an open question (also anonymous feedback, which is never shown on the stage).
*
* @param string $id Slide id
* @return void
*/
public function answers(string $id): void
{
$slide = $this->loadSlide($id);
if ($slide->type !== Slide::TYPE_OPEN) {
throw new NotFoundException(__('Folie nicht gefunden.'));
}
$this->set('slide', $slide);
$this->set('answers', (new ResultsService())->answers($slide));
}
/**
* Loads a slide that belongs to the current poll (404 otherwise).
*
+13 -1
View File
@@ -81,7 +81,8 @@ class Slide extends Entity
self::TYPE_CHOICE => ['multiple' => false],
// allow_downvotes only takes effect together with allow_upvotes
self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true],
self::TYPE_OPEN => [],
// private: anonymous feedback, answers only visible in the admin area (never on the stage)
self::TYPE_OPEN => ['private' => false],
self::TYPE_SCALE => ['scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => ''],
self::TYPE_CONTENT => [],
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
@@ -327,4 +328,15 @@ class Slide extends Entity
{
return $this->getSettings()[$key] ?? null;
}
/**
* Open question collecting anonymous feedback: answers are never shown on the
* presenter screen or to participants, only in the admin area and the CSV export.
*
* @return bool
*/
public function isPrivate(): bool
{
return $this->type === self::TYPE_OPEN && (bool)$this->setting('private');
}
}
+3
View File
@@ -145,6 +145,9 @@ class SlidesTable extends Table
$settings['allow_upvotes'] = filter_var($input['allow_upvotes'] ?? true, FILTER_VALIDATE_BOOLEAN);
$settings['allow_downvotes'] = filter_var($input['allow_downvotes'] ?? true, FILTER_VALIDATE_BOOLEAN);
break;
case Slide::TYPE_OPEN:
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
break;
case Slide::TYPE_SCALE:
$min = max(0, min(1, (int)($input['scale_min'] ?? 1)));
$max = max(2, min(10, (int)($input['scale_max'] ?? 5)));
+2
View File
@@ -25,6 +25,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* when their deadline has passed.
*
* Q&A slides have their own participant view (`qa`, see qaState()), never `results`.
* Private open questions (anonymous feedback) never show results to participants.
*/
class PollStateService
{
@@ -162,6 +163,7 @@ class PollStateService
$showResults = $slide !== null
&& $slide->isInteractive()
&& $qa === null
&& !$slide->isPrivate()
&& ($quiz !== null
? $quiz['phase'] === Slide::QUIZ_FINISHED
: ($poll->show_results_to_participants && ($hasResponded || !$isVotingOpen))
+30 -12
View File
@@ -16,7 +16,8 @@ use Cake\ORM\Locator\LocatorAwareTrait;
* - wordcloud: 'words' => [['key' (lower case), 'text', 'count', 'down', 'weight' (0..1)]]
* (count = participants who named or upvoted the word, down = downvotes,
* weight follows count)
* - open: 'answers' => [['text', 'created']] newest first
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
* private (anonymous feedback): 'answers' is always empty, texts only via answers()
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
* 'min', 'max', 'minLabel', 'maxLabel'
* - quiz: 'phase' (ready|running|finished), 'timeLimit' (s, 0 = manual), 'remaining' (s|null),
@@ -213,19 +214,36 @@ class ResultsService
*/
protected function open(Slide $slide): array
{
$rows = $this->Responses->find()
->select(['text_value', 'created'])
->where(['slide_id' => $slide->id, 'text_value IS NOT' => null])
->orderBy(['id' => 'DESC'])
->limit(self::MAX_ANSWERS)
->all();
$answers = [];
foreach ($rows as $row) {
$answers[] = ['text' => $row->text_value, 'created' => $row->created->toIso8601String()];
return [
'private' => $slide->isPrivate(),
'answers' => $slide->isPrivate() ? [] : $this->answers($slide, self::MAX_ANSWERS),
];
}
return ['answers' => $answers];
/**
* Texts of an open question, newest first – also of private slides,
* so only for the admin area (never for the presenter screen or participants).
*
* @param \App\Model\Entity\Slide $slide Open question
* @param int|null $limit Max. answers, null = all
* @return list<array{text: string, created: string}>
*/
public function answers(Slide $slide, ?int $limit = null): array
{
$query = $this->Responses->find()
->select(['text_value', 'created'])
->where(['slide_id' => $slide->id, 'text_value IS NOT' => null])
->orderBy(['id' => 'DESC']);
if ($limit !== null) {
$query->limit($limit);
}
$answers = [];
foreach ($query->all() as $row) {
$answers[] = ['text' => (string)$row->text_value, 'created' => $row->created->toIso8601String()];
}
return $answers;
}
/**
+4
View File
@@ -97,6 +97,7 @@ $url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $ad
'discuss' => __('Fragen werden besprochen'),
][$slide->qaStage()]) ?> · <?= __n('max. {0} Upvote pro Person', 'max. {0} Upvotes pro Person', (int)$slide->setting('max_upvotes'), (int)$slide->setting('max_upvotes')) ?></span>
<?php elseif (!$slide->is_voting_open) : ?><span class="muted">· <?= __('Abstimmung geschlossen') ?></span><?php endif; ?>
<?php if ($slide->isPrivate()) : ?><span class="badge" title="<?= __('Antworten werden nicht öffentlich angezeigt') ?>">🔒 <?= __('anonym') ?></span><?php endif; ?>
<?php endif; ?>
</div>
<a class="slide-item__title" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= h($slide->question) ?></a>
@@ -126,6 +127,9 @@ $url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $ad
'title' => __('Diese Folie jetzt den Teilnehmenden zeigen'),
]) ?>
<?php endif; ?>
<?php if ($slide->type === 'open' && $count > 0) : ?>
<a class="button button--small" href="<?= $this->Url->build($url('slides:answers', ['id' => $slide->id])) ?>"><?= __('Antworten') ?></a>
<?php endif; ?>
<a class="button button--small" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= __('Bearbeiten') ?></a>
<?php if ($count > 0) : ?>
<?= $this->Form->postLink(__('Zurücksetzen'), $url('slides:reset', ['id' => $slide->id]), [
+6
View File
@@ -190,7 +190,13 @@ $countdown = function (?int $remaining): string {
<?php elseif ($slide->type === 'open') : ?>
<textarea name="text" rows="4" maxlength="500" required
<?= $slide->isPrivate() ? 'aria-describedby="private-hint"' : '' ?>
placeholder="<?= __('Deine Antwort …') ?>"></textarea>
<?php if ($slide->isPrivate()) : ?>
<p class="hint private-hint" id="private-hint">
🔒 <?= __('Anonymes Feedback: Deine Antwort wird nicht öffentlich angezeigt und nicht mit deinem Namen gespeichert.') ?>
</p>
<?php endif; ?>
<?php elseif ($slide->type === 'scale') : ?>
<div class="scale">
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* All answers of an open question – the only place where anonymous feedback
* (private open questions) can be read, besides the CSV export.
*
* @var \App\View\AppView $this
* @var \App\Model\Entity\Poll $poll
* @var string $adminToken
* @var \App\Model\Entity\Slide $slide
* @var list<array{text: string, created: string}> $answers
*/
use Cake\I18n\DateTime;
$this->assign('title', $slide->question);
$this->assign('noindex', '1');
$count = count($answers);
?>
<p><a href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>">← <?= __('Zurück zur Verwaltung') ?></a></p>
<section class="card">
<p class="eyebrow">
<?= h($slide->typeLabel()) ?>
<?php if ($slide->isPrivate()) : ?>· 🔒 <?= __('Anonymes Feedback') ?><?php endif; ?>
</p>
<h1><?= h($slide->question) ?></h1>
<p class="muted"><?= __n('{0} Antwort, neueste zuerst', '{0} Antworten, neueste zuerst', $count, $count) ?></p>
<?php if ($slide->isPrivate()) : ?>
<p class="hint"><?= __('Diese Antworten werden weder in der Präsentation noch den Teilnehmenden angezeigt.') ?></p>
<?php endif; ?>
<?php if ($answers === []) : ?>
<p class="empty"><?= __('Noch keine Antworten.') ?></p>
<?php else : ?>
<ol class="answers-page" reversed>
<?php foreach ($answers as $answer) :
$created = new DateTime($answer['created']); ?>
<li>
<?= h($answer['text']) ?>
<time datetime="<?= h($answer['created']) ?>"><?= h($created->i18nFormat('dd.MM.yyyy, HH:mm')) ?></time>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
</section>
+7
View File
@@ -128,6 +128,13 @@ $optionsError = $slide->getError('options_text');
'label' => __('Mehrfachauswahl erlauben'),
'checked' => (bool)$settings['multiple'],
]) ?>
<?php elseif ($slide->type === 'open') : ?>
<?= $this->Form->control('settings.private', [
'type' => 'checkbox',
'label' => __('Anonymes Feedback: Antworten nicht öffentlich anzeigen'),
'checked' => (bool)$settings['private'],
]) ?>
<p class="hint"><?= __('Präsentation und Teilnehmende sehen nur, wie viele Antworten eingegangen sind. Die Texte siehst nur du hier in der Verwaltung (und im CSV-Export).') ?></p>
<?php elseif ($slide->type === 'wordcloud') : ?>
<?= $this->Form->control('settings.allow_upvotes', [
'type' => 'checkbox',
@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Model\Table\SlidesTable;
use App\Service\VoteService;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* Open questions as anonymous feedback: answers only in the admin area.
*/
class PrivateFeedbackTest 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();
}
/**
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
*/
protected function privateSlideWithAnswer(string $text = 'Geheimes <Feedback>'): array
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN, ['settings' => ['private' => true]]);
$poll = $this->goLive($poll, $slide);
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), ['text' => $text]);
return [$poll, $token, $slide];
}
protected function participantState(Poll $poll): array
{
$this->get('/p/' . $poll->join_code . '/state');
return json_decode((string)$this->_response->getBody(), true);
}
public function testSettingIsSanitized(): void
{
$this->assertTrue(SlidesTable::sanitizeSettings(Slide::TYPE_OPEN, ['private' => '1'])['private']);
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_OPEN, ['private' => '0'])['private']);
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_OPEN, [])['private']);
}
public function testExistingOpenSlidesStayPublic(): void
{
[$poll] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN, ['settings' => []]);
$this->assertFalse($slide->isPrivate());
}
public function testFormSavesPrivateSetting(): void
{
[$poll, $token] = $this->createPoll();
$this->post("/admin/$token/slides/add?type=open", [
'type' => 'open',
'question' => 'Was können wir besser machen?',
'settings' => ['private' => '1'],
]);
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
$this->assertTrue($slide->isPrivate());
}
public function testPresenterSeesOnlyTheCount(): void
{
[, $token] = $this->privateSlideWithAnswer();
$this->get("/admin/$token/state");
$state = json_decode((string)$this->_response->getBody(), true);
$this->assertTrue($state['results']['private']);
$this->assertSame([], $state['results']['answers']);
$this->assertSame(1, $state['results']['participants']);
$this->assertResponseNotContains('Geheimes');
}
public function testParticipantsNeverSeeAnswers(): void
{
[$poll] = $this->privateSlideWithAnswer();
$this->assertTrue($poll->show_results_to_participants);
$this->assertNull($this->participantState($poll)['results']);
$this->get('/p/' . $poll->join_code);
$this->assertResponseContains('Anonymes Feedback');
$this->assertResponseNotContains('Geheimes');
// Not even after answering themselves.
$this->post('/p/' . $poll->join_code . '/vote', ['slide_id' => $poll->current_slide_id, 'text' => 'Meins']);
$this->assertNull($this->participantState($poll)['results']);
$this->assertResponseNotContains('Geheimes');
}
public function testEmbedSeesOnlyTheCount(): void
{
[$poll, , $slide] = $this->privateSlideWithAnswer();
$key = $this->pollsTable()->ensureEmbedKey($poll);
$this->get("/e/$key/{$slide->id}/state");
$this->assertResponseOk();
$this->assertResponseNotContains('Geheimes');
}
public function testAdminReadsAnswers(): void
{
[, $token, $slide] = $this->privateSlideWithAnswer();
$this->get("/admin/$token");
$this->assertResponseContains("/slides/{$slide->id}/answers");
$this->get("/admin/$token/slides/{$slide->id}/answers");
$this->assertResponseOk();
$this->assertResponseContains('Geheimes &lt;Feedback&gt;');
$this->assertHeader('Referrer-Policy', 'no-referrer');
}
public function testAnswersPageOnlyForOwnOpenSlides(): void
{
[$poll, $token] = $this->createPoll();
$choice = $this->createSlide($poll);
[$other] = $this->createPoll('Andere');
$foreign = $this->createSlide($other, Slide::TYPE_OPEN);
$this->get("/admin/$token/slides/{$choice->id}/answers");
$this->assertResponseCode(404);
$this->get("/admin/$token/slides/{$foreign->id}/answers");
$this->assertResponseCode(404);
}
public function testPublicOpenQuestionStillShowsAnswers(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$poll = $this->goLive($poll, $slide);
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('b', 32), $poll->id), ['text' => 'Offen']);
$this->get("/admin/$token/state");
$state = json_decode((string)$this->_response->getBody(), true);
$this->assertFalse($state['results']['private']);
$this->assertSame('Offen', $state['results']['answers'][0]['text']);
}
}
+9
View File
@@ -456,6 +456,15 @@ button.qa-steps__step { cursor: pointer; }
button.qa-steps__step:hover:not(:disabled) { color: var(--text); border-color: var(--text); }
.qa-steps .is-current .qa-steps__step { background: var(--qa); border-color: var(--qa); color: var(--surface); font-weight: 700; cursor: default; }
.private-summary { text-align: center; }
.private-summary p { margin: 0 0 .3em; }
.private-summary__count { font-size: 3em; font-weight: 800; line-height: 1; color: var(--c2); font-variant-numeric: tabular-nums; }
.private-summary__hint { color: var(--muted); font-size: .85em; }
.private-hint { margin-top: 8px; }
.answers-page { list-style: none; padding: 0; margin: 0; }
.answers-page li { padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface); white-space: pre-line; overflow-wrap: anywhere; }
.answers-page time { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; }
/* ---------------------------------------------------------------- presenter */
/* Dark by default (beamer); the presenter's own switch can make it light (data-theme="light"). */
body.present {
+9
View File
@@ -499,6 +499,15 @@
},
open: function (results) {
if (results.private) {
// Anonymous feedback: the texts never reach the stage, only the count.
var n = results.participants;
return el('div', { class: 'private-summary' }, [
el('p', { class: 'private-summary__count', text: String(n) }),
el('p', { text: (n === 1 ? 'anonyme Antwort' : 'anonyme Antworten') + ' eingegangen' }),
el('p', { class: 'private-summary__hint', text: '🔒 Antworten werden nicht öffentlich angezeigt.' })
]);
}
return el('ul', { class: 'answers' }, results.answers.map(function (answer) {
return el('li', { class: 'answer', text: answer.text });
}));