Rollen, Rechte und Zielgruppen
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m30s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m28s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1m45s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 54s

- Rollen mit globalen Rechten und Rechten für einzelne Objekte (z. B. „Beiträge
  schreiben in Kategorie MAV-Info“); Rollen sind additiv, Zuweisungen merken
  sich ihre Herkunft (manuell oder später Identity-Provider-Gruppe)
- Systemrolle „Administration“ ersetzt users.is_admin (Migration übernimmt
  bestehende Administratoren); nicht löschbar, man kann sie sich nicht selbst entziehen
- Rechte je Person vorberechnet und gecacht, Versionszähler invalidiert bei Änderungen
- Gate-Anbindung: registrierte Rechte entscheidet das Rechtesystem, Objektregeln
  die Policies; Admin-Seiten und Plugin-Ressourcen hinter passenden Rechten
- Redaktion nach Kategorie: Schreiben und Veröffentlichen getrennt, Liste im
  Admin auf eigene Kategorien beschränkt, ohne Veröffentlichungsrecht bleibt
  ein Beitrag Entwurf
- Zielgruppen (Rolle/Abteilung/Standort) für Kategorien und Termine als
  indizierte SQL-Bedingung in Listen, Detailseiten, Kacheln und .ics-Export
- Admin: Rollen-Verwaltung, „Rechte prüfen“, Redaktion und Sichtbarkeit direkt
  an Kategorie bzw. Termin
- Kern-Ressourcen explizit registriert, damit nach Updates liegengebliebene
  alte Dateien nicht doppelt geladen werden
- docs/PLUGINS.md für Plugin-Entwicklung; Demo-Rolle „MAV“

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 07:18:37 +00:00
parent 28ef1e4a20
commit 9ddc35a62c
112 changed files with 2408 additions and 267 deletions

View file

@ -0,0 +1,75 @@
<?php
namespace App\Support\Permissions;
/**
* Vorberechnete Rechte einer Person (gecacht, siehe Permissions).
*/
final class PermissionSet
{
/**
* @param list<int> $roleIds
* @param array<string, true> $global Ability => true („*“ = alles)
* @param array<string, array<string, list<int>|true>> $objects Ability => Typ => IDs oder true (alle)
*/
public function __construct(
public readonly array $roleIds,
public readonly array $global,
public readonly array $objects,
) {}
public function isSuperuser(): bool
{
return isset($this->global['*']);
}
public function can(string $ability, ?string $resourceType = null, ?int $resourceId = null): bool
{
if ($this->isSuperuser() || isset($this->global[$ability])) {
return true;
}
if ($resourceType === null) {
return false;
}
$ids = $this->objects[$ability][$resourceType] ?? null;
return $ids === true || ($ids !== null && ($resourceId === null ? $ids !== [] : in_array($resourceId, $ids, true)));
}
/**
* IDs der Objekte, für die das Recht gilt – für Abfragen („nur meine Kategorien“).
*
* @return list<int>|true true = alle
*/
public function ids(string $ability, string $resourceType): array|true
{
if ($this->isSuperuser() || isset($this->global[$ability])) {
return true;
}
return $this->objects[$ability][$resourceType] ?? [];
}
public function hasAnyObjectGrant(): bool
{
return $this->objects !== [];
}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
return ['roleIds' => $this->roleIds, 'global' => $this->global, 'objects' => $this->objects];
}
/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): self
{
return new self($data['roleIds'], $data['global'], $data['objects']);
}
}