Il gruppo ha un sorvegliante (proclamatore con utenza: email e password temporanea, senza conferma dell'email) e dei membri; l'amministratore mette in blocco dei territori nel pacchetto del gruppo. Il pacchetto non e' un'assegnazione e non tocca le statistiche; quando il sorvegliante da' un territorio a un membro nasce un'assegnazione normale con gruppo_servizio_id. Al rientro il territorio torna in reparto. Sciogliere il gruppo libera pacchetto e membri e disattiva l'utenza. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.6 KiB
PHP
74 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Spatie\Permission\Models\Role;
|
|
use Spatie\Permission\Models\Permission;
|
|
|
|
class RolesAndPermissionsSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
// Reset cached roles and permissions
|
|
app()[\Spatie\Permission\PermissionRegistrar::class]->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']);
|
|
}
|
|
}
|