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())
|
return $query->where('efz', '<=', now()->subYears(5)->endOfYear())
|
||||||
->orWhereNull('efz');
|
->orWhereNull('efz');
|
||||||
})
|
})
|
||||||
|
->whereCurrentGroup()
|
||||||
->orderByRaw('lastname, firstname')
|
->orderByRaw('lastname, firstname')
|
||||||
->whereHas('memberships', fn ($builder) => $builder->isLeader());
|
->whereHas('memberships', fn ($builder) => $builder->isLeader());
|
||||||
}
|
}
|
||||||
|
|
|
@ -405,6 +405,21 @@ class Member extends Model
|
||||||
return $query;
|
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
|
public static function fromVcard(string $url, string $data): static
|
||||||
{
|
{
|
||||||
$settings = app(NamiSettings::class);
|
$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)->whereNull('more_ps_at'))
|
||||||
->orWhere(fn ($query) => $query->where('ps_at', '>=', $time)->where('more_ps_at', '<=', $time));
|
->orWhere(fn ($query) => $query->where('ps_at', '>=', $time)->where('more_ps_at', '<=', $time));
|
||||||
})
|
})
|
||||||
|
->whereCurrentGroup()
|
||||||
->orderByRaw('lastname, firstname')
|
->orderByRaw('lastname, firstname')
|
||||||
->whereHas('memberships', fn ($builder) => $builder->isLeader());
|
->whereHas('memberships', fn ($builder) => $builder->isLeader());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Setting;
|
namespace App\Setting;
|
||||||
|
|
||||||
|
use App\Group;
|
||||||
use Spatie\LaravelSettings\Settings;
|
use Spatie\LaravelSettings\Settings;
|
||||||
use Zoomyboy\LaravelNami\Api;
|
use Zoomyboy\LaravelNami\Api;
|
||||||
use Zoomyboy\LaravelNami\Nami;
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
|
@ -23,4 +24,9 @@ class NamiSettings extends Settings
|
||||||
{
|
{
|
||||||
return Nami::login($this->mglnr, $this->password);
|
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;
|
namespace Tests\Feature\Member;
|
||||||
|
|
||||||
|
use App\Group;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use App\Member\Membership;
|
use App\Member\Membership;
|
||||||
use App\Member\PsPendingBlock;
|
use App\Member\PsPendingBlock;
|
||||||
|
@ -14,37 +15,47 @@ class PsPendingBlockTest extends TestCase
|
||||||
|
|
||||||
public function testItRendersContent(): void
|
public function testItRendersContent(): void
|
||||||
{
|
{
|
||||||
|
$this->withoutExceptionHandling()->withNamiSettings(12345, 'password', 101);
|
||||||
|
$group = Group::factory()->inNami(101)->create();
|
||||||
|
|
||||||
$noPsAtAll = Member::factory()
|
$noPsAtAll = Member::factory()
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||||
->create(['firstname' => 'Jane', 'lastname' => 'Doe']);
|
->create(['firstname' => 'Jane', 'lastname' => 'Doe']);
|
||||||
$validPs = Member::factory()
|
$validPs = Member::factory()
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||||
->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)]);
|
->create(['firstname' => 'Max', 'lastname' => 'Doe', 'ps_at' => now()->subYears(4)]);
|
||||||
$validMorePs = Member::factory()
|
$validMorePs = Member::factory()
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||||
->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)]);
|
->create(['firstname' => 'Joe', 'lastname' => 'Doe', 'more_ps_at' => now()->subYears(4)]);
|
||||||
$invalidPs = Member::factory()
|
$invalidPs = Member::factory()
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||||
->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)]);
|
->create(['firstname' => 'Mike', 'lastname' => 'Doe', 'ps_at' => now()->subYears(5)]);
|
||||||
$invalidMorePs = Member::factory()
|
$invalidMorePs = Member::factory()
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||||
->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)]);
|
->create(['firstname' => 'Nora', 'lastname' => 'Doe', 'more_ps_at' => now()->subYears(5)]);
|
||||||
$invalidPsButValidMorePs = Member::factory()
|
$invalidPsButValidMorePs = Member::factory()
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
->has(Membership::factory()->in('€ LeiterIn', 5, 'Wölfling', 8))
|
||||||
->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)]);
|
->create(['firstname' => 'Hey', 'lastname' => 'Doe', 'ps_at' => now()->subYears(10), 'more_ps_at' => now()->subYears(3)]);
|
||||||
$notALeader = Member::factory()
|
$notALeader = Member::factory()
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->has(Membership::factory()->in('€ Mitglied', 5, 'Wölfling', 8))
|
->has(Membership::factory()->in('€ Mitglied', 5, 'Wölfling', 8))
|
||||||
->create(['firstname' => 'Mae', 'lastname' => 'Doe']);
|
->create(['firstname' => 'Mae', 'lastname' => 'Doe']);
|
||||||
|
|
||||||
|
@ -58,4 +69,21 @@ class PsPendingBlockTest extends TestCase
|
||||||
],
|
],
|
||||||
], $data);
|
], $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;
|
namespace Tests\Feature\Membership;
|
||||||
|
|
||||||
use App\Efz\EfzPendingBlock;
|
use App\Efz\EfzPendingBlock;
|
||||||
|
use App\Group;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use App\Member\Membership;
|
use App\Member\Membership;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
@ -14,30 +15,38 @@ class EfzPendingBlockTest extends TestCase
|
||||||
|
|
||||||
public function testItDisplaysEfzPending(): void
|
public function testItDisplaysEfzPending(): void
|
||||||
{
|
{
|
||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling()->withNamiSettings(12345, 'password', 101);
|
||||||
|
$group = Group::factory()->inNami(101)->create();
|
||||||
|
|
||||||
Member::factory()
|
Member::factory()
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->create(['firstname' => 'Max', 'lastname' => 'Muster', 'efz' => now()->subYear()]);
|
->create(['firstname' => 'Max', 'lastname' => 'Muster', 'efz' => now()->subYear()]);
|
||||||
Member::factory()
|
Member::factory()
|
||||||
->has(Membership::factory()->in('€ Mitglied', 1, 'Biber', 2))
|
->has(Membership::factory()->in('€ Mitglied', 1, 'Biber', 2))
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->create(['firstname' => 'Jane', 'lastname' => 'Muster', 'efz' => now()->subYear()]);
|
->create(['firstname' => 'Jane', 'lastname' => 'Muster', 'efz' => now()->subYear()]);
|
||||||
Member::factory()
|
Member::factory()
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->create(['firstname' => 'Mae', 'lastname' => 'Muster', 'efz' => now()->subYears(5)->startOfYear()]);
|
->create(['firstname' => 'Mae', 'lastname' => 'Muster', 'efz' => now()->subYears(5)->startOfYear()]);
|
||||||
Member::factory()
|
Member::factory()
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->create(['firstname' => 'Joe', 'lastname' => 'Muster', 'efz' => now()->subYears(5)->endOfYear()]);
|
->create(['firstname' => 'Joe', 'lastname' => 'Muster', 'efz' => now()->subYears(5)->endOfYear()]);
|
||||||
Member::factory()
|
Member::factory()
|
||||||
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
->has(Membership::factory()->in('€ LeiterIn', 1, 'Biber', 2))
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->create(['firstname' => 'Moa', 'lastname' => 'Muster', 'efz' => null]);
|
->create(['firstname' => 'Moa', 'lastname' => 'Muster', 'efz' => null]);
|
||||||
Member::factory()
|
Member::factory()
|
||||||
->has(Membership::factory()->in('€ Mitglied', 1, 'Biber', 2))
|
->has(Membership::factory()->in('€ Mitglied', 1, 'Biber', 2))
|
||||||
->defaults()
|
->defaults()
|
||||||
|
->for($group)
|
||||||
->create(['firstname' => 'Doe', 'lastname' => 'Muster', 'efz' => now()->subYears(5)]);
|
->create(['firstname' => 'Doe', 'lastname' => 'Muster', 'efz' => now()->subYears(5)]);
|
||||||
|
|
||||||
$data = app(EfzPendingBlock::class)->render()['data'];
|
$data = app(EfzPendingBlock::class)->render()['data'];
|
||||||
|
@ -46,4 +55,21 @@ class EfzPendingBlockTest extends TestCase
|
||||||
'members' => ['Joe Muster', 'Mae Muster', 'Moa Muster'],
|
'members' => ['Joe Muster', 'Mae Muster', 'Moa Muster'],
|
||||||
], $data);
|
], $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();
|
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);
|
Auth::success($mglnr, $password);
|
||||||
$this->withNamiSettings($mglnr, $password);
|
$this->withNamiSettings($mglnr, $password, $groupId);
|
||||||
Group::factory()->create(['nami_id' => 55]);
|
Group::factory()->create(['nami_id' => $groupId]);
|
||||||
|
|
||||||
return $this;
|
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([
|
NamiSettings::fake([
|
||||||
'mglnr' => $mglnr,
|
'mglnr' => $mglnr,
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'default_group_id' => 55,
|
'default_group_id' => $groupId,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
Loading…
Reference in New Issue