Let participants edit their open answer while voting is open
CI / Deploy / test (push) Successful in 1m4s
CI / Deploy / deploy (push) Skipped

Generalises the comment edit to /p/{code}/edit: open answers can be
corrected (not emptied), scale comments as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 11:59:54 +01:00
1 parent e6f52a0449
commit 51d1be8695
7 files changed
+135 -48

No files matched your search

+13 -9
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Controller;
use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Model\Table\PollsTable;
use App\Service\PollStateService;
use App\Service\VoteException;
@@ -86,11 +87,11 @@ class ParticipateController extends AppController
$slide = $poll->is_active ? $stateService->currentSlide($poll) : null;
$participantHash = $this->participantHash($poll);
$state = $stateService->forParticipant($poll, $participantHash, $slide);
$ownComment = $slide?->hasComments() && $state['hasResponded']
? (new VoteService())->ownComment($slide, $participantHash)
$ownText = $slide !== null && VoteService::hasEditableText($slide) && $state['hasResponded']
? (new VoteService())->ownText($slide, $participantHash)
: null;
$this->set(compact('poll', 'slide', 'state', 'participantHash', 'ownComment'));
$this->set(compact('poll', 'slide', 'state', 'participantHash', 'ownText'));
$this->setPollInterval();
}
@@ -157,12 +158,13 @@ class ParticipateController extends AppController
}
/**
* Replaces the own comment on a scale slide while voting is open (e.g. to fix a typo).
* Replaces the own answer text (open question) or comment (scale) while voting is open,
* e.g. to fix a typo. See VoteService::editText().
*
* @param string $code Join code
* @return \Cake\Http\Response|null
*/
public function comment(string $code): ?Response
public function edit(string $code): ?Response
{
$this->request->allowMethod(['post']);
$poll = $this->loadPoll($code);
@@ -176,11 +178,13 @@ class ParticipateController extends AppController
throw new VoteException(__('Diese Frage ist nicht mehr aktiv.'));
}
$data = (array)$this->request->getData();
(new VoteService())->editComment($poll, $slide, $this->participantHash($poll), $data);
(new VoteService())->editText($poll, $slide, $this->participantHash($poll), $data);
$comment = $data['comment'] ?? '';
$this->Flash->success(!is_scalar($comment) || trim((string)$comment) === ''
? __('Dein Kommentar wurde entfernt.')
: __('Dein Kommentar wurde gespeichert.'));
$this->Flash->success(match (true) {
$slide->type === Slide::TYPE_OPEN => __('Deine Antwort wurde geändert.'),
!is_scalar($comment) || trim((string)$comment) === '' => __('Dein Kommentar wurde entfernt.'),
default => __('Dein Kommentar wurde gespeichert.'),
});
} catch (VoteException $e) {
$this->Flash->error($e->getMessage());
}