323 lines
8.7 KiB
PHP
323 lines
8.7 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');
|
|
|
|
$roles = PermissionType::firstOrCreate([
|
|
'name' => 'Roles'
|
|
]);
|
|
|
|
[
|
|
$roleIndex,
|
|
$roleCreate,
|
|
$roleEdit,
|
|
$roleDestroy
|
|
] = $this->onCRUD('roles', $roles, 'api');
|
|
$rolePermissions = $this->onPermission('roles.permissions', 'Permisos de roles', $roles, 'api');
|
|
|
|
$modules = PermissionType::firstOrCreate([ // Modulos
|
|
'name' => 'Módulos'
|
|
]);
|
|
|
|
[
|
|
$moduleIndex,
|
|
$moduleCreate,
|
|
$moduleEdit,
|
|
$moduleDestroy
|
|
] = $this->onCRUD('modules', $modules, 'api');
|
|
|
|
$moduleToggleStatus = $this->onPermission(
|
|
'modules.toggle_status',
|
|
'Cambiar estado del módulo',
|
|
$modules,
|
|
'api'
|
|
);
|
|
|
|
$devices = PermissionType::firstOrCreate([ //Dispositivos
|
|
'name' => 'Dispositivos Móviles'
|
|
]);
|
|
|
|
[
|
|
$deviceIndex,
|
|
$deviceCreate,
|
|
$deviceEdit,
|
|
$deviceDestroy
|
|
] = $this->onCRUD('devices', $devices, 'api');
|
|
|
|
$inscriptions = PermissionType::firstOrCreate([ // Inscripciones de vehículos
|
|
'name' => 'Proceso de Sustitución por primera vez'
|
|
]);
|
|
|
|
$inscriptionVehicle = $this->onPermission(
|
|
'inscription.vehicle',
|
|
'Inscribir vehículo',
|
|
$inscriptions,
|
|
'api'
|
|
);
|
|
|
|
$inscriptionSearch = $this->onPermission(
|
|
'inscription.search.national',
|
|
'Buscar en consulta nacional',
|
|
$inscriptions,
|
|
'api'
|
|
);
|
|
|
|
$inscriptionBusqueda = $this->onPermission(
|
|
'inscription.search',
|
|
'Buscar en consulta',
|
|
$inscriptions,
|
|
'api'
|
|
);
|
|
|
|
$cancellations = PermissionType::firstOrCreate([
|
|
'name' => 'Cancelaciones'
|
|
]);
|
|
|
|
|
|
$cancellationTagNoAsignado = $this->onPermission(
|
|
'cancellations.tag_no_asignado',
|
|
'Cancelar constancia no asignada',
|
|
$cancellations,
|
|
'api'
|
|
);
|
|
|
|
$updates = PermissionType::firstOrCreate([
|
|
'name' => 'Actualizar Registro'
|
|
]);
|
|
|
|
$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' => 'Generar Formatos'
|
|
]);
|
|
|
|
$recordGeneratePdf = $this->onPermission(
|
|
'records.generate_pdf',
|
|
'Generar Hoja de recepción',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$recordGeneratePdfVerification = $this->onPermission(
|
|
'records.generate_pdf_verification',
|
|
'Generar Hoja de verificación',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$recordGeneratePdfConstancia = $this->onPermission(
|
|
'records.generate_pdf_constancia',
|
|
'Generar Impresión en la constancia',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$recordGeneratePdfSubtitution = $this->onPermission(
|
|
'records.generate_pdf_substitution',
|
|
'Generar Solicitud de sustitución',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$recordGeneratePdfDamaged = $this->onPermission(
|
|
'records.generate_pdf_damaged',
|
|
'Generar PDF constancia dañada',
|
|
$records,
|
|
'api'
|
|
);
|
|
|
|
$packages = PermissionType::firstOrCreate([
|
|
'name' => 'Cajas'
|
|
]);
|
|
|
|
[
|
|
$packageIndex,
|
|
$packageCreate,
|
|
$packageEdit,
|
|
$packageDestroy
|
|
] = $this->onCRUD('packages', $packages, 'api');
|
|
|
|
$tags = PermissionType::firstOrCreate([
|
|
'name' => 'Constancias de Inscripción'
|
|
]);
|
|
|
|
[
|
|
$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,
|
|
$roleIndex,
|
|
$roleCreate,
|
|
$roleEdit,
|
|
$roleDestroy,
|
|
$rolePermissions,
|
|
$moduleIndex, //Módulos
|
|
$moduleCreate,
|
|
$moduleEdit,
|
|
$moduleDestroy,
|
|
$moduleToggleStatus,
|
|
$deviceIndex, //Dispositivos
|
|
$deviceCreate,
|
|
$deviceEdit,
|
|
$deviceDestroy,
|
|
$inscriptionVehicle, //Inscripcion de vehículos
|
|
$inscriptionSearch,
|
|
$inscriptionBusqueda,
|
|
$cancellationTagNoAsignado, //Cancelacion de constancia no asignada
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
$recordGeneratePdf, //Expedientes
|
|
$recordGeneratePdfVerification,
|
|
$recordGeneratePdfConstancia,
|
|
$recordGeneratePdfSubtitution,
|
|
$recordGeneratePdfDamaged,
|
|
$packageIndex, //Paquetes
|
|
$packageCreate,
|
|
$packageEdit,
|
|
$packageDestroy,
|
|
$tagIndex, //Etiquetas
|
|
$tagCreate,
|
|
$tagEdit,
|
|
$tagDestroy
|
|
|
|
);
|
|
|
|
// Encargado
|
|
Role::updateOrCreate([
|
|
'name' => 'encargado',
|
|
'description' => 'Encargado',
|
|
'guard_name' => 'api'
|
|
])->syncPermissions(
|
|
$userIndex,
|
|
$roleIndex,
|
|
|
|
$deviceIndex, //Dispositivos
|
|
$deviceCreate,
|
|
$deviceEdit,
|
|
$deviceDestroy,
|
|
$inscriptionVehicle, //Inscripcion de vehículos
|
|
$inscriptionSearch,
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
$recordGeneratePdf, //Expedientes
|
|
$recordGeneratePdfVerification,
|
|
$recordGeneratePdfConstancia,
|
|
$recordGeneratePdfSubtitution,
|
|
$recordGeneratePdfDamaged,
|
|
$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,
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
);
|
|
|
|
// Perito
|
|
Role::updateOrCreate([
|
|
'name' => 'perito',
|
|
'description' => 'Perito',
|
|
'guard_name' => 'api'
|
|
])->syncPermissions(
|
|
$userIndex,
|
|
$inscriptionVehicle, //Inscripcion de vehículos
|
|
$inscriptionSearch,
|
|
$updateVehicleData, //Actualizaciones de vehículo
|
|
$updateVehicleUpdate,
|
|
);
|
|
}
|
|
}
|