Reversed order of find

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2023-10-09 16:43:14 +01:00
parent e3591dc756
commit f685ba01b6
6 changed files with 11 additions and 6 deletions

View file

@ -146,7 +146,7 @@ class AccessoriesFilesController extends Controller
$this->authorize('view', $accessory); $this->authorize('view', $accessory);
$this->authorize('accessories.files', $accessory); $this->authorize('accessories.files', $accessory);
if (! $log = Actionlog::find($fileId)->whereNotNull('filename')->where('item_id', $accessory->id)->first()) { if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $accessory->id)->find($fileId)) {
return redirect()->route('accessories.index')->with('error', trans('admin/users/message.log_record_not_found')); return redirect()->route('accessories.index')->with('error', trans('admin/users/message.log_record_not_found'));
} }

View file

@ -86,7 +86,7 @@ class AssetFilesController extends Controller
if (isset($asset->id)) { if (isset($asset->id)) {
$this->authorize('view', $asset); $this->authorize('view', $asset);
if (! $log = Actionlog::find($fileId)->whereNotNull('filename')->where('item_id', $asset->id)->first()) { if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $asset->id)->find($fileId)) {
return response('No matching record for that asset/file', 500) return response('No matching record for that asset/file', 500)
->header('Content-Type', 'text/plain'); ->header('Content-Type', 'text/plain');
} }

View file

@ -142,7 +142,7 @@ class ComponentsFilesController extends Controller
$this->authorize('view', $component); $this->authorize('view', $component);
$this->authorize('components.files', $component); $this->authorize('components.files', $component);
if (! $log = Actionlog::find($fileId)) { if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $component->id)->find($fileId)) {
return response('No matching record for that asset/file', 500) return response('No matching record for that asset/file', 500)
->header('Content-Type', 'text/plain'); ->header('Content-Type', 'text/plain');
} }

View file

@ -140,7 +140,7 @@ class ConsumablesFilesController extends Controller
$this->authorize('view', $consumable); $this->authorize('view', $consumable);
$this->authorize('consumables.files', $consumable); $this->authorize('consumables.files', $consumable);
if (! $log = Actionlog::find($fileId)->whereNotNull('filename')->where('item_id', $consumable->id)->first()) { if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $consumable->id)->find($fileId)) {
return response('No matching record for that asset/file', 500) return response('No matching record for that asset/file', 500)
->header('Content-Type', 'text/plain'); ->header('Content-Type', 'text/plain');
} }

View file

@ -137,7 +137,7 @@ class LicenseFilesController extends Controller
$this->authorize('view', $license); $this->authorize('view', $license);
$this->authorize('licenses.files', $license); $this->authorize('licenses.files', $license);
if (! $log = Actionlog::find($fileId)->whereNotNull('filename')->where('item_id', $license->id)->first()) { if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $license->id)->find($fileId)) {
return response('No matching record for that asset/file', 500) return response('No matching record for that asset/file', 500)
->header('Content-Type', 'text/plain'); ->header('Content-Type', 'text/plain');
} }

View file

@ -136,6 +136,11 @@ class UserFilesController extends Controller
*/ */
public function show($userId = null, $fileId = null) public function show($userId = null, $fileId = null)
{ {
if (empty($fileId)) {
return redirect()->route('users.show')->with('error', 'Invalid file request');
}
$user = User::find($userId); $user = User::find($userId);
// the license is valid // the license is valid
@ -143,7 +148,7 @@ class UserFilesController extends Controller
$this->authorize('view', $user); $this->authorize('view', $user);
if ($log = Actionlog::find($fileId)->whereNotNull('filename')->where('item_id', $user->id)->first()) { if ($log = Actionlog::whereNotNull('filename')->where('item_id', $user->id)->find($fileId)) {
// Display the file inline // Display the file inline
if (request('inline') == 'true') { if (request('inline') == 'true') {