340 lines
9.0 KiB
PHP
340 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
/**
|
|
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
|
*/
|
|
|
|
use App\Models\PermissionType;
|
|
use App\Models\Role;
|
|
use Illuminate\Database\Seeder;
|
|
use Notsoweb\LaravelCore\Traits\MySql\RolePermission;
|
|
use Spatie\Permission\Models\Permission;
|
|
|
|
/**
|
|
* Roles y permisos
|
|
*
|
|
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
class RoleSeeder extends Seeder
|
|
{
|
|
use RolePermission;
|
|
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$users = PermissionType::firstOrCreate([
|
|
'name' => 'Usuarios'
|
|
]);
|
|
|
|
[
|
|
$userIndex,
|
|
$userCreate,
|
|
$userEdit,
|
|
$userDestroy
|
|
] = $this->onCRUD('users', $users, 'api');
|
|
|
|
$userSettings = $this->onPermission('users.settings', 'Configuración de usuarios', $users, 'api');
|
|
$userOnline = $this->onPermission('users.online', 'Usuarios en linea', $users, 'api');
|
|
|
|
$roles = PermissionType::firstOrCreate([
|
|
'name' => 'Roles'
|
|
]);
|
|
|
|
[
|
|
$roleIndex,
|
|
$roleCreate,
|
|
$roleEdit,
|
|
$roleDestroy
|
|
] = $this->onCRUD('roles', $roles, 'api');
|
|
|
|
$pulse = PermissionType::firstOrCreate([
|
|
'name' => 'Sistema'
|
|
]);
|
|
|
|
$systemPulse = $this->onPermission('pulse', 'Monitoreo de Pulse', $pulse, 'api');
|
|
|
|
$pulse = PermissionType::firstOrCreate([
|
|
'name' => 'Historial de actividades'
|
|
]);
|
|
|
|
$activityIndex = $this->onIndex(
|
|
code: 'activities',
|
|
type: $pulse,
|
|
guardName: 'api'
|
|
);
|
|
|
|
|
|
$modules = PermissionType::firstOrCreate([ // Modulos
|
|
'name' => 'Módulos'
|
|
]);
|
|
|
|
[
|
|
$moduleIndex,
|
|
$moduleCreate,
|
|
$moduleEdit,
|
|
$moduleDestroy
|
|
] = $this->onCRUD('module', $modules, 'api');
|
|
|
|
$moduleToggleStatus = $this->onPermission(
|
|
'module.toggle-status',
|
|
'Cambiar estado del módulo',
|
|
$modules,
|
|
'api'
|
|
);
|
|
|
|
$devices = PermissionType::firstOrCreate([ //Dispositivos
|
|
'name' => 'Dispositivos'
|
|
]);
|
|
|
|
[
|
|
$deviceIndex,
|
|
$deviceCreate,
|
|
$deviceEdit,
|
|
$deviceDestroy
|
|
] = $this->onCRUD('devices', $devices, 'api');
|
|
|
|
$inscriptions = PermissionType::firstOrCreate([ // Inscripciones de vehículos
|
|
'name' => 'Inscripciones'
|
|
]);
|
|
|
|
$inscriptionVehicle = $this->onPermission(
|
|
'inscription.vehicle',
|
|
'Inscribir vehículo',
|
|
$inscriptions,
|
|
'api'
|
|
);
|
|
|
|
$inscriptionSearch = $this->onPermission(
|
|
'inscription.search',
|
|
'Buscar registros',
|
|
$inscriptions,
|
|
'api'
|
|
);
|
|
|
|
$inscriptionStolen = $this->onPermission(
|
|
'inscription.stolen',
|
|
'Marcar como robado',
|
|
$inscriptions,
|
|
'api'
|
|
);
|
|
|
|
$cancellations = PermissionType::firstOrCreate([
|
|
'name' => 'Cancelaciones'
|
|
]);
|
|
|
|
$cancellationCancel = $this->onPermission(
|
|
'cancellations.cancel',
|
|
'Cancelar constancia',
|
|
$cancellations,
|
|
'api'
|
|
);
|
|
|
|
$updates = PermissionType::firstOrCreate([
|
|
'name' => 'Actualizaciones'
|
|
]);
|
|
|
|
$updateVehicleData = $this->onPermission(
|
|
'updates.vehicle-data',
|
|
'Consultar datos de vehículo',
|
|
$updates,
|
|
'api'
|
|
);
|
|
|
|
$updateVehicleUpdate = $this->onPermission(
|
|
'updates.vehicle-update',
|
|
'Actualizar datos de vehículo',
|
|
$updates,
|
|
'api'
|
|
);
|
|
|
|
$records = PermissionType::firstOrCreate([
|
|
'name' => 'Expedientes'
|
|
]);
|
|
|
|
$recordGeneratePdf = $this->onPermission(
|
|
'records.generate-pdf',
|
|
'Generar PDF de expediente',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$recordGeneratePdfVerification = $this->onPermission(
|
|
'records.generate-pdf-verification',
|
|
'Generar PDF de verificación',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$recordGeneratePdfConstancia = $this->onPermission(
|
|
'records.generate-pdf-constancia',
|
|
'Generar PDF de constancia',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$recordGeneratePdfImages = $this->onPermission(
|
|
'records.generate-pdf-images',
|
|
'Generar PDF de imágenes',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$packages = PermissionType::firstOrCreate([
|
|
'name' => 'Paquetes'
|
|
]);
|
|
|
|
[
|
|
$packageIndex,
|
|
$packageCreate,
|
|
$packageEdit,
|
|
$packageDestroy
|
|
] = $this->onCRUD('packages', $packages, 'api');
|
|
|
|
$tags = PermissionType::firstOrCreate([
|
|
'name' => 'Etiquetas'
|
|
]);
|
|
|
|
[
|
|
$tagIndex,
|
|
$tagCreate,
|
|
$tagEdit,
|
|
$tagDestroy,
|
|
] = $this->onCRUD('tags', $tags, 'api');
|
|
|
|
$tagAssignToModule = $this->onPermission(
|
|
'tags.assign-to-module',
|
|
'Asignar etiquetas a módulo',
|
|
$tags,
|
|
'api'
|
|
);
|
|
|
|
|
|
// Desarrollador
|
|
Role::updateOrCreate([
|
|
'name' => 'developer',
|
|
'description' => 'Desarrollador',
|
|
'guard_name' => 'api'
|
|
])->syncPermissions(Permission::all());
|
|
|
|
// Administrador
|
|
Role::updateOrCreate([
|
|
'name' => 'admin',
|
|
'description' => 'Administrador',
|
|
'guard_name' => 'api'
|
|
])->syncPermissions(
|
|
$userIndex,
|
|
$userCreate,
|
|
$userEdit,
|
|
$userDestroy,
|
|
$userSettings,
|
|
$userOnline,
|
|
$roleIndex,
|
|
$roleCreate,
|
|
$roleEdit,
|
|
$roleDestroy,
|
|
$systemPulse,
|
|
$activityIndex,
|
|
|
|
$moduleIndex, //Módulos
|
|
$moduleCreate,
|
|
$moduleEdit,
|
|
$moduleDestroy,
|
|
$moduleToggleStatus,
|
|
$deviceIndex, //Dispositivos
|
|
$deviceCreate,
|
|
$deviceEdit,
|
|
$deviceDestroy,
|
|
$inscriptionVehicle, //Inscripcion de vehículos
|
|
$inscriptionSearch,
|
|
$inscriptionStolen,
|
|
$cancellationCancel, //Cancelacion de constancia
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
$recordGeneratePdf, //Expedientes
|
|
$recordGeneratePdfVerification,
|
|
$recordGeneratePdfConstancia,
|
|
$recordGeneratePdfImages,
|
|
$packageIndex, //Paquetes
|
|
$packageCreate,
|
|
$packageEdit,
|
|
$packageDestroy,
|
|
$tagIndex, //Etiquetas
|
|
$tagCreate,
|
|
$tagEdit,
|
|
$tagDestroy
|
|
|
|
);
|
|
|
|
// Encargado
|
|
Role::updateOrCreate([
|
|
'name' => 'encargado',
|
|
'description' => 'Encargado',
|
|
'guard_name' => 'api'
|
|
])->syncPermissions(
|
|
$userIndex,
|
|
$userOnline,
|
|
$roleIndex,
|
|
$systemPulse,
|
|
$activityIndex,
|
|
|
|
$deviceIndex, //Dispositivos
|
|
$deviceCreate,
|
|
$deviceEdit,
|
|
$deviceDestroy,
|
|
$inscriptionVehicle, //Inscripcion de vehículos
|
|
$inscriptionSearch,
|
|
$inscriptionStolen,
|
|
$cancellationCancel, //Cancelacion de constancia
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
$recordGeneratePdf, //Expedientes
|
|
$recordGeneratePdfVerification,
|
|
$recordGeneratePdfConstancia,
|
|
$recordGeneratePdfImages,
|
|
$packageIndex, //Paquetes
|
|
$packageCreate,
|
|
$packageEdit,
|
|
$packageDestroy,
|
|
$tagIndex, //Etiquetas
|
|
$tagCreate,
|
|
$tagEdit,
|
|
$tagDestroy,
|
|
$tagAssignToModule
|
|
);
|
|
|
|
// Capturista
|
|
Role::updateOrCreate([
|
|
'name' => 'capturista',
|
|
'description' => 'Capturista',
|
|
'guard_name' => 'api'
|
|
])->syncPermissions(
|
|
$userIndex,
|
|
$inscriptionVehicle, //Inscripcion de vehículos
|
|
$inscriptionSearch,
|
|
$inscriptionStolen,
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
);
|
|
|
|
// Perito
|
|
Role::updateOrCreate([
|
|
'name' => 'perito',
|
|
'description' => 'Perito',
|
|
'guard_name' => 'api'
|
|
])->syncPermissions(
|
|
$userIndex,
|
|
$inscriptionVehicle, //Inscripcion de vehículos
|
|
$inscriptionSearch,
|
|
$inscriptionStolen,
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
);
|
|
}
|
|
}
|