Compare commits

...

2 Commits

Author SHA1 Message Date
philipp lang 80e9cb3881 Add filter for preventions to yearly mail
continuous-integration/drone/push Build is failing Details
2025-05-30 02:02:32 +02:00
philipp lang 57e0278bd2 Add preventAgainst to frontend 2025-05-30 01:46:46 +02:00
10 changed files with 53 additions and 4 deletions

View File

@ -2,6 +2,7 @@
namespace App\Prevention\Actions;
use App\Prevention\Enums\Prevention;
use App\Prevention\PreventionSettings;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\Concerns\AsAction;
@ -14,6 +15,9 @@ class SettingApiAction
{
return response()->json([
'data' => app(PreventionSettings::class)->toFrontend(),
'meta' => [
'preventAgainsts' => Prevention::values(),
]
]);
}
}

View File

@ -36,6 +36,7 @@ class SettingStoreAction
$settings->freshRememberInterval = $request->freshRememberInterval;
$settings->active = $request->active;
$settings->yearlyMemberFilter = FilterScope::from($request->yearlyMemberFilter);
$settings->preventAgainst = $request->preventAgainst;
$settings->save();
Succeeded::message('Einstellungen gespeichert.')->dispatch();

View File

@ -29,7 +29,8 @@ class YearlyRememberAction
}
$noticePreventions = $member->preventions($expireDate)
->filter(fn($prevention) => $prevention->expiresAt($expireDate));
->filter(fn($prevention) => $prevention->expiresAt($expireDate))
->filter(fn($p) => $p->appliesToSettings($settings));
if ($noticePreventions->count() === 0) {
continue;
@ -45,7 +46,8 @@ class YearlyRememberAction
}
$preventions = $member->preventions()
->filter(fn($prevention) => $prevention->expiresAt(now()));
->filter(fn($prevention) => $prevention->expiresAt(now()))
->filter(fn($p) => $p->appliesToSettings($settings));
if ($preventions->count() === 0) {
continue;

View File

@ -3,6 +3,7 @@
namespace App\Prevention\Data;
use App\Prevention\Enums\Prevention;
use App\Prevention\PreventionSettings;
use Carbon\Carbon;
use Spatie\LaravelData\Data;
@ -22,4 +23,9 @@ class PreventionData extends Data
fn($str) => $str->append(' (fällig am ' . $this->expires->format('d.m.Y') . ')')
);
}
public function appliesToSettings(PreventionSettings $settings): bool
{
return in_array($this->type->name, $settings->preventAgainst);
}
}

View File

@ -49,4 +49,15 @@ enum Prevention
'tooltip' => $case->tooltip($preventions->pluck('type')->doesntContain($case)),
]);
}
/**
* @return array<int, string>
*/
public static function values(): array
{
return collect(static::cases())->map(fn($case) => [
'id' => $case->name,
'name' => $case->text(),
])->toArray();
}
}

View File

@ -15,6 +15,7 @@ class PreventionSettings extends LocalSettings
public int $freshRememberInterval;
public bool $active;
public FilterScope $yearlyMemberFilter;
public array $preventAgainst;
public static function group(): string
{

View File

@ -12,5 +12,6 @@ return new class extends SettingsMigration
$this->migrator->add('prevention.freshRememberInterval', 12);
$this->migrator->add('prevention.active', false);
$this->migrator->add('prevention.yearlyMemberFilter', FilterScope::from([])->toArray());
$this->migrator->add('prevention.preventAgainst', []);
}
};

View File

@ -21,6 +21,7 @@
</div>
<f-editor v-if="active === 1" id="yearlymail" v-model="data.yearlymail" label="Jährliche Präventions-Erinnerung"></f-editor>
<f-member-filter id="yearly_member_filter" v-model="data.yearlyMemberFilter" label="nur für folgende Mitglieder erlauben" />
<f-multipleselect id="prevent_against" v-model="data.preventAgainst" :options="meta.preventAgainsts" label="An diese Dokumente erinnern" size="sm"></f-multipleselect>
</div>
</form>
</setting-layout>
@ -38,7 +39,7 @@ const tabs = [
];
const active = ref(0);
const { axios, data, reload } = useApiIndex('/api/prevention', 'prevention');
const { axios, data, meta, reload } = useApiIndex('/api/prevention', 'prevention');
const loaded = ref(false);
async function load() {

View File

@ -27,6 +27,10 @@ uses(DatabaseTransactions::class);
uses(CreatesFormFields::class);
uses(EndToEndTestCase::class);
beforeEach(function () {
app(PreventionSettings::class)->fill(['preventAgainst' => array_column(Prevention::values(), 'id')])->save();
});
function createForm(): Form
{
return Form::factory()->fields([
@ -284,6 +288,17 @@ it('testItDoesntRememberParticipantThatHasNoMail', function () {
Mail::assertNotSent(PreventionRememberMail::class);
});
it('doesnt remember when prevent against doesnt match', function () {
Mail::fake();
app(PreventionSettings::class)->fill(['preventAgainst' => []])->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 has no mail', function () {
Mail::fake();
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'email' => '', 'email_parents' => '']);

View File

@ -3,6 +3,7 @@
namespace Tests\Feature\Prevention;
use App\Member\FilterScope;
use App\Prevention\Enums\Prevention;
use App\Prevention\PreventionSettings;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\RequestFactories\EditorRequestFactory;
@ -27,6 +28,7 @@ it('receives settings', function () {
'weeks' => 9,
'freshRememberInterval' => 11,
'active' => true,
'preventAgainst' => [Prevention::MOREPS->name],
'yearlyMemberFilter' => FilterScope::from([
'memberships' => [['group_ids' => [33]]],
'search' => 'searchstring',
@ -40,7 +42,10 @@ it('receives settings', function () {
->assertJsonPath('data.active', true)
->assertJsonPath('data.freshRememberInterval', '11')
->assertJsonPath('data.yearlyMemberFilter.search', 'searchstring')
->assertJsonPath('data.yearlyMemberFilter.memberships.0.group_ids.0', 33);
->assertJsonPath('data.yearlyMemberFilter.memberships.0.group_ids.0', 33)
->assertJsonPath('data.preventAgainst', ['MOREPS'])
->assertJsonPath('meta.preventAgainsts.0.name', 'erweitertes Führungszeugnis')
->assertJsonPath('meta.preventAgainsts.0.id', 'EFZ');
});
it('testItStoresSettings', function () {
@ -52,6 +57,7 @@ it('testItStoresSettings', function () {
'weeks' => 9,
'freshRememberInterval' => 11,
'active' => true,
'preventAgainst' => ['EFZ'],
'yearlyMemberFilter' => [
'memberships' => [['group_ids' => 33]],
'search' => 'searchstring',
@ -64,4 +70,5 @@ it('testItStoresSettings', function () {
test()->assertTrue(app(PreventionSettings::class)->active);
test()->assertEquals([['group_ids' => 33]], app(PreventionSettings::class)->yearlyMemberFilter->memberships);
test()->assertEquals('searchstring', app(PreventionSettings::class)->yearlyMemberFilter->search);
test()->assertEquals('EFZ', app(PreventionSettings::class)->preventAgainst[0]);
});