Remove the polls menu, keep the single commands
bin/cake polls list|show|delete|remind|cleanup stay as they are. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
664088e139
commit
349359dad3
6 files changed
+4
-220
No files matched your search
@@ -34,7 +34,7 @@ E-Mail anlegen, kein Login, Verwaltung über einen geheimen Admin-Link, Teilnahm
|
||||
| Coding Standard | `vendor/bin/phpcs` / Autofix `vendor/bin/phpcbf` |
|
||||
| Neue Migration | `bin/cake bake migration NameDerMigration` |
|
||||
| Verwaiste Folienbilder löschen | `bin/cake images_cleanup [--dry-run]` |
|
||||
| Umfragen verwalten (Admin-CLI) | `bin/cake polls` (Menü) bzw. `polls list\|show\|delete\|remind\|cleanup` (siehe [docs/operations.md](docs/operations.md)) |
|
||||
| Umfragen verwalten (Admin-CLI) | `bin/cake polls list\|show\|delete\|remind\|cleanup` (siehe [docs/operations.md](docs/operations.md)) |
|
||||
|
||||
**Vor jedem Commit:** `vendor/bin/phpunit` und `vendor/bin/phpcs` müssen grün sein
|
||||
(Warnungen zur Zeilenlänge bei langen deutschen Texten sind ok).
|
||||
|
||||
@@ -24,7 +24,7 @@ src/
|
||||
EmbedController /e/{key}/{id}: eine Folie zum Einbetten (z. B. Canva), activate/heartbeat/pause/control
|
||||
ErrorController Fehlerseiten (Templates unter templates/Error, Layout `error`)
|
||||
Command/ImagesCleanupCommand `images_cleanup`: Bilddateien ohne Folie entfernen (idempotent)
|
||||
Command/Polls*Command `polls` (Menü), `polls list|show|delete|remind|cleanup` (Basis `PollsCommand`: Suche per id/Code, Links, Löschen)
|
||||
Command/Polls*Command `polls list|show|delete|remind|cleanup` (Basis `PollsCommand`: Suche per id/Code, Links, Löschen)
|
||||
Mailer/ PollMailer (adminLink, recovery; `sendSafely()` loggt Transportfehler statt zu werfen), Transport/FileTransport (lokal)
|
||||
Middleware/ HostHeaderMiddleware: prüft in Produktion den Host gegen APP_FULL_BASE_URL;
|
||||
SecurityHeadersMiddleware (äußerste Schicht): CSP mit Nonce, Framing, nosniff, Referrer-/Permissions-Policy
|
||||
|
||||
+1
-4
@@ -118,13 +118,10 @@ Bei Updates: Code aktualisieren, `composer install --no-dev`, Migrationen und `c
|
||||
|
||||
### Umfragen verwalten und aufräumen (CLI)
|
||||
|
||||
Am einfachsten geht es menügeführt: `bin/cake polls` ohne Unterbefehl zeigt ein Menü (Umfragen anzeigen und suchen,
|
||||
Umfrage öffnen mit Details, Admin-Link und Löschen, Erinnern, Aufräumen). Destruktive Aktionen zeigen vorher eine Vorschau
|
||||
und fragen nach, jede Eingabe hat eine sichere Vorgabe (Zurück/Nein). Für Skripte und Cron gibt es die einzelnen Befehle:
|
||||
Zum Verwalten per Hand und für Skripte/Cron:
|
||||
|
||||
| Befehl | Zweck |
|
||||
|---|---|
|
||||
| `bin/cake polls` | Menü (interaktiv) |
|
||||
| `bin/cake polls list [--expired] [--email=text] [--sort=created\|activity\|title]` | Umfragen mit E-Mail, Ablaufdatum und Erinnerung |
|
||||
| `bin/cake polls show <id\|code> [--link]` | Details; mit `--link` auch der geheime Admin-Link (nur auf Wunsch) |
|
||||
| `bin/cake polls delete <id\|code> [--yes]` | Eine Umfrage samt Folien, Antworten und Bildern löschen (fragt nach) |
|
||||
|
||||
+1
-2
@@ -13,8 +13,7 @@ Aufräumen und Erinnerungen, CI/CD, Release-Pakete, Container.
|
||||
Aufräumen per Cron: `bin/cake polls cleanup` (erst `remind`, dann idempotent löschen über `PollsTable::delete()` samt
|
||||
Folien/Bildern, danach `images_cleanup`; `--dry-run`; Cron-Einrichtung für Server und Docker steht in [deployment.md](deployment.md) unter
|
||||
„Cronjob einrichten“, im Container läuft kein cron). `last_admin_access` fließt nicht mehr ein. `polls show --link`
|
||||
ist die einzige Stelle, die den Admin-Link ausgibt (nie in `list`). Das Menü `bin/cake polls` (`PollsMenuCommand`) ruft nur diese Befehle per `executeCommand()` auf; jede Abfrage hat eine
|
||||
Vorgabe (`0`/leer/`n`), damit geschlossene Eingabe es beendet statt zu schleifen; Löschen/Aufräumen erst nach Vorschau (`--dry-run`) und Rückfrage.
|
||||
ist die einzige Stelle, die den Admin-Link ausgibt (nie in `list`).
|
||||
Tests: `PollsCommandsTest.php` (leert vorher alle Umfragen).
|
||||
|
||||
## Deployment
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\Entity\Poll;
|
||||
use Cake\Console\Arguments;
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\Console\ConsoleOptionParser;
|
||||
|
||||
/**
|
||||
* Menu-driven entry to the poll administration: `bin/cake polls` without a sub command.
|
||||
* Only wraps the other `polls …` commands, so scripts and cron keep using those directly.
|
||||
* Every prompt has a safe default (back/quit/no), so a closed stdin ends the menu instead of looping.
|
||||
*
|
||||
* Usage: bin/cake polls
|
||||
*/
|
||||
class PollsMenuCommand extends PollsCommand
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function defaultName(): string
|
||||
{
|
||||
return 'polls';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Cake\Console\ConsoleOptionParser $parser Parser
|
||||
* @return \Cake\Console\ConsoleOptionParser
|
||||
*/
|
||||
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
|
||||
{
|
||||
return $parser
|
||||
->setDescription(__('Menügeführte Verwaltung der Umfragen. Für Skripte und Cron: polls list|show|delete|remind|cleanup.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Cake\Console\Arguments $args Arguments
|
||||
* @param \Cake\Console\ConsoleIo $io Console
|
||||
* @return int
|
||||
*/
|
||||
public function execute(Arguments $args, ConsoleIo $io): int
|
||||
{
|
||||
while (true) {
|
||||
$io->out('');
|
||||
$io->out('<info>' . __('PlenarIO – Umfragen verwalten') . '</info>');
|
||||
$io->out([
|
||||
' 1) ' . __('Alle Umfragen anzeigen'),
|
||||
' 2) ' . __('Abgelaufene Umfragen anzeigen'),
|
||||
' 3) ' . __('Nach E-Mail-Adresse suchen'),
|
||||
' 4) ' . __('Umfrage öffnen (Details, Admin-Link, Löschen)'),
|
||||
' 5) ' . __('Erinnerungen vor dem Ablauf versenden'),
|
||||
' 6) ' . __('Aufräumen (Erinnern, abgelaufene Umfragen löschen)'),
|
||||
' 0) ' . __('Beenden'),
|
||||
]);
|
||||
|
||||
switch ($io->askChoice(__('Was möchtest du tun?'), ['1', '2', '3', '4', '5', '6', '0'], '0')) {
|
||||
case '1':
|
||||
$this->executeCommand(PollsListCommand::class, [], $io);
|
||||
break;
|
||||
case '2':
|
||||
$this->executeCommand(PollsListCommand::class, ['--expired'], $io);
|
||||
break;
|
||||
case '3':
|
||||
$email = $io->ask(__('Teil der E-Mail-Adresse (leer = zurück)'), '');
|
||||
if ($email !== '') {
|
||||
$this->executeCommand(PollsListCommand::class, ['--email=' . $email], $io);
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
$this->openPoll($io);
|
||||
break;
|
||||
case '5':
|
||||
$this->confirmed($io, PollsRemindCommand::class, $this->polls()->find('reminderDue')->count());
|
||||
break;
|
||||
case '6':
|
||||
$this->confirmed($io, PollsCleanupCommand::class, $this->polls()->find('expired')->count()
|
||||
+ $this->polls()->find('reminderDue')->count());
|
||||
break;
|
||||
default:
|
||||
return static::CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows what a command would do (--dry-run), asks and only then runs it for real.
|
||||
*
|
||||
* @param \Cake\Console\ConsoleIo $io Console
|
||||
* @param class-string<\Cake\Command\Command> $command Command with a --dry-run option
|
||||
* @param int $affected Number of polls the command would touch
|
||||
* @return void
|
||||
*/
|
||||
protected function confirmed(ConsoleIo $io, string $command, int $affected): void
|
||||
{
|
||||
if ($affected === 0) {
|
||||
$io->out(__('Nichts zu tun.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->executeCommand($command, ['--dry-run'], $io);
|
||||
if ($io->askChoice(__('Jetzt ausführen?'), ['y', 'n'], 'n') === 'y') {
|
||||
$this->executeCommand($command, [], $io);
|
||||
} else {
|
||||
$io->out(__('Abgebrochen.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks for one poll and offers the actions on it until the user goes back.
|
||||
*
|
||||
* @param \Cake\Console\ConsoleIo $io Console
|
||||
* @return void
|
||||
*/
|
||||
protected function openPoll(ConsoleIo $io): void
|
||||
{
|
||||
$this->executeCommand(PollsListCommand::class, [], $io);
|
||||
$reference = $io->ask(__('ID oder Code der Umfrage (leer = zurück)'), '');
|
||||
if ($reference === '') {
|
||||
return;
|
||||
}
|
||||
$poll = $this->findPoll($reference);
|
||||
if ($poll === null) {
|
||||
$io->err(__('Umfrage „{0}“ nicht gefunden.', $reference));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->executeCommand(PollsShowCommand::class, [(string)$poll->id], $io);
|
||||
while (true) {
|
||||
$io->out([
|
||||
'',
|
||||
' 1) ' . __('Details anzeigen'),
|
||||
' 2) ' . __('Admin-Link anzeigen (geheim!)'),
|
||||
' 3) ' . __('Umfrage endgültig löschen'),
|
||||
' 0) ' . __('Zurück'),
|
||||
]);
|
||||
$choice = $io->askChoice(__('#{0} {1}: Was möchtest du tun?', $poll->id, $this->shorten($poll)), ['1', '2', '3', '0'], '0');
|
||||
if ($choice === '1') {
|
||||
$this->executeCommand(PollsShowCommand::class, [(string)$poll->id], $io);
|
||||
} elseif ($choice === '2') {
|
||||
$this->executeCommand(PollsShowCommand::class, [(string)$poll->id, '--link'], $io);
|
||||
} elseif ($choice === '3') {
|
||||
// The delete command asks for confirmation itself.
|
||||
$this->executeCommand(PollsDeleteCommand::class, [(string)$poll->id], $io);
|
||||
if ($this->polls()->find()->where(['Polls.id' => $poll->id])->count() === 0) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Model\Entity\Poll $poll Poll
|
||||
* @return string Title, shortened for prompts
|
||||
*/
|
||||
protected function shorten(Poll $poll): string
|
||||
{
|
||||
return mb_strimwidth($poll->title, 0, 40, '…');
|
||||
}
|
||||
}
|
||||
@@ -118,53 +118,6 @@ class PollsCommandsTest extends TestCase
|
||||
$this->assertExitError();
|
||||
}
|
||||
|
||||
public function testMenuQuits(): void
|
||||
{
|
||||
$this->exec('polls', ['0']);
|
||||
$this->assertExitSuccess();
|
||||
$this->assertOutputContains('Umfragen verwalten');
|
||||
}
|
||||
|
||||
public function testMenuListsAndOpensPollWithLink(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll('Menü-Umfrage', 'menu@example.org');
|
||||
|
||||
$this->exec('polls', ['1', '4', (string)$poll->id, '2', '0', '0']);
|
||||
$this->assertExitSuccess();
|
||||
$this->assertOutputContains('menu@example.org');
|
||||
$this->assertOutputContains('https://plenario.test/admin/' . $token);
|
||||
|
||||
$this->exec('polls', ['4', 'ZZZZZZ', '0']);
|
||||
$this->assertExitSuccess();
|
||||
$this->assertErrorContains('nicht gefunden');
|
||||
}
|
||||
|
||||
public function testMenuDeleteNeedsConfirmation(): void
|
||||
{
|
||||
[$poll] = $this->createPoll();
|
||||
|
||||
$this->exec('polls', ['4', (string)$poll->id, '3', 'n', '0', '0']);
|
||||
$this->assertSame(1, $this->pollsTable()->find()->where(['id' => $poll->id])->count());
|
||||
|
||||
$this->exec('polls', ['4', (string)$poll->id, '3', 'y', '0']);
|
||||
$this->assertSame(0, $this->pollsTable()->find()->where(['id' => $poll->id])->count());
|
||||
}
|
||||
|
||||
public function testMenuCleanupAsksBeforeDeleting(): void
|
||||
{
|
||||
[$old] = $this->createPoll();
|
||||
$this->age($old->id, 100);
|
||||
|
||||
$this->exec('polls', ['6', 'n', '0']);
|
||||
$this->assertSame(1, $this->pollsTable()->find()->count());
|
||||
|
||||
$this->exec('polls', ['6', 'y', '0']);
|
||||
$this->assertSame(0, $this->pollsTable()->find()->count());
|
||||
|
||||
$this->exec('polls', ['6', '0']);
|
||||
$this->assertOutputContains('Nichts zu tun.');
|
||||
}
|
||||
|
||||
public function testReminderGoesOutOnceInTheLastDaysBeforeExpiry(): void
|
||||
{
|
||||
[$young, $youngToken] = $this->createPoll('Jung', 'jung@example.org');
|
||||
|
||||
Reference in new issue
Block a user