- users:manage/roles:manage auf allen User-/Rollen-Masken erzwungen; is_super_admin aus $fillable entfernt und nur per autorisiertem forceFill setzbar; zentraler Gate::before-Super-Admin-Kurzschluss (K1/M8). - Nicht-Super-Admins können Super-Admin-Konten nicht mehr bearbeiten (Fix#2); Impersonation mit Rangprüfung, keine Token-Erstellung während Impersonation (H1). - Destruktive/verwaltende Admin-Aktionen (CRM/Billing/Compliance/Struktur) hängen an neuen admin-only Permissions; Editor behält reine Content-Rechte (H2). - Kanonischer Permission-Katalog (App\Authorization\Permission) als Single Source of Truth für Seeder und Monitoring. Deployment: `php artisan db:seed --class=RolesAndPermissionsSeeder` auf allen Umgebungen ausführen (neue Permissions). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Authorization\Permission as PermissionCatalog;
|
|
use Illuminate\Database\Seeder;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class RolesAndPermissionsSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Seed the application's database.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$roles = [
|
|
'admin',
|
|
'editor',
|
|
'customer',
|
|
'api-only',
|
|
];
|
|
|
|
foreach ($roles as $role) {
|
|
Role::firstOrCreate(['name' => $role]);
|
|
}
|
|
|
|
// Kanonischer Permission-Katalog inkl. Rollen-Zuordnung: siehe
|
|
// App\Authorization\Permission. Schreibende CRM-/Verwaltungsrechte gehen
|
|
// nur an `admin` (Befund H2); der `editor` behält reine Content-Rechte.
|
|
$permissions = PermissionCatalog::all();
|
|
|
|
foreach ($permissions as $permission) {
|
|
Permission::firstOrCreate(['name' => $permission]);
|
|
}
|
|
|
|
Role::findByName('admin')->syncPermissions($permissions);
|
|
Role::findByName('editor')->syncPermissions(PermissionCatalog::editor());
|
|
Role::findByName('customer')->syncPermissions(PermissionCatalog::customer());
|
|
Role::findByName('api-only')->syncPermissions(PermissionCatalog::apiOnly());
|
|
}
|
|
}
|