Loheide-eu-mitarbeiterplatt.../app/Support/Abilities.php
Friederich Loheide 9d8bdc08ce
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Failing after 19m38s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 24m17s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 9m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 6m4s
Frag das Portal (0.64.0)
Antworten mit Quellen aus Seiten, QM-Dokumenten, Glossar und Neuigkeiten –
nur aus Sichtbarem, über den KI-Assistenten (Anthropic, OpenAI, Ollama).
Wissensquellen als Registry für Plugins, Auswertung ohne Personenbezug.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 18:08:35 +00:00

117 lines
4.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Support;
/**
* Registry der Rechte (Abilities). Kern und Plugins melden hier an, welche
* Rechte es gibt – das Rollen-Formular und der Rechte-Prüfer bauen darauf auf.
*
* Globale Rechte gelten überall („Benutzer verwalten“). Objekt-Rechte gelten für
* einzelne Objekte eines Typs („Beiträge schreiben in Kategorie MAV-Info“).
*/
class Abilities
{
/** @var array<string, array{label: string, group: string, resource: string|null, portal: bool}> */
private array $abilities = [];
/** @var array<string, array{label: string, options: callable, descendants: callable|null}> */
private array $resourceTypes = [];
public function __construct()
{
$this->define('users.manage', 'Benutzer verwalten', 'System');
$this->define('roles.manage', 'Rollen und Rechte verwalten', 'System');
$this->define('identity.manage', 'Anmeldung (Microsoft Entra ID) einrichten', 'System');
$this->define('plugins.manage', 'Plugins verwalten und installieren', 'System');
$this->define('appearance.manage', 'Erscheinungsbild und Schnellzugriffe', 'System');
$this->define('updates.manage', 'Aktualisierungen, Lizenz und Systemzustand', 'System');
$this->define('mail.manage', 'E-Mail-Versand einrichten', 'System');
$this->define('ai.manage', 'KI-Assistent einrichten', 'System');
$this->define('ask.manage', '„Frag das Portal“ einschalten und auswerten', 'System');
$this->define('feedback.send', 'Rückmeldungen an den Hersteller senden', 'System');
$this->define('media.manage', 'Mediathek verwalten: ersetzen, löschen, aufräumen', 'Mediathek', portal: true);
}
/**
* @param bool $portal Recht wird vollständig im Portal ausgeübt (Redaktion) – öffnet nicht das Backend
*/
public function define(string $ability, string $label, string $group, ?string $resource = null, bool $portal = false): void
{
$this->abilities[$ability] = ['label' => $label, 'group' => $group, 'resource' => $resource, 'portal' => $portal];
}
/**
* Braucht dieses Recht das Backend (/admin)? Nur-Portal-Rechte und unbekannte
* (z. B. von deaktivierten Plugins) nicht.
*/
public function needsBackend(string $ability): bool
{
return isset($this->abilities[$ability]) && ! $this->abilities[$ability]['portal'];
}
public function isPortalOnly(string $ability): bool
{
return (bool) ($this->abilities[$ability]['portal'] ?? false);
}
/**
* Objekttyp, auf den sich Rechte beziehen können (z. B. „news_category“).
*
* Hierarchische Typen (z. B. Seiten) geben $descendants an: Rechte mit
* „inkl. Unterobjekten“ gelten dann auch für alle Nachfahren.
*
* @param callable(): array<int|string, string> $options ID => Bezeichnung
* @param (callable(list<int>): list<int>)|null $descendants IDs => IDs aller Nachfahren
*/
public function resourceType(string $type, string $label, callable $options, ?callable $descendants = null): void
{
$this->resourceTypes[$type] = ['label' => $label, 'options' => $options, 'descendants' => $descendants];
}
public function isHierarchical(?string $type): bool
{
return $type !== null && isset($this->resourceTypes[$type]['descendants']);
}
/**
* @return array<string, array{label: string, group: string, resource: string|null}>
*/
public function all(): array
{
return $this->abilities;
}
/**
* @return array<string, array{label: string, group: string, resource: string|null}>
*/
public function global(): array
{
return array_filter($this->abilities, fn (array $a) => $a['resource'] === null);
}
/**
* @return array<string, array{label: string, group: string, resource: string|null}>
*/
public function forResource(string $type): array
{
return array_filter($this->abilities, fn (array $a) => $a['resource'] === $type);
}
/**
* @return array<string, array{label: string, options: callable, descendants: callable|null}>
*/
public function resourceTypes(): array
{
return $this->resourceTypes;
}
public function exists(string $ability): bool
{
return isset($this->abilities[$ability]);
}
public function label(string $ability): string
{
return $this->abilities[$ability]['label'] ?? $ability;
}
}