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

View File

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

View File

@ -29,7 +29,8 @@ class YearlyRememberAction
} }
$noticePreventions = $member->preventions($expireDate) $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) { if ($noticePreventions->count() === 0) {
continue; continue;
@ -45,7 +46,8 @@ class YearlyRememberAction
} }
$preventions = $member->preventions() $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) { if ($preventions->count() === 0) {
continue; continue;

View File

@ -3,6 +3,7 @@
namespace App\Prevention\Data; namespace App\Prevention\Data;
use App\Prevention\Enums\Prevention; use App\Prevention\Enums\Prevention;
use App\Prevention\PreventionSettings;
use Carbon\Carbon; use Carbon\Carbon;
use Spatie\LaravelData\Data; 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') . ')') 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)), '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 int $freshRememberInterval;
public bool $active; public bool $active;
public FilterScope $yearlyMemberFilter; public FilterScope $yearlyMemberFilter;
public array $preventAgainst;
public static function group(): string 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.freshRememberInterval', 12);
$this->migrator->add('prevention.active', false); $this->migrator->add('prevention.active', false);
$this->migrator->add('prevention.yearlyMemberFilter', FilterScope::from([])->toArray()); $this->migrator->add('prevention.yearlyMemberFilter', FilterScope::from([])->toArray());
$this->migrator->add('prevention.preventAgainst', []);
} }
}; };

View File

@ -21,6 +21,7 @@
</div> </div>
<f-editor v-if="active === 1" id="yearlymail" v-model="data.yearlymail" label="Jährliche Präventions-Erinnerung"></f-editor> <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-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> </div>
</form> </form>
</setting-layout> </setting-layout>
@ -38,7 +39,7 @@ const tabs = [
]; ];
const active = ref(0); 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); const loaded = ref(false);
async function load() { async function load() {

View File

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

View File

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