From 9d41cdb0103044986025dd1af7682ec749f78644 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 30 May 2025 19:13:38 +0200 Subject: [PATCH] Fix: Dont send yearly mail when yearly prevention is inactive --- app/Prevention/Actions/YearlyRememberAction.php | 4 ++++ tests/EndToEnd/Member/PreventionTest.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Prevention/Actions/YearlyRememberAction.php b/app/Prevention/Actions/YearlyRememberAction.php index df78546d..4f94fc80 100644 --- a/app/Prevention/Actions/YearlyRememberAction.php +++ b/app/Prevention/Actions/YearlyRememberAction.php @@ -22,6 +22,10 @@ class YearlyRememberAction $settings = app(PreventionSettings::class); $expireDate = now()->addWeeks($settings->weeks); + if (!$settings->active) { + return; + } + foreach ($settings->yearlyMemberFilter->getQuery()->get() as $member) { // @todo add this check to FilterScope if ($member->getMailRecipient() === null) { diff --git a/tests/EndToEnd/Member/PreventionTest.php b/tests/EndToEnd/Member/PreventionTest.php index 4c70aeb5..137b405d 100644 --- a/tests/EndToEnd/Member/PreventionTest.php +++ b/tests/EndToEnd/Member/PreventionTest.php @@ -28,7 +28,7 @@ uses(CreatesFormFields::class); uses(EndToEndTestCase::class); beforeEach(function () { - app(PreventionSettings::class)->fill(['preventAgainst' => array_column(Prevention::values(), 'id')])->save(); + app(PreventionSettings::class)->fill(['preventAgainst' => array_column(Prevention::values(), 'id'), 'active' => true])->save(); }); function createForm(): Form @@ -309,6 +309,17 @@ it('doesnt send yearly mail when member has no mail', function () { Mail::assertNotSent(YearlyMail::class); }); +it('doesnt send yearly mail when yearly sending is deactivated', function () { + Mail::fake(); + app(PreventionSettings::class)->fill(['active' => false])->save(); + createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true]); + + sleep(2); + YearlyRememberAction::run(); + + Mail::assertNotSent(YearlyMail::class); +}); + it('doesnt send yearly mail when member doesnt match', function () { Mail::fake(); app(PreventionSettings::class)->fill([