From 4cbb9c24096bf8e77494b5614499894ef99fc87b Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 15 Apr 2023 17:28:25 -0700 Subject: [PATCH] Use abs() instead of max Signed-off-by: snipe --- app/Http/Controllers/Api/AccessoriesController.php | 4 ++-- .../Api/AssetMaintenancesController.php | 4 ++-- app/Http/Controllers/Api/AssetModelsController.php | 4 ++-- app/Http/Controllers/Api/AssetsController.php | 4 ++-- app/Http/Controllers/Api/CategoriesController.php | 8 ++------ app/Http/Controllers/Api/CompaniesController.php | 5 +++-- app/Http/Controllers/Api/ComponentsController.php | 5 ++--- app/Http/Controllers/Api/ConsumablesController.php | 5 +++-- app/Http/Controllers/Api/DepartmentsController.php | 5 +++-- .../Controllers/Api/DepreciationsController.php | 5 +++-- app/Http/Controllers/Api/GroupsController.php | 4 ++-- .../Controllers/Api/LicenseSeatsController.php | 5 ++--- app/Http/Controllers/Api/LicensesController.php | 4 ++-- app/Http/Controllers/Api/LocationsController.php | 14 ++++++++++++-- .../Controllers/Api/ManufacturersController.php | 4 ++-- .../Controllers/Api/PredefinedKitsController.php | 4 ++-- app/Http/Controllers/Api/ReportsController.php | 5 +++-- .../Controllers/Api/StatuslabelsController.php | 4 ++-- app/Http/Controllers/Api/SuppliersController.php | 5 +++-- app/Http/Controllers/Api/UsersController.php | 5 +++-- 20 files changed, 57 insertions(+), 46 deletions(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index e87791e599..298723d07e 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -81,8 +81,8 @@ class AccessoriesController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $accessories->count()) ? $accessories->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $locations->count()) ? $locations->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort_override = $request->input('sort'); diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index ab2a59eaa1..3896d26d8d 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -56,8 +56,8 @@ class AssetMaintenancesController extends Controller // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $maintenances->count()) ? $maintenances->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $maintenances->count()) ? $maintenances->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $allowed_columns = [ 'id', diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 5275997443..39e7b3d13e 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -79,8 +79,8 @@ class AssetModelsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $assetmodels->count()) ? $assetmodels->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $assetmodels->count()) ? $assetmodels->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'models.created_at'; diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 4fd7577382..2754902944 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -200,8 +200,8 @@ class AssetsController extends Controller $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : ''; // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $assets->count()) ? $assets->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $assets->count()) ? $assets->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.php index d9ddbb4514..d00138ee3c 100644 --- a/app/Http/Controllers/Api/CategoriesController.php +++ b/app/Http/Controllers/Api/CategoriesController.php @@ -67,8 +67,6 @@ class CategoriesController extends Controller $categories = $categories->withCount('showableAssets as assets_count'); } - - if ($request->filled('search')) { $categories = $categories->TextSearch($request->input('search')); } @@ -93,11 +91,9 @@ class CategoriesController extends Controller $categories->where('checkin_email', '=', $request->input('checkin_email')); } - - // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $categories->count()) ? $categories->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $categories->count()) ? $categories->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'assets_count'; diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index c49d295830..efb4450291 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -49,8 +49,9 @@ class CompaniesController extends Controller // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $companies->count()) ? $companies->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $companies->count()) ? $companies->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php index b19f370d85..ddf412a442 100644 --- a/app/Http/Controllers/Api/ComponentsController.php +++ b/app/Http/Controllers/Api/ComponentsController.php @@ -73,10 +73,9 @@ class ComponentsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $components->count()) ? $components->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $components->count()) ? $components->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort_override = $request->input('sort'); $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at'; diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index 430502ac5f..a075fce566 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -85,8 +85,9 @@ class ConsumablesController extends Controller // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $consumables->count()) ? $consumables->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $consumables->count()) ? $consumables->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + $allowed_columns = ['id', 'name', 'order_number', 'min_amt', 'purchase_date', 'purchase_cost', 'company', 'category', 'model_number', 'item_no', 'manufacturer', 'location', 'qty', 'image']; $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php index 2226feb02c..e804aa42c4 100644 --- a/app/Http/Controllers/Api/DepartmentsController.php +++ b/app/Http/Controllers/Api/DepartmentsController.php @@ -59,8 +59,9 @@ class DepartmentsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $departments->count()) ? $departments->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $departments->count()) ? $departments->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index bf49c18cc4..90bf26ac42 100644 --- a/app/Http/Controllers/Api/DepreciationsController.php +++ b/app/Http/Controllers/Api/DepreciationsController.php @@ -29,8 +29,9 @@ class DepreciationsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $depreciations->count()) ? $depreciations->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $depreciations->count()) ? $depreciations->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/GroupsController.php b/app/Http/Controllers/Api/GroupsController.php index d1b18f6f3c..4a00a78c77 100644 --- a/app/Http/Controllers/Api/GroupsController.php +++ b/app/Http/Controllers/Api/GroupsController.php @@ -36,8 +36,8 @@ class GroupsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $groups->count()) ? $groups->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $groups->count()) ? $groups->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.php index 5ba530ab1c..0afc643377 100644 --- a/app/Http/Controllers/Api/LicenseSeatsController.php +++ b/app/Http/Controllers/Api/LicenseSeatsController.php @@ -41,9 +41,8 @@ class LicenseSeatsController extends Controller $total = $seats->count(); // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $seats->count()) ? $seats->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); - + $offset = ($request->input('offset') > $seats->count()) ? $seats->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $seats = $seats->skip($offset)->take($limit)->get(); diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 91792da7b8..9320aa27b2 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -95,8 +95,8 @@ class LicensesController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $licenses->count()) ? $licenses->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $licenses->count()) ? $licenses->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index cb9e232088..14e97a9848 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -79,12 +79,22 @@ class LocationsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $locations->count()) ? $locations->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $locations->count()) ? $locations->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; + \Log::debug('Max in env: '.config('app.max_results')); + \Log::debug('Original requested offset: '.$request->input('offset')); + \Log::debug('Intval offset: '.intval($request->input('offset'))); + \Log::debug('Modified offset: '.$offset); + \Log::debug('Original requested limit: '.$request->input('limit')); + \Log::debug('Intval limit: '.intval($request->input('limit'))); + \Log::debug('Modified limit: '.$limit); + \Log::debug('Total results: '.$locations->count()); + \Log::debug('------------------------------'); + switch ($request->input('sort')) { case 'parent': diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php index 6ae8d692cb..f0a02484ed 100644 --- a/app/Http/Controllers/Api/ManufacturersController.php +++ b/app/Http/Controllers/Api/ManufacturersController.php @@ -58,8 +58,8 @@ class ManufacturersController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $manufacturers->count()) ? $manufacturers->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $manufacturers->count()) ? $manufacturers->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/PredefinedKitsController.php b/app/Http/Controllers/Api/PredefinedKitsController.php index 08d9e15f1c..fc55de4d69 100644 --- a/app/Http/Controllers/Api/PredefinedKitsController.php +++ b/app/Http/Controllers/Api/PredefinedKitsController.php @@ -30,8 +30,8 @@ class PredefinedKitsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $kits->count()) ? $kits->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $kits->count()) ? $kits->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'desc' ? 'desc' : 'asc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'name'; diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php index eb88a58c72..18772b55ea 100644 --- a/app/Http/Controllers/Api/ReportsController.php +++ b/app/Http/Controllers/Api/ReportsController.php @@ -56,8 +56,9 @@ class ReportsController extends Controller // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $actionlogs->count()) ? $actionlogs->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $actionlogs->count()) ? $actionlogs->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $order = ($request->input('order') == 'asc') ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index e12b612f1e..d37204ac9d 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -51,8 +51,8 @@ class StatuslabelsController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $statuslabels->count()) ? $statuslabels->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $statuslabels->count()) ? $statuslabels->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/SuppliersController.php b/app/Http/Controllers/Api/SuppliersController.php index 7acd2b5179..0a1710d183 100644 --- a/app/Http/Controllers/Api/SuppliersController.php +++ b/app/Http/Controllers/Api/SuppliersController.php @@ -75,8 +75,9 @@ class SuppliersController extends Controller } // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $suppliers->count()) ? $suppliers->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $suppliers->count()) ? $suppliers->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index fc8518cd98..060858128b 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -194,8 +194,9 @@ class UsersController extends Controller $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; // Make sure the offset and limit are actually integers and do not exceed system limits - $offset = ($request->input('offset') > $users->count()) ? $users->count() : intval(request('offset')); - $limit = ($request->input('limit') > config('app.max_results')) ? config('app.max_results') : max(intval(request('offset')), config('app.max_results')); + $offset = ($request->input('offset') > $users->count()) ? $users->count() : abs($request->input('offset')); + $limit = (abs($request->input('limit')) > config('app.max_results')) ? config('app.max_results') : abs($request->input('limit')); + switch ($request->input('sort')) {