Rollen ausschließen: bei Inhalten (Zielgruppen) und für ganze Module
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m45s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m25s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m21s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m49s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m59s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m21s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m30s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m45s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m25s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m21s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m49s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m59s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m21s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m30s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
19193b850b
commit
1877a0922f
113 changed files with 699 additions and 428 deletions
|
|
@ -88,10 +88,10 @@ class AudienceTest extends TestCase
|
|||
public function test_audience_sync_replaces_rules(): void
|
||||
{
|
||||
Audiences::sync('event', 5, ['department' => ['Pflege', 'Pflege', ''], 'location' => ['Hamburg']]);
|
||||
$this->assertSame(['role' => [], 'department' => ['Pflege'], 'location' => ['Hamburg']], Audiences::get('event', 5));
|
||||
$this->assertSame(['role' => [], 'department' => ['Pflege'], 'location' => ['Hamburg'], 'exclude_role' => []], Audiences::get('event', 5));
|
||||
|
||||
Audiences::sync('event', 5, []);
|
||||
$this->assertSame(['role' => [], 'department' => [], 'location' => []], Audiences::get('event', 5));
|
||||
$this->assertSame(['role' => [], 'department' => [], 'location' => [], 'exclude_role' => []], Audiences::get('event', 5));
|
||||
$this->assertTrue(Audiences::allows('event', 5, null));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
71
tests/Feature/Permissions/ExcludedRolesTest.php
Normal file
71
tests/Feature/Permissions/ExcludedRolesTest.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Permissions;
|
||||
|
||||
use App\Filament\Pages\Plugins;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Plugins\PluginAccess;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExcludedRolesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_excluded_role_never_sees_the_object_even_if_another_rule_matches(): void
|
||||
{
|
||||
$clients = Role::query()->create(['name' => 'Klienten']);
|
||||
$client = User::factory()->withRoles([$clients])->create(['department' => 'Werkstatt']);
|
||||
$colleague = User::factory()->create(['department' => 'Werkstatt']);
|
||||
|
||||
$onlyExcluded = Event::factory()->create(['is_published' => true]);
|
||||
Audiences::sync('event', $onlyExcluded->id, ['exclude_role' => [$clients->id]]);
|
||||
$both = Event::factory()->create(['is_published' => true]);
|
||||
Audiences::sync('event', $both->id, ['department' => ['Werkstatt'], 'exclude_role' => [$clients->id]]);
|
||||
|
||||
foreach ([$onlyExcluded, $both] as $event) {
|
||||
$this->assertFalse(Audiences::allows('event', $event->id, $client));
|
||||
$this->assertTrue(Audiences::allows('event', $event->id, $colleague));
|
||||
$this->assertFalse(Audiences::matches(Audiences::get('event', $event->id), $client));
|
||||
}
|
||||
|
||||
$this->assertSame([], Event::query()->visibleTo($client)->pluck('id')->all());
|
||||
$this->assertEqualsCanonicalizing([$onlyExcluded->id, $both->id], Event::query()->visibleTo($colleague)->pluck('id')->all());
|
||||
}
|
||||
|
||||
public function test_excluded_role_loses_the_whole_module(): void
|
||||
{
|
||||
$clients = Role::query()->create(['name' => 'Klienten']);
|
||||
$client = User::factory()->withRoles([$clients])->create();
|
||||
$admin = User::factory()->admin()->create();
|
||||
NewsPost::factory()->create(['title' => 'Sommerfest intern']);
|
||||
app(PluginAccess::class)->exclude('news', [$clients->id]);
|
||||
|
||||
$this->actingAs($client)->get('/neuigkeiten')->assertForbidden();
|
||||
|
||||
$page = $this->actingAs($client)->get('/')->assertOk()->viewData('page');
|
||||
$this->assertNotContains('/neuigkeiten', array_column($page['props']['navigation'], 'href'));
|
||||
$this->assertSame([], array_filter(array_column($page['props']['widgets'], 'key'), fn ($key) => str_starts_with($key, 'news.')));
|
||||
$this->assertSame([], $this->actingAs($client)->getJson('/suche/live?q=sommerfest')->json('groups'));
|
||||
|
||||
// Verwaltung ist nie ausgeschlossen
|
||||
$this->actingAs($admin)->get('/neuigkeiten')->assertOk();
|
||||
}
|
||||
|
||||
public function test_admin_sets_module_access_on_the_plugins_page(): void
|
||||
{
|
||||
$clients = Role::query()->create(['name' => 'Klienten']);
|
||||
|
||||
Livewire::actingAs(User::factory()->admin()->create())
|
||||
->test(Plugins::class)
|
||||
->callAction('access', ['roles' => [(string) $clients->id]], ['slug' => 'events'])
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$this->assertSame([$clients->id], app(PluginAccess::class)->excludedRoles('events'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue