Compare commits
1 Commits
master
...
skip_remem
| Author | SHA1 | Date |
|---|---|---|
|
|
0724052313 |
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Lib;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Scout\Builder;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
|
|
@ -40,4 +41,20 @@ abstract class ScoutFilter extends Data
|
|||
{
|
||||
return static::factory()->withoutMagicalCreation()->from($post ?: []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, string> $filter
|
||||
* @param array<string, bool|null> $conditions
|
||||
* @return Collection<int, string>
|
||||
*/
|
||||
public function switches(Collection $filter, array $conditions): Collection
|
||||
{
|
||||
foreach ($conditions as $field => $value) {
|
||||
if ($value !== null) {
|
||||
$filter->push($field . ' = ' . ($value ? 'true' : 'false'));
|
||||
}
|
||||
}
|
||||
|
||||
return $filter;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ class FilterScope extends ScoutFilter
|
|||
public ?bool $hasBirthday = null,
|
||||
public ?bool $hasSvk = null,
|
||||
public ?bool $hasVk = null,
|
||||
public ?bool $skipYearlyPrevention = null,
|
||||
public ?bool $skipEventPrevention = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
|
@ -72,6 +74,7 @@ class FilterScope extends ScoutFilter
|
|||
$this->search = $this->search ?: '';
|
||||
|
||||
return Member::search($this->search, function ($engine, string $query, array $options) {
|
||||
/** @var Collection<int, string> */
|
||||
$filter = collect([]);
|
||||
|
||||
if ($this->hasFullAddress === true) {
|
||||
|
|
@ -86,12 +89,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'));
|
||||
}
|
||||
$filter = $this->switches($filter, [
|
||||
'skip_yearly_prevention' => $this->skipYearlyPrevention,
|
||||
'skip_event_prevention' => $this->skipEventPrevention,
|
||||
'has_vk' => $this->hasVk,
|
||||
'has_svk' => $this->hasSvk,
|
||||
]);
|
||||
if ($this->ausstand === true) {
|
||||
$filter->push('ausstand > 0');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ class Member extends Model implements Geolocatable, Preventable
|
|||
'nami_id' => 'integer',
|
||||
'has_svk' => 'boolean',
|
||||
'has_vk' => 'boolean',
|
||||
'skip_yearly_prevention' => 'boolean',
|
||||
'skip_event_prevention' => 'boolean',
|
||||
'multiply_pv' => 'boolean',
|
||||
'multiply_more_pv' => 'boolean',
|
||||
'is_leader' => 'boolean',
|
||||
|
|
@ -597,6 +599,8 @@ class Member extends Model implements Geolocatable, Preventable
|
|||
'group_name' => $this->group->inner_name ?: $this->group->name,
|
||||
'has_vk' => $this->has_vk,
|
||||
'has_svk' => $this->has_svk,
|
||||
'skip_yearly_prevention' => $this->skip_yearly_prevention,
|
||||
'skip_event_prevention' => $this->skip_event_prevention,
|
||||
'links' => [
|
||||
'show' => route('member.show', ['member' => $this], false),
|
||||
'edit' => route('member.edit', ['member' => $this], false),
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class YearlyRememberAction
|
|||
return;
|
||||
}
|
||||
|
||||
foreach ($settings->yearlyMemberFilter->getQuery()->get() as $member) {
|
||||
foreach ($settings->getYearlyMemberFilter()->getQuery()->get() as $member) {
|
||||
// @todo add this check to FilterScope
|
||||
if ($member->getMailRecipient() === null) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -53,4 +53,11 @@ class PreventionSettings extends LocalSettings
|
|||
'replyToMail' => $this->replyToMail,
|
||||
];
|
||||
}
|
||||
|
||||
public function getYearlyMemberFilter(): FilterScope
|
||||
{
|
||||
$this->yearlyMemberFilter->skipYearlyPrevention = false;
|
||||
|
||||
return $this->yearlyMemberFilter;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,10 +138,10 @@ return [
|
|||
'key' => env('MEILI_MASTER_KEY', null),
|
||||
'index-settings' => [
|
||||
Member::class => [
|
||||
'filterableAttributes' => ['address', 'birthday', 'ausstand', 'bill_kind', 'group_id', 'memberships', 'has_vk', 'has_svk', 'id'],
|
||||
'filterableAttributes' => ['address', 'birthday', 'ausstand', 'bill_kind', 'group_id', 'memberships', 'has_vk', 'has_svk', 'id', 'skip_yearly_prevention', 'skip_event_prevention'],
|
||||
'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'],
|
||||
'displayedAttributes' => ['age_group_icon', 'group_name', 'links', 'is_leader', 'lastname', 'firstname', 'fullname', 'address', 'ausstand', 'birthday', 'id', 'memberships', 'bill_kind', 'group_id', 'skip_yearly_prevention', 'skip_event_prevention', 'has_vk', 'has_svk'],
|
||||
'pagination' => [
|
||||
'maxTotalHits' => 1000000,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ class MemberFactory extends Factory
|
|||
'keepdata' => false,
|
||||
'has_svk' => $this->faker->boolean(),
|
||||
'has_vk' => $this->faker->boolean(),
|
||||
'skip_yearly_prevention' => false,
|
||||
'skip_event_prevention' => false,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->boolean('skip_yearly_prevention')->default(false);
|
||||
$table->boolean('skip_event_prevention')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->dropColumn('skip_yearly_prevention');
|
||||
$table->dropColumn('skip_event_prevention');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -248,6 +248,18 @@ it('notices a few weeks before', function ($date, bool $shouldSend) {
|
|||
[fn() => now()->subYears(5)->addWeeks(2)->subDay(), false],
|
||||
]);
|
||||
|
||||
it('skips members that are marked as skipped for yearly mail', function (bool $skip) {
|
||||
Mail::fake();
|
||||
createMember(['efz' => null, 'skip_yearly_prevention' => $skip]);
|
||||
|
||||
sleep(2);
|
||||
YearlyRememberAction::run();
|
||||
|
||||
$skip
|
||||
? Mail::assertNotSent(YearlyMail::class)
|
||||
: Mail::assertSent(YearlyMail::class);
|
||||
})->with([true, false]);
|
||||
|
||||
it('sets reply to mail', function () {
|
||||
Mail::fake();
|
||||
app(PreventionSettings::class)->fill(['replyToMail' => 'admin@example.com'])->save();
|
||||
|
|
|
|||
Loading…
Reference in New Issue