Fix: Dont send yearly prevention mail when user has no email address

This commit is contained in:
philipp lang 2025-05-30 01:12:59 +02:00
parent 419b4227eb
commit e97d39abd7
3 changed files with 38 additions and 1 deletions

View File

@ -204,6 +204,10 @@ class Member extends Model implements Geolocatable, Preventable
return null;
}
if (!$this->email) {
return null;
}
return (object) ['name' => $this->fullname, 'email' => $this->email];
}

View File

@ -22,8 +22,12 @@ class YearlyRememberAction
$settings = app(PreventionSettings::class);
$expireDate = now()->addWeeks($settings->weeks);
foreach ($settings->yearlyMemberFilter->getQuery()->get() as $member) {
// @todo add this check to FilterScope
if ($member->getMailRecipient() === null) {
continue;
}
$noticePreventions = $member->preventions($expireDate)
->filter(fn($prevention) => $prevention->expiresAt($expireDate));
@ -35,6 +39,11 @@ class YearlyRememberAction
}
foreach ($settings->yearlyMemberFilter->getQuery()->get() as $member) {
// @todo add this check to FilterScope
if ($member->getMailRecipient() === null) {
continue;
}
$preventions = $member->preventions()
->filter(fn($prevention) => $prevention->expiresAt(now()));

View File

@ -10,6 +10,7 @@ use App\Form\Models\Form;
use App\Form\Models\Participant;
use App\Invoice\InvoiceSettings;
use App\Lib\Editor\Condition;
use App\Member\FilterScope;
use App\Prevention\Mails\PreventionRememberMail;
use App\Member\Member;
use App\Member\Membership;
@ -283,6 +284,29 @@ it('testItDoesntRememberParticipantThatHasNoMail', function () {
Mail::assertNotSent(PreventionRememberMail::class);
});
it('doesnt send yearly mail when member has no mail', function () {
Mail::fake();
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'email' => '', 'email_parents' => '']);
sleep(2);
YearlyRememberAction::run();
Mail::assertNotSent(YearlyMail::class);
});
it('doesnt send yearly mail when member doesnt match', function () {
Mail::fake();
app(PreventionSettings::class)->fill([
'yearlyMemberFilter' => FilterScope::from(['search' => 'Lorem Ipsum']),
])->save();
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'firstname' => 'Max', 'lastname' => 'Muster']);
sleep(2);
YearlyRememberAction::run();
Mail::assertNotSent(YearlyMail::class);
});
it('testItRendersSetttingMail', function () {
Mail::fake();
app(PreventionSettings::class)->fill([