admin: Verlauf protokolliert jede versendete E-Mail

Neuer Listener RecordMailActivity am MessageSent-Event erfasst zentral
alle Versandwege (Mailables, Notifications, Fortify, Queue-Mails beim
realen Versand im Worker). Neuer ActivityType "E-Mail" mit Empfänger,
Betreff und Mailable-Klasse in den Metadaten; bekannte Empfänger werden
mit ihrem User verknüpft.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-07-21 09:13:43 +00:00
parent e59e1320a3
commit 33e84afa2a
6 changed files with 165 additions and 74 deletions

View file

@ -11,6 +11,7 @@ use App\Models\WithdrawalRequest;
use App\Services\PressRelease\PressReleaseService;
use Database\Seeders\RolesAndPermissionsSeeder;
use Illuminate\Auth\Events\Login;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Queue;
use Livewire\Volt\Volt;
@ -111,3 +112,30 @@ test('the activity report page lists events and filters by type', function () {
->assertSee('Kontaktanfrage „Testthema“')
->assertDontSee('hat sich angemeldet');
});
test('a sent mail is recorded and linked to the recipient user', function () {
$user = User::factory()->create(['email' => 'empfaenger@example.com']);
Mail::raw('Inhalt', function ($message) {
$message->to('empfaenger@example.com')->subject('Willkommen bei pressekonto');
});
$event = ActivityEvent::query()->where('type', ActivityType::MailSent->value)->sole();
expect($event->description)->toContain('Willkommen bei pressekonto')
->and($event->description)->toContain('empfaenger@example.com')
->and($event->user_id)->toBe($user->id)
->and($event->meta['to'])->toBe(['empfaenger@example.com'])
->and($event->meta['subject'])->toBe('Willkommen bei pressekonto');
});
test('a mail to an unknown address is recorded with the address as actor label', function () {
Mail::raw('Inhalt', function ($message) {
$message->to('extern@example.com')->subject('Externe Info');
});
$event = ActivityEvent::query()->where('type', ActivityType::MailSent->value)->sole();
expect($event->user_id)->toBeNull()
->and($event->actor_label)->toBe('extern@example.com');
});