Skip to content

Commit 7f76198

Browse files
committed
Fixed RB-20501 - correctly return error response when license+seat don’t match
TypeError: App\Http\Transformers\LicenseSeatsTransformer::transformLicenseSeat(): Argument #1 ($seat) must be of type App\Models\LicenseSeat, bool given, called in /snipe-it/app/Http/Controllers/Api/LicenseSeatsController.php on line 92
1 parent 69994e0 commit 7f76198

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

app/Http/Controllers/Api/LicenseSeatsController.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,14 @@ public function show($licenseId, $seatId) : JsonResponse | array
7979
{
8080

8181
$this->authorize('view', License::class);
82-
// sanity checks:
83-
// 1. does the license seat exist?
84-
if (! $licenseSeat = LicenseSeat::find($seatId)) {
85-
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat not found'));
86-
}
87-
// 2. does the seat belong to the specified license?
88-
if (! $licenseSeat = $licenseSeat->license()->first() || $licenseSeat->id != intval($licenseId)) {
89-
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat does not belong to the specified license'));
82+
83+
if ($licenseSeat = LicenseSeat::where('id',$seatId)->where('license_id', $licenseId)->first()) {
84+
return (new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat);
9085
}
9186

92-
return (new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat);
87+
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat ID or license not found or the seat does not belong to this license'));
88+
89+
9390
}
9491

9592
/**

0 commit comments

Comments
 (0)