diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index 58b1402df4..8cac1890f0 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -190,8 +190,13 @@ class AssetMaintenancesController extends Controller { $this->authorize('update', Asset::class); // Check if the asset maintenance exists + $assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId); + if (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) { + return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot delete a maintenance for that asset')); + } + $assetMaintenance->delete(); return response()->json(Helper::formatStandardApiResponse('success', $assetMaintenance, trans('admin/asset_maintenances/message.delete.success')));