E-Mail-Praeferenzen: Opt-out je Mail-Typ + One-Click-Unsubscribe ohne Login

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Kevin Adametz 2026-07-10 17:15:05 +00:00
parent 484e062264
commit d5b806443e
21 changed files with 746 additions and 9 deletions

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\Enums\EmailNotificationType;
use App\Enums\Portal;
use App\Enums\RegistrationType;
use App\Enums\Tier;
@ -367,6 +368,33 @@ class User extends Authenticatable implements MustVerifyEmail
return $this->hasMany(NewsletterSubscription::class);
}
public function emailNotificationOptOuts(): HasMany
{
return $this->hasMany(EmailNotificationOptOut::class);
}
/**
* Versand-Gate für Benachrichtigungs-Mails: Vor jedem Versand eines
* abbestellbaren Mail-Typs prüfen, ob der Empfänger ihn abbestellt hat
* (One-Click-Unsubscribe aus der Mail oder Präferenzen im Profil).
*/
public function wantsEmailNotification(EmailNotificationType $type): bool
{
return ! $this->emailNotificationOptOuts()
->where('type', $type->value)
->exists();
}
public function optOutOfEmailNotification(EmailNotificationType $type): void
{
$this->emailNotificationOptOuts()->firstOrCreate(['type' => $type->value]);
}
public function optIntoEmailNotification(EmailNotificationType $type): void
{
$this->emailNotificationOptOuts()->where('type', $type->value)->delete();
}
public function billingAddress(): HasOne
{
return $this->hasOne(BillingAddress::class);