From de57d71bf12dc48bef933e6c64e23e8724996297 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Sep 2024 16:30:24 +0100 Subject: [PATCH 1/3] Fixed #15548 - unify audit due/overdue APIs Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 3 ++- routes/api.php | 9 +-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 241b0f7b0e8a..9cd05b49caad 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -154,7 +154,8 @@ public function index(Request $request, $action = null, $upcoming_status = null) * Handle due and overdue audits and checkin dates */ switch ($action) { - case 'audits': + // Audit (singular) is left over from earlier legacy APIs + case ('audit' || 'audits'): switch ($upcoming_status) { case 'due': diff --git a/routes/api.php b/routes/api.php index 108f2ac23186..8e3c02af0464 100644 --- a/routes/api.php +++ b/routes/api.php @@ -495,13 +495,6 @@ )->name('api.assets.show.byserial') ->where('any', '.*'); - // LEGACY URL - Get assets that are due or overdue for audit - Route::get('audit/{status}', - [ - Api\AssetsController::class, - 'index' - ] - )->name('api.asset.to-audit'); @@ -512,7 +505,7 @@ 'index' ] )->name('api.assets.list-upcoming') - ->where(['action' => 'audits|checkins', 'upcoming_status' => 'due|overdue|due-or-overdue']); + ->where(['action' => 'audit|audits|checkins', 'upcoming_status' => 'due|overdue|due-or-overdue']); From 5fb43dd159b1af02c82f2b3a3f3530c9ca6612ec Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Sep 2024 16:55:56 +0100 Subject: [PATCH 2/3] Handle `audit` *and* `audits` for urls Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 16 ++++++++++++++-- routes/api.php | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 9cd05b49caad..882126f665f6 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -56,6 +56,11 @@ class AssetsController extends Controller public function index(Request $request, $action = null, $upcoming_status = null) : JsonResponse | array { + + // This handles the legacy audit endpoints :( + if ($action == 'audit') { + $action = 'audits'; + } $filter_non_deprecable_assets = false; /** @@ -155,30 +160,37 @@ public function index(Request $request, $action = null, $upcoming_status = null) */ switch ($action) { // Audit (singular) is left over from earlier legacy APIs - case ('audit' || 'audits'): - + case 'audits' : + \Log::error('audit/audits'); switch ($upcoming_status) { case 'due': + \Log::error('due'); $assets->DueForAudit($settings); break; case 'overdue': + \Log::error('overdue'); $assets->OverdueForAudit(); break; case 'due-or-overdue': + \Log::error('due-or-overdue'); $assets->DueOrOverdueForAudit($settings); break; } break; case 'checkins': + \Log::error('checkins'); switch ($upcoming_status) { case 'due': + \Log::error('due'); $assets->DueForCheckin($settings); break; case 'overdue': + \Log::error('overdue'); $assets->OverdueForCheckin(); break; case 'due-or-overdue': + \Log::error('due-or-overdue'); $assets->DueOrOverdueForCheckin($settings); break; } diff --git a/routes/api.php b/routes/api.php index 8e3c02af0464..0581a046827d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -498,7 +498,7 @@ - // This gets the "due or overdue" API endpoints for audits and checkins + // This gets the "due or overdue" API endpoints for audit/audits and checkins Route::get('{action}/{upcoming_status}', [ Api\AssetsController::class, From 0ce5832b6cbed103433664fd9aa08cef2c1fd796 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Sep 2024 17:29:40 +0100 Subject: [PATCH 3/3] Removed debugging Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 882126f665f6..514f4484c8f0 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -161,36 +161,28 @@ public function index(Request $request, $action = null, $upcoming_status = null) switch ($action) { // Audit (singular) is left over from earlier legacy APIs case 'audits' : - \Log::error('audit/audits'); switch ($upcoming_status) { case 'due': - \Log::error('due'); $assets->DueForAudit($settings); break; case 'overdue': - \Log::error('overdue'); $assets->OverdueForAudit(); break; case 'due-or-overdue': - \Log::error('due-or-overdue'); $assets->DueOrOverdueForAudit($settings); break; } break; case 'checkins': - \Log::error('checkins'); switch ($upcoming_status) { case 'due': - \Log::error('due'); $assets->DueForCheckin($settings); break; case 'overdue': - \Log::error('overdue'); $assets->OverdueForCheckin(); break; case 'due-or-overdue': - \Log::error('due-or-overdue'); $assets->DueOrOverdueForCheckin($settings); break; }