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

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
@ -31,14 +32,21 @@ class UserFactory extends Factory
'department' => fake()->randomElement(['Verwaltung', 'Pflege', 'IT', 'Personal', 'Buchhaltung', 'Technik']),
'location' => fake()->city(),
'phone' => fake()->phoneNumber(),
'is_admin' => false,
'is_active' => true,
];
}
public function admin(): static
{
return $this->state(fn () => ['is_admin' => true]);
return $this->afterCreating(fn (User $user) => $user->roles()->attach(Role::administration()->id, ['source' => 'manual', 'created_at' => now()]));
}
/**
* @param list<int|Role> $roles
*/
public function withRoles(array $roles): static
{
return $this->afterCreating(fn (User $user) => $user->syncManualRoles(array_map(fn ($r) => $r instanceof Role ? $r->id : $r, $roles)));
}
public function inactive(): static

View file

@ -0,0 +1,101 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Rollen und Rechte (docs/PLAN.md, Abschnitt 7).
*
* roles – Rollen, z. B. „MAV“ oder „Redaktion Hamburg“
* role_user – Zuweisungen mit Herkunft: manuell oder über eine IdP-Gruppe (Phase 3)
* grants – Rechte einer Rolle, global (resource_type = null) oder für ein Objekt
* audiences – Zielgruppen: wer ein Objekt sehen darf (Rolle, Abteilung, Standort)
*
* Ersetzt das bisherige Feld users.is_admin durch die Systemrolle „Administration“.
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->string('slug', 100)->unique();
$table->string('description', 500)->nullable();
$table->boolean('is_system')->default(false);
$table->timestamps();
});
Schema::create('role_user', function (Blueprint $table) {
$table->id();
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('source', 20)->default('manual');
$table->string('source_ref', 191)->nullable();
$table->timestamp('created_at')->nullable();
$table->unique(['role_id', 'user_id', 'source', 'source_ref']);
$table->index(['user_id', 'role_id']);
});
Schema::create('grants', function (Blueprint $table) {
$table->id();
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
$table->string('ability', 100);
$table->string('resource_type', 50)->nullable();
$table->unsignedBigInteger('resource_id')->nullable();
$table->boolean('include_children')->default(false);
$table->timestamps();
$table->index(['resource_type', 'resource_id']);
$table->index(['role_id', 'ability']);
});
Schema::create('audiences', function (Blueprint $table) {
$table->id();
$table->string('resource_type', 50);
$table->unsignedBigInteger('resource_id');
$table->string('rule_type', 20);
$table->string('rule_value', 191);
$table->index(['resource_type', 'resource_id']);
$table->index(['rule_type', 'rule_value']);
});
$now = now();
$adminRole = DB::table('roles')->insertGetId([
'name' => 'Administration',
'slug' => 'administration',
'description' => 'Voller Zugriff auf alle Bereiche und Einstellungen.',
'is_system' => true,
'created_at' => $now,
'updated_at' => $now,
]);
DB::table('grants')->insert(['role_id' => $adminRole, 'ability' => '*', 'created_at' => $now, 'updated_at' => $now]);
DB::table('users')->where('is_admin', true)->pluck('id')->each(fn (int $userId) => DB::table('role_user')->insert([
'role_id' => $adminRole, 'user_id' => $userId, 'source' => 'manual', 'created_at' => $now,
]));
Schema::table('users', fn (Blueprint $table) => $table->dropColumn('is_admin'));
}
public function down(): void
{
Schema::table('users', fn (Blueprint $table) => $table->boolean('is_admin')->default(false));
$adminRole = DB::table('roles')->where('slug', 'administration')->value('id');
if ($adminRole) {
DB::table('users')->whereIn('id', DB::table('role_user')->where('role_id', $adminRole)->pluck('user_id'))->update(['is_admin' => true]);
}
Schema::dropIfExists('audiences');
Schema::dropIfExists('grants');
Schema::dropIfExists('role_user');
Schema::dropIfExists('roles');
}
};

View file

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\Role;
use App\Models\User;
use App\Support\Branding;
use Illuminate\Database\Seeder;
@ -24,7 +25,7 @@ class DemoContentSeeder extends Seeder
$authors = User::query()->inRandomOrder()->limit(5)->get();
$categories = collect([
'Unternehmen', 'Arbeit & Bildung', 'Menschen', 'Nachhaltigkeit', 'Freizeit & Kultur', 'Verwaltung',
'Unternehmen', 'Arbeit & Bildung', 'Menschen', 'Nachhaltigkeit', 'Freizeit & Kultur', 'Verwaltung', 'MAV-Info',
])->mapWithKeys(fn (string $name, int $i) => [$name => NewsCategory::query()->create([
'name' => $name,
'slug' => Str::slug($name, language: 'de'),
@ -59,6 +60,24 @@ class DemoContentSeeder extends Seeder
]);
}
// Beispiel für das Rechtesystem: Die MAV schreibt nur in „MAV-Info“.
$mav = Role::query()->create(['name' => 'MAV', 'description' => 'Mitarbeitervertretung – schreibt in „MAV-Info“.']);
$mav->grants()->create(['ability' => 'news.post.create', 'resource_type' => 'news_category', 'resource_id' => $categories['MAV-Info']->id]);
$mav->grants()->create(['ability' => 'news.post.publish', 'resource_type' => 'news_category', 'resource_id' => $categories['MAV-Info']->id]);
$mavMember = User::factory()->withRoles([$mav])->create([
'first_name' => 'Grete', 'last_name' => 'Hoffmann', 'email' => 'mav@example.com',
'job_title' => 'Vorsitzende der MAV', 'department' => 'Mitarbeitervertretung',
]);
NewsPost::query()->create([
'category_id' => $categories['MAV-Info']->id,
'author_id' => $mavMember->id,
'title' => 'MAV-Sprechstunde ab sofort jeden Dienstag',
'teaser' => 'Wir sind für Ihre Fragen da – persönlich oder per Videoanruf.',
'body' => $this->body('Wir sind für Ihre Fragen da – persönlich oder per Videoanruf.'),
'published_at' => now()->subHours(30),
]);
NewsPost::query()->create([
'category_id' => $categories['Unternehmen']->id,
'title' => 'Entwurf: Ausblick auf das zweite Halbjahr',