Add filter for member prevention
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2025-01-04 23:27:23 +01:00
parent a456cc1889
commit b1dcdeb579
5 changed files with 37 additions and 1 deletions

View File

@ -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');
}

View File

@ -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),

View File

@ -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'],

View File

@ -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(),
];
}

View File

@ -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();