Fix: Dont send yearly prevention mail when user has no email address
This commit is contained in:
parent
419b4227eb
commit
e97d39abd7
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
@ -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()));
|
||||
|
||||
|
|
|
@ -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([
|
||||
|
|
Loading…
Reference in New Issue