From d70b7dbf4194b98980768b4c67060f9aca33f258 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 28 Mar 2023 16:12:48 -0600 Subject: [PATCH 1/5] Checks if exist on API checkout --- app/Http/Controllers/Api/AssetsController.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 382990b57..b14a79bcf 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -826,12 +826,20 @@ class AssetsController extends Controller // This item is checked out to a location if (request('checkout_to_type') == 'location') { $target = Location::find(request('assigned_location')); + if (!$target) { + return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.error'))); + } + $asset->location_id = ($target) ? $target->id : ''; $error_payload['target_id'] = $request->input('assigned_location'); $error_payload['target_type'] = 'location'; } elseif (request('checkout_to_type') == 'asset') { $target = Asset::where('id', '!=', $asset_id)->find(request('assigned_asset')); + if (!$target) { + return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.error'))); + } + $asset->location_id = $target->rtd_location_id; // Override with the asset's location_id if it has one $asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : ''; @@ -841,6 +849,10 @@ class AssetsController extends Controller } elseif (request('checkout_to_type') == 'user') { // Fetch the target and set the asset's new location_id $target = User::find(request('assigned_user')); + if (!$target) { + return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.error'))); + } + $asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : ''; $error_payload['target_id'] = $request->input('assigned_user'); $error_payload['target_type'] = 'user'; From 77d513f80bcf34511d8ac1bc4997500b2fe323cb Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 28 Mar 2023 17:25:57 -0600 Subject: [PATCH 2/5] Assign target variable as the other checkout types --- app/Http/Controllers/Api/AssetsController.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index b14a79bcf..d4ff0092b 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -826,21 +826,12 @@ class AssetsController extends Controller // This item is checked out to a location if (request('checkout_to_type') == 'location') { $target = Location::find(request('assigned_location')); - if (!$target) { - return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.error'))); - } - $asset->location_id = ($target) ? $target->id : ''; $error_payload['target_id'] = $request->input('assigned_location'); $error_payload['target_type'] = 'location'; } elseif (request('checkout_to_type') == 'asset') { $target = Asset::where('id', '!=', $asset_id)->find(request('assigned_asset')); - if (!$target) { - return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.error'))); - } - - $asset->location_id = $target->rtd_location_id; // Override with the asset's location_id if it has one $asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : ''; $error_payload['target_id'] = $request->input('assigned_asset'); @@ -849,10 +840,6 @@ class AssetsController extends Controller } elseif (request('checkout_to_type') == 'user') { // Fetch the target and set the asset's new location_id $target = User::find(request('assigned_user')); - if (!$target) { - return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.error'))); - } - $asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : ''; $error_payload['target_id'] = $request->input('assigned_user'); $error_payload['target_type'] = 'user'; From 88826c1115a94a96b4a8959b2ecbee0a77b715bc Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 Mar 2023 16:26:27 -0700 Subject: [PATCH 3/5] Added link to SnipeAgent Signed-off-by: snipe --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9faa02f5b..4c569520c 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Since the release of the JSON REST API, several third-party developers have been - [WWW::SnipeIT](https://github.com/SEDC/perl-www-snipeit) by [@SEDC](https://github.com/SEDC) - perl module for accessing the API - [UniFi to Snipe-IT](https://github.com/RodneyLeeBrands/UnifiSnipeSync) by [@karpadiem](https://github.com/karpadiem) - Python script that synchronizes UniFi devices with Snipe-IT. - [Kandji2Snipe](https://github.com/grokability/kandji2snipe) by [@briangoldstein](https://github.com/briangoldstein) - Python script that synchronizes Kandji with Snipe-IT. +- [SnipeAgent](https://github.com/ReticentRobot/SnipeAgent) by @ReticentRobot - Windows agent for Snipe-IT As these were created by third-parties, Snipe-IT cannot provide support for these project, and you should contact the developers directly if you need assistance. Additionally, Snipe-IT makes no guarantees as to the reliability, accuracy or maintainability of these libraries. Use at your own risk. :) From 527c812d04725c7475422fb847ae877b1c8078f0 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 Mar 2023 16:39:41 -0700 Subject: [PATCH 4/5] Use icon for group users header Signed-off-by: snipe --- resources/views/groups/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/groups/index.blade.php b/resources/views/groups/index.blade.php index 4958e3a4d..4b2a2f0e3 100755 --- a/resources/views/groups/index.blade.php +++ b/resources/views/groups/index.blade.php @@ -43,7 +43,7 @@ {{ trans('general.id') }} {{ trans('admin/groups/table.name') }} - {{ trans('admin/groups/table.users') }} + {{ trans('admin/groups/table.users') }} {{ trans('general.created_at') }} {{ trans('table.actions') }} From 32922e6461b6bc2b4e7d4952f3af4b6350272723 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 Mar 2023 16:39:52 -0700 Subject: [PATCH 5/5] Use corrected language string Signed-off-by: snipe --- app/Http/Controllers/GroupsController.php | 11 +++++------ resources/lang/en/admin/groups/message.php | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/GroupsController.php b/app/Http/Controllers/GroupsController.php index abe3e0682..b98156824 100755 --- a/app/Http/Controllers/GroupsController.php +++ b/app/Http/Controllers/GroupsController.php @@ -92,7 +92,7 @@ class GroupsController extends Controller return view('groups.edit', compact('group', 'permissions', 'selected_array', 'groupPermissions')); } - return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found')); + return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', ['id' => $id])); } /** @@ -107,7 +107,7 @@ class GroupsController extends Controller public function update(Request $request, $id = null) { if (! $group = Group::find($id)) { - return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', compact('id'))); + return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', ['id' => $id])); } $group->name = $request->input('name'); $group->permissions = json_encode($request->input('permission')); @@ -133,14 +133,13 @@ class GroupsController extends Controller * @return \Illuminate\Http\RedirectResponse * @throws \Exception */ - public function destroy($id = null) + public function destroy($id) { if (! config('app.lock_passwords')) { if (! $group = Group::find($id)) { - return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', compact('id'))); + return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', ['id' => $id])); } $group->delete(); - // Redirect to the group management page return redirect()->route('groups.index')->with('success', trans('admin/groups/message.success.delete')); } @@ -164,6 +163,6 @@ class GroupsController extends Controller return view('groups/view', compact('group')); } - return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', compact('id'))); + return redirect()->route('groups.index')->with('error', trans('admin/groups/message.group_not_found', ['id' => $id])); } } diff --git a/resources/lang/en/admin/groups/message.php b/resources/lang/en/admin/groups/message.php index f14b6339e..495acaf36 100644 --- a/resources/lang/en/admin/groups/message.php +++ b/resources/lang/en/admin/groups/message.php @@ -3,7 +3,7 @@ return array( 'group_exists' => 'Group already exists!', - 'group_not_found' => 'Group [:id] does not exist.', + 'group_not_found' => 'Group ID :id does not exist.', 'group_name_required' => 'The name field is required', 'success' => array(