From b1dcdeb579ef02ee99b8dd3953025fc47d360ec0 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 4 Jan 2025 23:27:23 +0100 Subject: [PATCH] Add filter for member prevention --- app/Member/FilterScope.php | 8 +++++++ app/Member/Member.php | 2 ++ config/scout.php | 2 +- database/factories/Member/MemberFactory.php | 2 ++ tests/EndToEnd/MemberIndexTest.php | 24 +++++++++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Member/FilterScope.php b/app/Member/FilterScope.php index 5f1e03fb..24fdb73b 100644 --- a/app/Member/FilterScope.php +++ b/app/Member/FilterScope.php @@ -46,6 +46,8 @@ class FilterScope extends ScoutFilter public array $exclude = [], public ?bool $hasFullAddress = null, public ?bool $hasBirthday = null, + public ?bool $hasSvk = null, + public ?bool $hasVk = null, ) { } @@ -85,6 +87,12 @@ class FilterScope extends ScoutFilter if ($this->hasBirthday === true) { $filter->push('birthday IS NOT NULL'); } + if ($this->hasSvk !== null) { + $filter->push('has_svk = ' . ($this->hasSvk ? 'true' : 'false')); + } + if ($this->hasVk !== null) { + $filter->push('has_vk = ' . ($this->hasVk ? 'true' : 'false')); + } if ($this->ausstand === true) { $filter->push('ausstand > 0'); } diff --git a/app/Member/Member.php b/app/Member/Member.php index f92d0375..cfe280a3 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -544,6 +544,8 @@ class Member extends Model implements Geolocatable 'bill_kind' => $this->bill_kind?->value, 'group_id' => $this->group->id, 'group_name' => $this->group->inner_name ?: $this->group->name, + 'has_vk' => $this->has_vk, + 'has_svk' => $this->has_svk, 'links' => [ 'show' => route('member.show', ['member' => $this], false), 'edit' => route('member.edit', ['member' => $this], false), diff --git a/config/scout.php b/config/scout.php index d76b800e..85d135f3 100644 --- a/config/scout.php +++ b/config/scout.php @@ -138,7 +138,7 @@ return [ 'key' => env('MEILI_MASTER_KEY', null), 'index-settings' => [ Member::class => [ - 'filterableAttributes' => ['address', 'birthday', 'ausstand', 'bill_kind', 'group_id', 'memberships', 'id'], + 'filterableAttributes' => ['address', 'birthday', 'ausstand', 'bill_kind', 'group_id', 'memberships', 'has_vk', 'has_svk', 'id'], 'searchableAttributes' => ['fullname', 'address'], 'sortableAttributes' => ['lastname', 'firstname'], 'displayedAttributes' => ['age_group_icon', 'group_name', 'links', 'is_leader', 'lastname', 'firstname', 'fullname', 'address', 'ausstand', 'birthday', 'id', 'memberships', 'bill_kind', 'group_id'], diff --git a/database/factories/Member/MemberFactory.php b/database/factories/Member/MemberFactory.php index 059262cf..a5d06419 100644 --- a/database/factories/Member/MemberFactory.php +++ b/database/factories/Member/MemberFactory.php @@ -37,6 +37,8 @@ class MemberFactory extends Factory 'email' => $this->faker->safeEmail(), 'recertified_at' => null, 'keepdata' => false, + 'has_svk' => $this->faker->boolean(), + 'has_vk' => $this->faker->boolean(), ]; } diff --git a/tests/EndToEnd/MemberIndexTest.php b/tests/EndToEnd/MemberIndexTest.php index a790c111..b0cbf406 100644 --- a/tests/EndToEnd/MemberIndexTest.php +++ b/tests/EndToEnd/MemberIndexTest.php @@ -202,6 +202,30 @@ class MemberIndexTest extends EndToEndTestCase ]])->assertInertiaCount('data.data', 1); } + public function testItFiltersForSvkPrevention(): void + { + Member::factory()->defaults()->create(['has_svk' => true]); + Member::factory()->defaults()->create(['has_svk' => false]); + Member::factory()->defaults()->create(['has_svk' => false]); + + sleep(1); + $this->callFilter('member.index', ['has_svk' => true])->assertInertiaCount('data.data', 1); + $this->callFilter('member.index', ['has_svk' => false])->assertInertiaCount('data.data', 2); + $this->callFilter('member.index', ['has_svk' => null])->assertInertiaCount('data.data', 3); + } + + public function testItFiltersForVkPrevention(): void + { + Member::factory()->defaults()->create(['has_vk' => true]); + Member::factory()->defaults()->create(['has_vk' => false]); + Member::factory()->defaults()->create(['has_vk' => false]); + + sleep(1); + $this->callFilter('member.index', ['has_vk' => true])->assertInertiaCount('data.data', 1); + $this->callFilter('member.index', ['has_vk' => false])->assertInertiaCount('data.data', 2); + $this->callFilter('member.index', ['has_vk' => null])->assertInertiaCount('data.data', 3); + } + public function testGroupOfMembershipsFilterCanBeEmpty(): void { $mitglied = Activity::factory()->create();