Remove ps pending and efz block for foreign groups
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1ad411bad0
commit
afa29b416b
|
@ -17,6 +17,7 @@ class EfzPendingBlock extends Block
|
|||
return $query->where('efz', '<=', now()->subYears(5)->endOfYear())
|
||||
->orWhereNull('efz');
|
||||
})
|
||||
->whereCurrentGroup()
|
||||
->orderByRaw('lastname, firstname')
|
||||
->whereHas('memberships', fn ($builder) => $builder->isLeader());
|
||||
}
|
||||
|
|
|
@ -405,6 +405,21 @@ class Member extends Model
|
|||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWhereCurrentGroup(Builder $query): Builder
|
||||
{
|
||||
$group = app(NamiSettings::class)->localGroup();
|
||||
|
||||
if (!$group) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->where('group_id', $group->id);
|
||||
}
|
||||
|
||||
public static function fromVcard(string $url, string $data): static
|
||||
{
|
||||
$settings = app(NamiSettings::class);
|
||||
|
|
|
@ -21,6 +21,7 @@ class PsPendingBlock extends Block
|
|||
->orWhere(fn ($query) => $query->where('ps_at', '<=', $time)->whereNull('more_ps_at'))
|
||||
->orWhere(fn ($query) => $query->where('ps_at', '>=', $time)->where('more_ps_at', '<=', $time));
|
||||
})
|
||||
->whereCurrentGroup()
|
||||
->orderByRaw('lastname, firstname')
|
||||
->whereHas('memberships', fn ($builder) => $builder->isLeader());
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Setting;
|
||||
|
||||
use App\Group;
|
||||
use Spatie\LaravelSettings\Settings;
|
||||
use Zoomyboy\LaravelNami\Api;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
|
@ -23,4 +24,9 @@ class NamiSettings extends Settings
|
|||
{
|
||||
return Nami::login($this->mglnr, $this->password);
|
||||
}
|
||||
|
||||
public function localGroup(): ?Group
|
||||
{
|
||||
return Group::firstWhere('nami_id', $this->default_group_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\Feature\Member;
|
||||
|
||||
use App\Group;
|
||||
use App\Member\Member;
|
||||
use App\Member\Membership;
|
||||
use App\Member\PsPendingBlock;
|
||||
|
@ -14,37 +15,47 @@ class PsPendingBlockTest extends TestCase
|
|||
|
||||
public function testItRendersContent(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->withNamiSettings(12345, 'password', 101);
|
||||
$group = Group::factory()->inNami(101)->create();
|
||||
|
||||
$noPsAtAll = Member::factory()
|
||||
->defaults()
|
||||
->for($group)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->create(['firstname' => 'Jane', 'lastname' => 'Doe']);
|
||||
$validPs = Member::factory()
|
||||
->defaults()
|
||||
->for($group)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->create(['firstname' => 'Max', 'lastname' => 'Doe', 'ps_at' => now()->subYears(4)]);
|
||||
$validMorePs = Member::factory()
|
||||
->defaults()
|
||||
->for($group)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->create(['firstname' => 'Joe', 'lastname' => 'Doe', 'more_ps_at' => now()->subYears(4)]);
|
||||
$invalidPs = Member::factory()
|
||||
->defaults()
|
||||
->for($group)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->create(['firstname' => 'Mike', 'lastname' => 'Doe', 'ps_at' => now()->subYears(5)]);
|
||||
$invalidMorePs = Member::factory()
|
||||
->defaults()
|
||||
->for($group)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->create(['firstname' => 'Nora', 'lastname' => 'Doe', 'more_ps_at' => now()->subYears(5)]);
|
||||
$invalidPsButValidMorePs = Member::factory()
|
||||
->defaults()
|
||||
->for($group)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->create(['firstname' => 'Hey', 'lastname' => 'Doe', 'ps_at' => now()->subYears(10), 'more_ps_at' => now()->subYears(3)]);
|
||||
$notALeader = Member::factory()
|
||||
->defaults()
|
||||
->for($group)
|
||||
->has(Membership::factory()->in('€ Mitglied', 5, 'Wölfling', 8))
|
||||
->create(['firstname' => 'Mae', 'lastname' => 'Doe']);
|
||||
|
||||
|
@ -58,4 +69,21 @@ class PsPendingBlockTest extends TestCase
|
|||
],
|
||||
], $data);
|
||||
}
|
||||
|
||||
public function testItExcludesForeignGroups(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->withNamiSettings(12345, 'password', 101);
|
||||
Group::factory()->inNami(101)->create();
|
||||
$otherGroup = Group::factory()->inNami(55)->create();
|
||||
|
||||
Member::factory()
|
||||
->defaults()
|
||||
->for($otherGroup)
|
||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||
->create();
|
||||
|
||||
$data = app(PsPendingBlock::class)->render()['data'];
|
||||
|
||||
$this->assertCount(0, $data['members']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Tests\Feature\Membership;
|
||||
|
||||
use App\Efz\EfzPendingBlock;
|
||||
use App\Group;
|
||||
use App\Member\Member;
|
||||
use App\Member\Membership;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
@ -14,30 +15,38 @@ class EfzPendingBlockTest extends TestCase
|
|||
|
||||
public function testItDisplaysEfzPending(): void
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$this->withoutExceptionHandling()->withNamiSettings(12345, 'password', 101);
|
||||
$group = Group::factory()->inNami(101)->create();
|
||||
|
||||
Member::factory()
|
||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||
->defaults()
|
||||
->for($group)
|
||||
->create(['firstname' => 'Max', 'lastname' => 'Muster', 'efz' => now()->subYear()]);
|
||||
Member::factory()
|
||||
->has(Membership::factory()->in('€ Mitglied', 1, 'Biber', 2))
|
||||
->defaults()
|
||||
->for($group)
|
||||
->create(['firstname' => 'Jane', 'lastname' => 'Muster', 'efz' => now()->subYear()]);
|
||||
Member::factory()
|
||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||
->defaults()
|
||||
->for($group)
|
||||
->create(['firstname' => 'Mae', 'lastname' => 'Muster', 'efz' => now()->subYears(5)->startOfYear()]);
|
||||
Member::factory()
|
||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||
->defaults()
|
||||
->for($group)
|
||||
->create(['firstname' => 'Joe', 'lastname' => 'Muster', 'efz' => now()->subYears(5)->endOfYear()]);
|
||||
Member::factory()
|
||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||
->defaults()
|
||||
->for($group)
|
||||
->create(['firstname' => 'Moa', 'lastname' => 'Muster', 'efz' => null]);
|
||||
Member::factory()
|
||||
->has(Membership::factory()->in('€ Mitglied', 1, 'Biber', 2))
|
||||
->defaults()
|
||||
->for($group)
|
||||
->create(['firstname' => 'Doe', 'lastname' => 'Muster', 'efz' => now()->subYears(5)]);
|
||||
|
||||
$data = app(EfzPendingBlock::class)->render()['data'];
|
||||
|
@ -46,4 +55,21 @@ class EfzPendingBlockTest extends TestCase
|
|||
'members' => ['Joe Muster', 'Mae Muster', 'Moa Muster'],
|
||||
], $data);
|
||||
}
|
||||
|
||||
public function testItExcludesForeignGroups(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->withNamiSettings(12345, 'password', 101);
|
||||
Group::factory()->inNami(101)->create();
|
||||
$otherGroup = Group::factory()->inNami(55)->create();
|
||||
|
||||
Member::factory()
|
||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||
->defaults()
|
||||
->for($otherGroup)
|
||||
->create(['firstname' => 'Joe', 'lastname' => 'Muster', 'efz' => now()->subYears(5)->endOfYear()]);
|
||||
|
||||
$data = app(EfzPendingBlock::class)->render()['data'];
|
||||
|
||||
$this->assertCount(0, $data['members']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,21 +29,21 @@ abstract class TestCase extends BaseTestCase
|
|||
Auth::fake();
|
||||
}
|
||||
|
||||
public function loginNami(int $mglnr = 12345, string $password = 'password'): self
|
||||
public function loginNami(int $mglnr = 12345, string $password = 'password', int $groupId = 55): self
|
||||
{
|
||||
Auth::success($mglnr, $password);
|
||||
$this->withNamiSettings($mglnr, $password);
|
||||
Group::factory()->create(['nami_id' => 55]);
|
||||
$this->withNamiSettings($mglnr, $password, $groupId);
|
||||
Group::factory()->create(['nami_id' => $groupId]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withNamiSettings(int $mglnr = 12345, string $password = 'password'): self
|
||||
public function withNamiSettings(int $mglnr = 12345, string $password = 'password', int $groupId = 55): self
|
||||
{
|
||||
NamiSettings::fake([
|
||||
'mglnr' => $mglnr,
|
||||
'password' => $password,
|
||||
'default_group_id' => 55,
|
||||
'default_group_id' => $groupId,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
|
|
Loading…
Reference in New Issue