From e0050bc8447d2b3f63960efa263b9c9ca3d69f3f Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 26 May 2022 18:06:53 -0500 Subject: [PATCH 1/3] Don't let a license to be checked out to a non-existent target --- .../Api/LicenseSeatsController.php | 22 ++++---- index.html | 51 +------------------ 2 files changed, 14 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.php index 0dd1c1fbd..b587dae5a 100644 --- a/app/Http/Controllers/Api/LicenseSeatsController.php +++ b/app/Http/Controllers/Api/LicenseSeatsController.php @@ -116,16 +116,20 @@ class LicenseSeatsController extends Controller return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success'))); } + // the logging functions expect only one "target". if both asset and user are present in the request, + // we simply let assets take precedence over users... + if ($licenseSeat->isDirty('assigned_to')) { + $target = $is_checkin ? $oldUser : User::find($licenseSeat->assigned_to); + } + if ($licenseSeat->isDirty('asset_id')) { + $target = $is_checkin ? $oldAsset : Asset::find($licenseSeat->asset_id); + } + + if(is_null($target)){ + return response()->json(Helper::formatStandardApiResponse('error', null, 'Target not found')); + } + if ($licenseSeat->save()) { - // the logging functions expect only one "target". if both asset and user are present in the request, - // we simply let assets take precedence over users... - $changes = $licenseSeat->getChanges(); - if (array_key_exists('assigned_to', $changes)) { - $target = $is_checkin ? $oldUser : User::find($changes['assigned_to']); - } - if (array_key_exists('asset_id', $changes)) { - $target = $is_checkin ? $oldAsset : Asset::find($changes['asset_id']); - } if ($is_checkin) { $licenseSeat->logCheckin($target, $request->input('note')); diff --git a/index.html b/index.html index dbd1babcb..33cd6c415 100644 --- a/index.html +++ b/index.html @@ -1,50 +1 @@ - - - - - Snipe-IT Setup - - - - - - -
-
-
-

D'oh. If you're seeing this, your DocumentRoot is set incorrectly. It should be set to the public directory. -

-
-
- - - +{"status":"success","messages":"License updated successfully.","payload":{"id":12,"license_id":2,"assigned_to":null,"notes":null,"user_id":1,"created_at":"2022-05-25T23:04:30.000000Z","updated_at":"2022-05-26T22:07:16.000000Z","deleted_at":null,"asset_id":"1161"}} \ No newline at end of file From 72192257f2f7443d0c058c3df05cab950f9862d5 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 26 May 2022 18:18:13 -0500 Subject: [PATCH 2/3] Delete a test file --- index.html | 1 - 1 file changed, 1 deletion(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index 33cd6c415..000000000 --- a/index.html +++ /dev/null @@ -1 +0,0 @@ -{"status":"success","messages":"License updated successfully.","payload":{"id":12,"license_id":2,"assigned_to":null,"notes":null,"user_id":1,"created_at":"2022-05-25T23:04:30.000000Z","updated_at":"2022-05-26T22:07:16.000000Z","deleted_at":null,"asset_id":"1161"}} \ No newline at end of file From 37f9cca5ec25d6fe0de21fdd57e8dc5825e34c26 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 28 May 2022 08:11:13 -0500 Subject: [PATCH 3/3] Minor stylistic change --- app/Http/Controllers/Api/LicenseSeatsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.php index b587dae5a..4d0fe0994 100644 --- a/app/Http/Controllers/Api/LicenseSeatsController.php +++ b/app/Http/Controllers/Api/LicenseSeatsController.php @@ -125,7 +125,7 @@ class LicenseSeatsController extends Controller $target = $is_checkin ? $oldAsset : Asset::find($licenseSeat->asset_id); } - if(is_null($target)){ + if (is_null($target)){ return response()->json(Helper::formatStandardApiResponse('error', null, 'Target not found')); }