Baue die Verwaltung Kommunikation, die öffentliche Anfrageschnittstelle und das CMS-Widget Anfrage
Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und mehrstufiger Dialog aus derselben Beschreibung). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ee1fc9866
commit
c6a8167601
45 files changed
+5415
No files matched your search
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Communication\FormEvaluator;
|
||||
use App\Domain\Communication\FormPayload;
|
||||
use App\Domain\Communication\FormToken;
|
||||
use App\Domain\Communication\InquiryEntry;
|
||||
use App\Domain\Communication\InquiryService;
|
||||
use App\Domain\Communication\SubmissionException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Öffentliche Schnittstelle der Anfrage-Einstiege. Die Seite des CMS enthält nur die Kennung des Einstiegs; Formular,
|
||||
* Bedingungen und Annahme kommen von hier, damit eine zentrale Veröffentlichung sofort auf allen Seiten wirkt und keine
|
||||
* Formularstände in gespeicherten Seiten veralten.
|
||||
*/
|
||||
class InquiryFormController extends Controller
|
||||
{
|
||||
public function __construct(private readonly InquiryService $service, private readonly FormEvaluator $evaluator) {}
|
||||
|
||||
public function definition(InquiryEntry $entry): JsonResponse
|
||||
{
|
||||
$delivered = $this->service->deliver($entry);
|
||||
|
||||
if ($delivered === null) {
|
||||
return $this->json(['message' => 'Dieses Anfrageformular ist zurzeit nicht verfügbar.'], 404);
|
||||
}
|
||||
|
||||
return $this->json([
|
||||
...FormPayload::definition($delivered['form'], $this->evaluator),
|
||||
'token' => FormToken::issue($entry->id, $delivered['version']->id),
|
||||
'csrf' => csrf_token(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function state(Request $request, InquiryEntry $entry): JsonResponse
|
||||
{
|
||||
$delivered = $this->service->deliver($entry);
|
||||
|
||||
if ($delivered === null) {
|
||||
return $this->json(['message' => 'Dieses Anfrageformular ist zurzeit nicht verfügbar.'], 404);
|
||||
}
|
||||
|
||||
$values = $request->input('values');
|
||||
|
||||
if (! is_array($values) || strlen((string) json_encode($values)) > 40000) {
|
||||
return $this->json(['message' => 'Die Eingaben sind ungültig.'], 422);
|
||||
}
|
||||
|
||||
return $this->json(FormPayload::state($delivered['form'], $values, $this->evaluator));
|
||||
}
|
||||
|
||||
public function submit(Request $request, InquiryEntry $entry): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->service->submit($entry, [
|
||||
'token' => $request->input('token'),
|
||||
'values' => $request->input('values'),
|
||||
'website' => $request->input('website'),
|
||||
'source' => $request->input('source'),
|
||||
]);
|
||||
} catch (SubmissionException $e) {
|
||||
return $this->json(['message' => $e->getMessage(), 'fields' => (object) $e->fields], $e->getCode() ?: 422);
|
||||
}
|
||||
|
||||
return $this->json(['reference' => $result['reference']], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private function json(array $data, int $status = 200): JsonResponse
|
||||
{
|
||||
return response()->json($data, $status)->header('Cache-Control', 'no-store, private');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Communication\CommunicationAccess;
|
||||
use App\Domain\Communication\FormEvaluator;
|
||||
use App\Domain\Communication\FormFactory;
|
||||
use App\Domain\Communication\FormPayload;
|
||||
use App\Domain\Communication\InquiryEntry;
|
||||
use App\Domain\Communication\InquiryTemplate;
|
||||
use App\Domain\Communication\TemplateCompiler;
|
||||
use App\Domain\Communication\TemplateDraft;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Vorschau für die Verwaltung: das Formular, wie es ein Besucher sieht, aus dem gespeicherten Entwurf einer Vorlage oder
|
||||
* eines Einstiegs. Dieselbe Darstellung und dieselbe Auswertung wie öffentlich; gesendet wird nichts.
|
||||
*/
|
||||
class InquiryPreviewController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TemplateCompiler $compiler,
|
||||
private readonly FormFactory $factory,
|
||||
private readonly FormEvaluator $evaluator,
|
||||
) {}
|
||||
|
||||
public function template(Request $request, InquiryTemplate $template): View
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
|
||||
$mode = $request->query('modus') === 'wizard' ? 'wizard' : 'compact';
|
||||
$result = $this->compiler->compile(TemplateDraft::clean((array) $template->draft));
|
||||
|
||||
return view('communication.preview', [
|
||||
'title' => 'Vorschau: Vorlage „'.$template->name.'“',
|
||||
'note' => 'Entwurf der Vorlage mit allen angebotenen Anliegen. Es wird nichts gesendet.',
|
||||
'errors' => $result['errors'],
|
||||
'mode' => $mode,
|
||||
'switchUrl' => route('communication.preview.template', ['template' => $template, 'modus' => $mode === 'wizard' ? 'compact' : 'wizard']),
|
||||
'definitionUrl' => route('communication.preview.template.definition', ['template' => $template, 'modus' => $mode]),
|
||||
'stateUrl' => route('communication.preview.template.state', ['template' => $template, 'modus' => $mode]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function templateDefinition(Request $request, InquiryTemplate $template): JsonResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
|
||||
$form = $this->templateForm($request, $template);
|
||||
|
||||
return $form === null ? $this->unavailable() : $this->json([...FormPayload::definition($form, $this->evaluator), 'token' => 'vorschau', 'csrf' => csrf_token()]);
|
||||
}
|
||||
|
||||
public function templateState(Request $request, InquiryTemplate $template): JsonResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
|
||||
$form = $this->templateForm($request, $template);
|
||||
|
||||
return $form === null ? $this->unavailable() : $this->json(FormPayload::state($form, (array) $request->input('values', []), $this->evaluator));
|
||||
}
|
||||
|
||||
public function entry(InquiryEntry $entry): View
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
|
||||
$problem = $this->entryForm($entry) === null ? 'Die Anfragevorlage dieses Einstiegs hat noch keine gültige Fassung.' : null;
|
||||
|
||||
return view('communication.preview', [
|
||||
'title' => 'Vorschau: Einstieg „'.$entry->name.'“',
|
||||
'note' => 'Gespeicherter Entwurf des Einstiegs mit der gültigen Fassung der Vorlage. Es wird nichts gesendet.',
|
||||
'errors' => $problem === null ? [] : [$problem],
|
||||
'mode' => null,
|
||||
'switchUrl' => null,
|
||||
'definitionUrl' => route('communication.preview.entry.definition', $entry),
|
||||
'stateUrl' => route('communication.preview.entry.state', $entry),
|
||||
]);
|
||||
}
|
||||
|
||||
public function entryDefinition(InquiryEntry $entry): JsonResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
|
||||
$form = $this->entryForm($entry);
|
||||
|
||||
return $form === null ? $this->unavailable() : $this->json([...FormPayload::definition($form, $this->evaluator), 'token' => 'vorschau', 'csrf' => csrf_token()]);
|
||||
}
|
||||
|
||||
public function entryState(Request $request, InquiryEntry $entry): JsonResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
|
||||
$form = $this->entryForm($entry);
|
||||
|
||||
return $form === null ? $this->unavailable() : $this->json(FormPayload::state($form, (array) $request->input('values', []), $this->evaluator));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function templateForm(Request $request, InquiryTemplate $template): ?array
|
||||
{
|
||||
$result = $this->compiler->compile(TemplateDraft::clean((array) $template->draft));
|
||||
|
||||
if ($result['definition'] === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->factory->effective($result['definition'], ['mode' => $request->query('modus') === 'wizard' ? 'wizard' : 'compact']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function entryForm(InquiryEntry $entry): ?array
|
||||
{
|
||||
$version = $entry->template->publishedVersion;
|
||||
|
||||
return $version === null ? null : $this->factory->effective((array) $version->definition, (array) $entry->config);
|
||||
}
|
||||
|
||||
private function authorizeStaff(): void
|
||||
{
|
||||
abort_unless(CommunicationAccess::configure(auth('staff')->user()), 403);
|
||||
}
|
||||
|
||||
private function unavailable(): JsonResponse
|
||||
{
|
||||
return $this->json(['message' => 'Für diese Vorschau fehlt eine gültige Konfiguration.'], 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private function json(array $data, int $status = 200): JsonResponse
|
||||
{
|
||||
return response()->json($data, $status)->header('Cache-Control', 'no-store, private');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user