Merge pull request #10139 from FliegenKLATSCH/patch-1

API: Do not include deleted items per default on lookup by serial
This commit is contained in:
snipe 2021-10-28 17:09:20 -07:00 committed by GitHub
commit 2f9e5f79af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -370,14 +370,20 @@ class AssetsController extends Controller
public function showBySerial(Request $request, $serial) public function showBySerial(Request $request, $serial)
{ {
$this->authorize('index', Asset::class); $this->authorize('index', Asset::class);
if ($assets = Asset::with('assetstatus')->with('assignedTo')
->withTrashed()->where('serial',$serial)->get()) { $assets = Asset::with('assetstatus')->with('assignedTo');
if ($request->input('deleted', 'false') === 'true') {
$assets = $assets->withTrashed();
}
$assets = $assets->where('serial', $serial)->get();
if ($assets) {
return (new AssetsTransformer)->transformAssets($assets, $assets->count()); return (new AssetsTransformer)->transformAssets($assets, $assets->count());
} } else {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200); return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
} }
}
/** /**
* Returns JSON with information about an asset for detail view. * Returns JSON with information about an asset for detail view.