Skip to content

A free open source IT asset/license management system

Fixed RB-21535 - use withTrashed for maintenances on Activity Report

snipebe5b74af9081
diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php
index 75274be6c6..bb155d0009 100644
--- a/app/Http/Controllers/Api/ReportsController.php
+++ b/app/Http/Controllers/Api/ReportsController.php
@@ -39,15 +39,15 @@ class ReportsController extends Controller
if ((! Gate::allows('activity.view')) && (($request->filled('target_type')) && ($request->filled('target_id'))) || (($request->filled('item_type')) && ($request->filled('item_id')))) {
if (($request->filled('target_type')) && ($request->filled('target_id'))) {
- $target = Helper::normalizeFullModelName(request()->input('target_type'));
- $target::find(request()->input('target_id'))?->withTrashed();
- $this->authorize('view', $target);
+ $targetClass = Helper::normalizeFullModelName(request()->input('target_type'));
+ $target = $targetClass::withTrashed()->find(request()->input('target_id'));
+ $this->authorize('view', $target ?? $targetClass);
}
if (($request->filled('item_type')) && ($request->filled('item_id'))) {
- $item = Helper::normalizeFullModelName(request()->input('item_type'));
- $item::find(request()->input('item_id'))?->withTrashed();
- $this->authorize('view', $item);
+ $itemClass = Helper::normalizeFullModelName(request()->input('item_type'));
+ $item = $itemClass::withTrashed()->find(request()->input('item_id'));
+ $this->authorize('view', $item ?? $itemClass);
}
} else {
diff --git a/app/Policies/MaintenancePolicy.php b/app/Policies/MaintenancePolicy.php
index ea608457cd..9436b1cdac 100644
--- a/app/Policies/MaintenancePolicy.php
+++ b/app/Policies/MaintenancePolicy.php
@@ -37,8 +37,12 @@ final class MaintenancePolicy
* Determine whether the user can view a specific maintenance record.
* Allowed if the user can edit the associated asset.
*/
- public function view(User $user, Maintenance $maintenance): bool
+ public function view(User $user, ?Maintenance $maintenance = null): bool
{
+ if (is_null($maintenance)) {
+ return $user->hasAccess('assets.view');
+ }
+
return Gate::allows('update', $maintenance->asset);
}