Loheide-eu-mitarbeiterplatt.../app/Filament/Pages/Feedback.php
Friederich Loheide 029dbd243d Rückmeldungen, Hintergrundaufgaben, Systemzustand und Web-Installer
- Rückmeldungen an den Hersteller (docs/specs/feedback.md): Fehlerbericht und
  Funktionswunsch, nur freigeschaltete Wege, Idempotency-Key je Meldung,
  Warteschlange mit höchstens fünf Versuchen, 422 am Feld, 429 mit Wartezeit,
  404 blendet den Weg aus, Referenznummer und „Meine Rückmeldungen“,
  sichtbare technische Angaben und Datenschutzhinweis über dem Absendeknopf
- Hintergrundaufgaben ohne Dauerprozess: Cron, Web-Cron (/cron/{token}) oder
  Pseudo-Cron nach dem Seitenaufruf; Queue in kurzen Häppchen
- Seite „Systemzustand“ mit Voraussetzungen, Grenzen, Betrieb, Sicherheit und
  Anleitung für den Cronjob
- Web-Installer (Systemprüfung → Datenbank → Administrator), legt .env und
  Anwendungsschlüssel selbst an, arbeitet vor der Einrichtung ohne Datenbank
- Datenbank-Benachrichtigungen im Admin-Bereich

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 06:11:09 +00:00

137 lines
5.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Pages;
use App\Models\VendorFeedback;
use App\Support\Audit;
use App\Support\Feedback\FeedbackChannels;
use App\Support\Feedback\FeedbackOutbox;
use App\Support\Feedback\FeedbackResult;
use App\Support\Feedback\TechnicalInfo;
use App\Support\License\LicenseStore;
use BackedEnum;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use UnitEnum;
/**
* „Hilfe → Rückmeldung geben“: Fehlerbericht oder Funktionswunsch an den
* Hersteller (docs/specs/feedback.md).
*/
class Feedback extends Page
{
protected string $view = 'filament.pages.feedback';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedChatBubbleLeftEllipsis;
protected static string|UnitEnum|null $navigationGroup = 'Hilfe';
protected static ?string $navigationLabel = 'Rückmeldung geben';
protected static ?string $title = 'Rückmeldung geben';
protected static ?string $slug = 'rueckmeldung';
public string $type = '';
public string $subject = '';
public string $body = '';
public string $severity = 'normal';
public string $email = '';
public string $name = '';
public ?string $lastReference = null;
public ?string $notice = null;
public function mount(FeedbackChannels $channels): void
{
$this->type = (string) array_key_first($channels->available());
}
public function submit(FeedbackChannels $channels, FeedbackOutbox $outbox, TechnicalInfo $info): void
{
$available = $channels->available();
$this->validate([
'type' => ['required', 'in:'.implode(',', array_keys($available))],
'subject' => ['required', 'string', 'max:255'],
'body' => ['required', 'string', 'min:10', 'max:20000'],
'severity' => ['required', 'in:low,normal,high,critical'],
'email' => ['nullable', 'email', 'max:255'],
'name' => ['nullable', 'string', 'max:255'],
], attributes: [
'type' => 'Art der Meldung', 'subject' => 'Betreff', 'body' => 'Beschreibung',
'email' => 'E-Mail-Adresse', 'name' => 'Name',
]);
$this->notice = null;
$this->lastReference = null;
$payload = array_filter([
'title' => $this->subject,
'body' => $this->body,
'email' => $this->email ?: null,
'name' => $this->name ?: null,
'severity' => $this->type === 'bugreport' ? $this->severity : null,
...$info->collect(),
], fn ($value) => $value !== null);
$result = $outbox->submit(auth()->user(), $this->type, $payload);
switch ($result->status) {
case FeedbackResult::SENT:
Audit::log('feedback.sent', ['type' => $this->type, 'reference' => $result->reference]);
$this->lastReference = $result->reference;
$this->reset(['subject', 'body', 'severity']);
Notification::make()->success()->title('Vielen Dank – Ihre Meldung ist eingegangen')->body("Referenznummer: {$result->reference}")->persistent()->send();
break;
case FeedbackResult::RETRY:
$this->reset(['subject', 'body', 'severity']);
$this->notice = 'Der Server ist gerade nicht erreichbar. Ihre Meldung ist gespeichert und wird automatisch gesendet, sobald es wieder geht. Die Referenznummer erscheint dann unten in der Liste.';
break;
case FeedbackResult::INVALID:
// Fehler direkt am betroffenen Feld anzeigen (API-Feld „title“ = Formularfeld „subject“).
foreach ($result->errors as $field => $message) {
$field = $field === 'title' ? 'subject' : $field;
$this->addError(in_array($field, ['subject', 'body', 'email', 'name', 'severity'], true) ? $field : 'body', $message);
}
if ($result->errors === []) {
$this->addError('body', $result->message ?? 'Die Eingabe ist unvollständig.');
}
break;
case FeedbackResult::RATE_LIMITED:
$minutes = $result->retryAfter ? max(1, (int) ceil($result->retryAfter / 60)) : null;
$this->notice = 'Es wurden zu viele Meldungen in kurzer Zeit gesendet. Bitte versuchen Sie es '.($minutes ? "in etwa {$minutes} Minute(n)" : 'später').' noch einmal – Ihre Eingabe bleibt erhalten.';
break;
case FeedbackResult::DISABLED:
$channels->disable($this->type);
$this->notice = 'Dieser Meldeweg steht nicht mehr zur Verfügung. Ihre Eingabe bleibt erhalten'.(count($channels->available()) ? ' – bitte wählen Sie eine andere Art der Meldung.' : '.');
$this->type = (string) array_key_first($channels->available());
break;
}
}
/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
return [
'types' => app(FeedbackChannels::class)->available(),
'technical' => app(TechnicalInfo::class)->collect(),
'hasLicense' => app(LicenseStore::class)->hasLicense(),
'history' => VendorFeedback::query()->where('user_id', auth()->id())->latest()->limit(20)->get(),
];
}
}