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
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:
parent
28ef1e4a20
commit
9ddc35a62c
112 changed files with 2408 additions and 267 deletions
18
app/Models/Audience.php
Normal file
18
app/Models/Audience.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Zielgruppen-Regel: Objekt X ist sichtbar für Rolle/Abteilung/Standort Y.
|
||||
* Objekte ohne Regel sind für alle sichtbar; mehrere Regeln verknüpft ODER.
|
||||
*/
|
||||
#[Fillable(['resource_type', 'resource_id', 'rule_type', 'rule_value'])]
|
||||
class Audience extends Model
|
||||
{
|
||||
public const TYPES = ['role' => 'Rolle', 'department' => 'Abteilung', 'location' => 'Standort'];
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
35
app/Models/Grant.php
Normal file
35
app/Models/Grant.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Support\Permissions\Permissions;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Ein Recht einer Rolle: global (resource_type = null) oder für ein Objekt
|
||||
* (resource_id = null bedeutet: alle Objekte dieses Typs).
|
||||
*/
|
||||
#[Fillable(['role_id', 'ability', 'resource_type', 'resource_id', 'include_children'])]
|
||||
class Grant extends Model
|
||||
{
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(fn () => Permissions::flush());
|
||||
static::deleted(fn () => Permissions::flush());
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['include_children' => 'boolean', 'resource_id' => 'integer'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Role, $this>
|
||||
*/
|
||||
public function role(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Role::class);
|
||||
}
|
||||
}
|
||||
70
app/Models/Role.php
Normal file
70
app/Models/Role.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Support\Permissions\Permissions;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Fillable(['name', 'slug', 'description', 'is_system'])]
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const ADMINISTRATION = 'administration';
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (Role $role) {
|
||||
$role->slug = $role->slug ?: Str::slug($role->name, language: 'de');
|
||||
});
|
||||
|
||||
static::saved(fn () => Permissions::flush());
|
||||
static::deleted(fn () => Permissions::flush());
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['is_system' => 'boolean'];
|
||||
}
|
||||
|
||||
public static function administration(): self
|
||||
{
|
||||
$role = static::query()->firstOrCreate(['slug' => self::ADMINISTRATION], [
|
||||
'name' => 'Administration',
|
||||
'description' => 'Voller Zugriff auf alle Bereiche und Einstellungen.',
|
||||
'is_system' => true,
|
||||
]);
|
||||
|
||||
if (! $role->grants()->where('ability', '*')->exists()) {
|
||||
$role->grants()->create(['ability' => '*']);
|
||||
}
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<User, $this>
|
||||
*/
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class)->withPivot('source', 'source_ref', 'created_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Grant, $this>
|
||||
*/
|
||||
public function grants(): HasMany
|
||||
{
|
||||
return $this->hasMany(Grant::class);
|
||||
}
|
||||
|
||||
public function isAdministration(): bool
|
||||
{
|
||||
return $this->slug === self::ADMINISTRATION;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Support\Avatars;
|
||||
use App\Support\Permissions\Permissions;
|
||||
use App\Support\Permissions\PermissionSet;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Models\Contracts\HasAvatar;
|
||||
|
|
@ -12,6 +14,7 @@ use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -19,7 +22,7 @@ use Illuminate\Support\Str;
|
|||
#[Fillable([
|
||||
'name', 'first_name', 'last_name', 'email', 'password',
|
||||
'job_title', 'department', 'location', 'phone', 'mobile', 'about',
|
||||
'is_admin', 'is_active', 'theme',
|
||||
'is_active', 'theme',
|
||||
])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable implements FilamentUser, HasAvatar
|
||||
|
|
@ -47,18 +50,68 @@ class User extends Authenticatable implements FilamentUser, HasAvatar
|
|||
'email_verified_at' => 'datetime',
|
||||
'last_login_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_admin' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Vorläufig: Zugriff auf das Admin-Backend über das Flag is_admin.
|
||||
* Wird in Phase 2 durch das Rollen- und Rechtesystem ersetzt.
|
||||
* Admin-Backend: für alle mit irgendeinem Recht (z. B. Redaktion einer
|
||||
* Kategorie). Was sie dort sehen, regeln die Policies der einzelnen Seiten.
|
||||
*/
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return $this->is_admin && $this->is_active;
|
||||
return $this->canAccessAdmin();
|
||||
}
|
||||
|
||||
public function canAccessAdmin(): bool
|
||||
{
|
||||
$permissions = $this->permissions();
|
||||
|
||||
return $this->is_active && ($permissions->global !== [] || $permissions->hasAnyObjectGrant());
|
||||
}
|
||||
|
||||
public function permissions(): PermissionSet
|
||||
{
|
||||
return app(Permissions::class)->for($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsToMany<Role, $this>
|
||||
*/
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class)->withPivot('source', 'source_ref', 'created_at');
|
||||
}
|
||||
|
||||
public function hasRole(string $slug): bool
|
||||
{
|
||||
return $this->roles()->where('slug', $slug)->exists();
|
||||
}
|
||||
|
||||
public function isAdministrator(): bool
|
||||
{
|
||||
return $this->permissions()->isSuperuser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manuell vergebene Rollen setzen. Rollen aus Identity-Provider-Gruppen
|
||||
* (Quelle „idp“) bleiben unberührt – Rollen sind additiv.
|
||||
*
|
||||
* @param list<int> $roleIds
|
||||
*/
|
||||
public function syncManualRoles(array $roleIds): void
|
||||
{
|
||||
$current = $this->roles()->wherePivot('source', 'manual')->pluck('roles.id')->all();
|
||||
|
||||
foreach (array_diff($current, $roleIds) as $roleId) {
|
||||
$this->roles()->wherePivot('source', 'manual')->detach($roleId);
|
||||
}
|
||||
|
||||
foreach (array_diff($roleIds, $current) as $roleId) {
|
||||
$this->roles()->attach($roleId, ['source' => 'manual', 'created_at' => now()]);
|
||||
}
|
||||
|
||||
Permissions::flush();
|
||||
}
|
||||
|
||||
public function getFilamentAvatarUrl(): ?string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue