Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m38s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m7s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m24s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
||
|
||
namespace Inhaus\Plugins\Qm;
|
||
|
||
use App\Models\User;
|
||
use App\Support\Settings;
|
||
|
||
/**
|
||
* Wer das QM-Modul sehen und pflegen darf.
|
||
*
|
||
* - Sehen: alle angemeldeten Personen – außer Mitgliedern ausgeschlossener Rollen
|
||
* (z. B. Klient*innen). Ausschluss geht vor; wer QM pflegen darf, sieht es immer.
|
||
* - Pflegen: Recht „qm.manage“ (ohne Vergabe nur die Administration).
|
||
*/
|
||
class QmAccess
|
||
{
|
||
public const EXCLUDED_ROLES = 'qm.excluded_roles';
|
||
|
||
public function __construct(private readonly Settings $settings) {}
|
||
|
||
public function allows(?User $user): bool
|
||
{
|
||
if (! $user) {
|
||
return false;
|
||
}
|
||
|
||
if ($this->canManage($user)) {
|
||
return true;
|
||
}
|
||
|
||
$excluded = $this->excludedRoles();
|
||
|
||
return $excluded === [] || ! $user->roles()->whereIn('roles.id', $excluded)->exists();
|
||
}
|
||
|
||
/**
|
||
* @return list<int>
|
||
*/
|
||
public function excludedRoles(): array
|
||
{
|
||
return array_values(array_map('intval', (array) $this->settings->get(self::EXCLUDED_ROLES, [])));
|
||
}
|
||
|
||
public function canManage(?User $user): bool
|
||
{
|
||
return (bool) $user?->can('qm.manage');
|
||
}
|
||
}
|