forgetCachedPermissions(); // Create permissions $permissions = [ 'settings.manage', 'proclamatori.manage', 'territori.manage', 'campagne.manage', 'registro.view', 'registro.export', 'territori.assign', 'territori.return', 'audit.view', 'audit.export', 'gruppo.gestisci', ]; foreach ($permissions as $permission) { Permission::firstOrCreate(['name' => $permission]); } // givePermissionTo() rather than syncPermissions(): sync *detaches* // anything not in these lists. This seeder can re-run against a // populated database (the deploy marker lives on a volume that may be // recreated), and syncing would silently revoke every permission an // administrator had granted through the UI. Granting is additive and // therefore safe to repeat. // // These lists are the baseline each role starts with, not a // continuously enforced contract. // Amministratore: all permissions $admin = Role::firstOrCreate(['name' => 'amministratore']); // Tutti tranne gruppo.gestisci, che è del solo sorvegliante: l'admin // gestisce i gruppi da settings.manage, non ne ha uno suo. $admin->givePermissionTo(array_values(array_diff($permissions, ['gruppo.gestisci']))); // Assistente: proclamatori, campagne, assign, return $assistente = Role::firstOrCreate(['name' => 'assistente']); $assistente->givePermissionTo([ 'proclamatori.manage', 'campagne.manage', 'territori.assign', 'territori.return', 'registro.view', ]); // Operatore: assign and return only $operatore = Role::firstOrCreate(['name' => 'operatore']); $operatore->givePermissionTo([ 'territori.assign', 'territori.return', ]); // Sorvegliante di gruppo: solo il proprio gruppo di servizio. Il ruolo // si dà creando un gruppo (Gruppi di servizio), mai dalla pagina Utenti. $sorvegliante = Role::firstOrCreate(['name' => 'sorvegliante']); $sorvegliante->givePermissionTo(['gruppo.gestisci']); } }