Skip to content

A free open source IT asset/license management system

Fixed a 403 on componts-only view for “checked out”

snipe8d1d5c801d5b
diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php
index 6ee6317fbc..23154f5b54 100644
--- a/app/Http/Controllers/Api/ComponentsController.php
+++ b/app/Http/Controllers/Api/ComponentsController.php
@@ -21,6 +21,7 @@ use Illuminate\Database\Query\Builder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
@@ -342,7 +343,17 @@ class ComponentsController extends Controller
*/
public function getAssets(Component $component, Request $request): array
{
- $this->authorize('view', Asset::class);
+ // Backs the default "Assigned" tab on the component show
+ // page. Anyone who can view this specific component reaches
+ // that page, so gating on view Asset alone (which
+ // components-only viewers don't have) 403s the tab that
+ // opens by default and breaks the show page for scoped
+ // viewers. Accept either view on this component OR view on
+ // Asset. Asset viewers who hit this endpoint directly still
+ // work as they did before this widen. The BelongsToMany
+ // below still applies Asset's CompanyableScope so
+ // FMCS-scoped viewers see only assets in their own company.
+ abort_unless(Gate::allows('view', $component) || Gate::allows('view', Asset::class), 403);
$offset = request('offset', 0);
$limit = $request->input('limit', 50);