FIX: Correción modulos y asignación de permisos
This commit is contained in:
parent
82b7a179f5
commit
27cbc965b5
@ -164,6 +164,38 @@ public function update(ModuleUpdateRequest $request, int $id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function destroy(int $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$module = Module::findOrFail($id);
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$module->delete();
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
return ApiResponse::OK->response([
|
||||||
|
'message' => 'Módulo eliminado exitosamente',
|
||||||
|
]);
|
||||||
|
} catch (ModelNotFoundException $e) {
|
||||||
|
return ApiResponse::NOT_FOUND->response([
|
||||||
|
'message' => 'Módulo no encontrado',
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Log::error('Error al eliminar módulo: ' . $e->getMessage(), [
|
||||||
|
'module_id' => $id,
|
||||||
|
'trace' => $e->getTraceAsString()
|
||||||
|
]);
|
||||||
|
|
||||||
|
return ApiResponse::INTERNAL_ERROR->response([
|
||||||
|
'message' => 'Error al eliminar el módulo',
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cambiar solo el status de un módulo
|
* Cambiar solo el status de un módulo
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -14,9 +14,10 @@ public function authorize(): bool
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'box_number' => ['required', 'string', 'max:100'],
|
'lot' => ['required', 'string'],
|
||||||
'starting_page' => ['required', 'max:255'],
|
'box_number' => ['required', 'string'],
|
||||||
'ending_page' => ['required', 'max:255'],
|
'starting_page' => ['required'],
|
||||||
|
'ending_page' => ['required'],
|
||||||
'module_id' => ['required', 'exists:modules,id'],
|
'module_id' => ['required', 'exists:modules,id'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
<?php namespace Database\Seeders;
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
||||||
*/
|
*/
|
||||||
@ -11,9 +14,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Roles y permisos
|
* Roles y permisos
|
||||||
*
|
*
|
||||||
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
||||||
*
|
*
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
class RoleSeeder extends Seeder
|
class RoleSeeder extends Seeder
|
||||||
@ -61,11 +64,151 @@ public function run(): void
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$activityIndex = $this->onIndex(
|
$activityIndex = $this->onIndex(
|
||||||
code: 'activities',
|
code: 'activities',
|
||||||
type: $pulse,
|
type: $pulse,
|
||||||
guardName: 'api'
|
guardName: 'api'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$modules = PermissionType::create([ // 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::create([ //Dispositivos
|
||||||
|
'name' => 'Dispositivos'
|
||||||
|
]);
|
||||||
|
|
||||||
|
[
|
||||||
|
$deviceIndex,
|
||||||
|
$deviceCreate,
|
||||||
|
$deviceEdit,
|
||||||
|
$deviceDestroy
|
||||||
|
] = $this->onCRUD('devices', $devices, 'api');
|
||||||
|
|
||||||
|
$inscriptions = PermissionType::create([ // 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::create([
|
||||||
|
'name' => 'Cancelaciones'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$cancellationCancel = $this->onPermission(
|
||||||
|
'cancellations.cancel',
|
||||||
|
'Cancelar constancia',
|
||||||
|
$cancellations,
|
||||||
|
'api'
|
||||||
|
);
|
||||||
|
|
||||||
|
$updates = PermissionType::create([
|
||||||
|
'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::create([
|
||||||
|
'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::create([
|
||||||
|
'name' => 'Paquetes'
|
||||||
|
]);
|
||||||
|
|
||||||
|
[
|
||||||
|
$packageIndex,
|
||||||
|
$packageCreate,
|
||||||
|
$packageEdit,
|
||||||
|
$packageDestroy
|
||||||
|
] = $this->onCRUD('packages', $packages, 'api');
|
||||||
|
|
||||||
|
$tags = PermissionType::create([
|
||||||
|
'name' => 'Etiquetas'
|
||||||
|
]);
|
||||||
|
|
||||||
|
[
|
||||||
|
$tagIndex,
|
||||||
|
$tagCreate,
|
||||||
|
$tagEdit,
|
||||||
|
$tagDestroy
|
||||||
|
] = $this->onCRUD('tags', $tags, 'api');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Desarrollador
|
// Desarrollador
|
||||||
Role::create([
|
Role::create([
|
||||||
'name' => 'developer',
|
'name' => 'developer',
|
||||||
@ -90,7 +233,100 @@ public function run(): void
|
|||||||
$roleEdit,
|
$roleEdit,
|
||||||
$roleDestroy,
|
$roleDestroy,
|
||||||
$systemPulse,
|
$systemPulse,
|
||||||
$activityIndex
|
$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::create([
|
||||||
|
'name' => 'encargado',
|
||||||
|
'description' => 'Encargado',
|
||||||
|
'guard_name' => 'api'
|
||||||
|
])->givePermissionTo(
|
||||||
|
$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
|
||||||
|
);
|
||||||
|
|
||||||
|
// Capturista
|
||||||
|
Role::create([
|
||||||
|
'name' => 'capturista',
|
||||||
|
'description' => 'Capturista',
|
||||||
|
'guard_name' => 'api'
|
||||||
|
])->givePermissionTo(
|
||||||
|
$userIndex,
|
||||||
|
$inscriptionVehicle, //Inscripcion de vehículos
|
||||||
|
$inscriptionSearch,
|
||||||
|
$inscriptionStolen,
|
||||||
|
$updateVehicleData, //Actualizaciones de vehículo
|
||||||
|
$updateVehicleUpdate,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Perito
|
||||||
|
Role::create([
|
||||||
|
'name' => 'perito',
|
||||||
|
'description' => 'Perito',
|
||||||
|
'guard_name' => 'api'
|
||||||
|
])->givePermissionTo(
|
||||||
|
$userIndex,
|
||||||
|
$inscriptionVehicle, //Inscripcion de vehículos
|
||||||
|
$inscriptionSearch,
|
||||||
|
$inscriptionStolen,
|
||||||
|
$updateVehicleData, //Actualizaciones de vehículo
|
||||||
|
$updateVehicleUpdate,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user