Halte Seiten mit zurückgezogenem Einstieg speicherbar und berechne den Link der Benachrichtigung in der Web-Anfrage
CI Feature / test (push) In progress
CI Feature / test (push) In progress
Das Widget prüft nur noch, dass der Einstieg existiert; die Auswahl im Editor bietet weiter nur veröffentlichte an. Der Worker kennt keine Anfrage und APP_URL ist unzuverlässig, daher gibt die Web-Anfrage die Adresse der Anfrage in der Verwaltung an die Aufgabe weiter. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a495b0d740
commit
b9407c2f98
6 files changed
+39
-20
No files matched your search
@@ -74,11 +74,9 @@ public function dataFields(): array
|
||||
public function refRules(): array
|
||||
{
|
||||
return [
|
||||
'entry' => [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::exists('inquiry_entries', 'id')->where(fn ($query) => $query->whereNotNull('published_at')->whereNull('archived_at')),
|
||||
],
|
||||
// Nur die Existenz: Ein später zurückgezogener Einstieg darf eine Seite nicht unspeicherbar machen (Seiten bleiben
|
||||
// konsistent). Auswahl im Editor sind nur veröffentlichte Einstiege; öffentlich erscheint nichts, solange er es nicht ist.
|
||||
'entry' => ['required', 'integer', Rule::exists('inquiry_entries', 'id')],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public function submit(InquiryEntry $entry, array $payload): array
|
||||
|
||||
// Erst nach der Speicherung benachrichtigen. Ein Fehler hier verliert die Anfrage nie.
|
||||
try {
|
||||
SendInquiryNotification::dispatch($inquiry->id)->afterCommit();
|
||||
SendInquiryNotification::dispatch($inquiry->id, url('/verwaltung/anfragen/'.$inquiry->id))->afterCommit();
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
$inquiry->forceFill(['notification_error' => 'Die Benachrichtigung konnte nicht eingereiht werden: '.Str::limit($e->getMessage(), 300)])->save();
|
||||
|
||||
@@ -77,7 +77,7 @@ protected function getHeaderActions(): array
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Sendet die interne Benachrichtigung an die in den Einstellungen hinterlegten Empfänger noch einmal.')
|
||||
->action(function (): void {
|
||||
SendInquiryNotification::dispatchSync($this->getRecord()->id);
|
||||
SendInquiryNotification::dispatchSync($this->getRecord()->id, InquiryResource::getUrl('view', ['record' => $this->getRecord()]));
|
||||
$inquiry = $this->getRecord()->fresh();
|
||||
|
||||
if ($inquiry->notified_at !== null) {
|
||||
|
||||
@@ -21,7 +21,11 @@ class SendInquiryNotification implements ShouldQueue
|
||||
|
||||
public int $tries = 1;
|
||||
|
||||
public function __construct(public int $inquiryId) {}
|
||||
/**
|
||||
* @param ?string $adminUrl Adresse der Anfrage in der Verwaltung, während der Web-Anfrage berechnet: Im Worker
|
||||
* gibt es keine Anfrage, und APP_URL gilt in diesem Projekt nicht als verlässlich.
|
||||
*/
|
||||
public function __construct(public int $inquiryId, public ?string $adminUrl = null) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
@@ -40,7 +44,7 @@ public function handle(): void
|
||||
}
|
||||
|
||||
try {
|
||||
Mail::to($recipients)->send(new InquiryReceived($inquiry));
|
||||
Mail::to($recipients)->send(new InquiryReceived($inquiry, $this->adminUrl));
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
$inquiry->forceFill(['notification_error' => 'Der E-Mail-Versand ist fehlgeschlagen: '.Str::limit($e->getMessage(), 400)])->save();
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
class InquiryReceived extends Mailable
|
||||
{
|
||||
public function __construct(public Inquiry $inquiry) {}
|
||||
public function __construct(public Inquiry $inquiry, public ?string $adminUrl = null) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
@@ -28,7 +28,7 @@ public function content(): Content
|
||||
'reference' => $this->inquiry->reference,
|
||||
'issue' => $this->inquiry->issueTitle(),
|
||||
'received' => $this->inquiry->created_at?->timezone(config('app.timezone'))->format('d.m.Y H:i'),
|
||||
'url' => url('/verwaltung/anfragen/'.$this->inquiry->id),
|
||||
'url' => $this->adminUrl ?? url('/verwaltung/anfragen/'.$this->inquiry->id),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
use App\Domain\Communication\ExampleConfiguration;
|
||||
use App\Domain\Communication\Inquiry;
|
||||
use App\Domain\Communication\InquiryEntry;
|
||||
use App\Domain\Communication\InquiryTemplate;
|
||||
use App\Domain\Communication\Publisher;
|
||||
use App\Jobs\SendInquiryNotification;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
@@ -198,22 +199,38 @@ public function test_a_withdrawn_entry_leaves_the_page_valid_and_the_public_view
|
||||
$this->get('/partner')->assertOk()->assertDontSee('data-inquiry', false);
|
||||
}
|
||||
|
||||
public function test_the_page_editor_rejects_an_unpublished_entry_and_accepts_a_published_one(): void
|
||||
public function test_the_page_editor_rejects_an_unknown_entry_but_a_withdrawn_one_never_blocks_saving(): void
|
||||
{
|
||||
$page = Page::query()->create(['path' => '/neu']);
|
||||
$draft = new InquiryEntry(['key' => 'entwurf', 'name' => 'Entwurf', 'template_id' => InquiryTemplate::query()->first()->id, 'config' => InquiryEntry::emptyConfig()]);
|
||||
$draft->save();
|
||||
|
||||
$entry = $this->entry('kooperation');
|
||||
$page = $this->pageWith('/partner', $entry);
|
||||
$widget = fn (int $id): array => [['layout' => 'u4', 'slots' => [['type' => 'inquiry', 'v' => 1, 'variant' => 'standard', 'data' => [], 'refs' => ['entry' => $id]]]]];
|
||||
|
||||
try {
|
||||
app(PageService::class)->saveRevision($page, $widget($draft->id), null, null, null);
|
||||
$this->fail('Erwartet: unveröffentlichter Einstieg abgelehnt.');
|
||||
app(PageService::class)->saveRevision($page, $widget(999999), null, null, null);
|
||||
$this->fail('Erwartet: unbekannter Einstieg abgelehnt.');
|
||||
} catch (ValidationException $e) {
|
||||
$this->assertNotEmpty($e->errors());
|
||||
}
|
||||
|
||||
$this->assertNotNull(app(PageService::class)->saveRevision($page, $widget($this->entry('kooperation')->id), null, null, null));
|
||||
// Zurückgezogen oder archiviert: die Seite bleibt speicherbar (nur die Auswahl im Editor bietet ihn nicht mehr an).
|
||||
app(Publisher::class)->withdrawEntry($entry);
|
||||
$entry->forceFill(['archived_at' => now()])->save();
|
||||
|
||||
$this->assertNotNull(app(PageService::class)->saveRevision($page, $widget($entry->id), 'Anderer Titel', null, null));
|
||||
}
|
||||
|
||||
public function test_the_notification_link_is_built_from_the_web_request_not_inside_the_worker(): void
|
||||
{
|
||||
Queue::fake();
|
||||
$entry = $this->entry('allgemeiner_kontakt');
|
||||
$token = $this->getJson(route('inquiry.definition', $entry))->json('token');
|
||||
|
||||
$this->postJson('http://anfrage-test.example:3011/anfrage/'.$entry->id.'/senden', [
|
||||
'token' => $token,
|
||||
'values' => ['name' => 'Mira', 'email' => 'mira@example.org', 'nachricht' => 'Hallo'],
|
||||
])->assertCreated();
|
||||
|
||||
Queue::assertPushed(SendInquiryNotification::class, fn ($job): bool => str_starts_with((string) $job->adminUrl, 'http://anfrage-test.example:3011/verwaltung/anfragen/'));
|
||||
}
|
||||
|
||||
public function test_the_widget_offers_nothing_but_the_entry_choice_in_the_cms(): void
|
||||
|
||||
Reference in new issue
Block a user