From fe2cfa0d385db4c094b59541aecfb2f65e8c9cb5 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 20 Nov 2023 15:28:44 +0000 Subject: [PATCH 1/2] Redirect if category is missing or invalid Signed-off-by: snipe --- .../Controllers/Consumables/ConsumableCheckoutController.php | 5 +++++ resources/lang/en/general.php | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php b/app/Http/Controllers/Consumables/ConsumableCheckoutController.php index 6585624d82..d1c3d22eb7 100644 --- a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php +++ b/app/Http/Controllers/Consumables/ConsumableCheckoutController.php @@ -34,6 +34,11 @@ class ConsumableCheckoutController extends Controller return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.checkout.unavailable')); } + // Make sure there is a valid category + if (!$consumable->category){ + return redirect()->route('consumables.index')->with('error', trans('general.invalid_item_category_single', ['type' => trans('general.consumable')])); + } + $this->authorize('checkout', $consumable); return view('consumables/checkout', compact('consumable')); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index f0eda87d08..2deb8cb55b 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -353,7 +353,8 @@ return [ 'synchronize' => 'Synchronize', 'sync_results' => 'Synchronization Results', 'license_serial' => 'Serial/Product Key', - 'invalid_category' => 'Invalid category', + 'invalid_category' => 'Invalid or missing category', + 'invalid_item_category_single' => 'Invalid or missing :type category. Please update the category of this :type to include a valid category before checking out.', 'dashboard_info' => 'This is your dashboard. There are many like it, but this one is yours.', '60_percent_warning' => '60% Complete (warning)', 'dashboard_empty' => 'It looks like you have not added anything yet, so we do not have anything awesome to display. Get started by adding some assets, accessories, consumables, or licenses now!', From 7c8860106666d3a1da508b658e38852d5fd3650e Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 20 Nov 2023 15:31:39 +0000 Subject: [PATCH 2/2] Grab the API Signed-off-by: snipe --- app/Http/Controllers/Api/ConsumablesController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index b9b48328f5..1f3a347fb5 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -266,6 +266,14 @@ class ConsumablesController extends Controller \Log::debug('No enough remaining'); } + // Make sure there is a valid category + if (!$consumable->category){ + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.invalid_item_category_single', ['type' => trans('general.consumable')]))); + + return redirect()->route('consumables.index')->with('error', trans('general.invalid_item_category_single', ['type' => trans('general.consumable')])); + } + + // Check if the user exists - @TODO: this should probably be handled via validation, not here?? if (!$user = User::find($request->input('assigned_to'))) { // Return error message