From d7c531e1c7d4fb2d1340abce56c92c5ce5c3d87b Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 29 Mar 2023 10:33:15 -0600 Subject: [PATCH 01/19] Checks if user variable exist before using its properties --- resources/views/account/accept/index.blade.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index f97c6c5644..9f11bdfa7b 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -1,8 +1,11 @@ @extends('layouts/default') +@php + !empty($user) ? $full_name = $user->present()->full_name : $full_name = ''; +@endphp {{-- Page title --}} @section('title') -{{ trans('general.accept_assets', array('name' => $user->present()->fullName())) }} +{{ trans('general.accept_assets', array('name' => $full_name)) }} @parent @stop From 9cc74caa9e7fa4a1ff850c3e93aee4c76f34cb8a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 29 Mar 2023 10:58:25 -0700 Subject: [PATCH 02/19] Add wire:model to import form checkboxes --- resources/views/livewire/importer.blade.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index a7b9c3e51c..fbe5802d28 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -160,22 +160,22 @@
-
-
-
@@ -379,4 +379,4 @@ });}) -@endpush \ No newline at end of file +@endpush From 4cbe683a1a1e7d2d0ea27f4335380613491a9bcb Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 29 Mar 2023 11:28:04 -0700 Subject: [PATCH 03/19] Explicitly cast asset tag to string when querying --- app/Importer/AssetImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index bf47c73608..0fcbf1166c 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -60,7 +60,7 @@ class AssetImporter extends ItemImporter $asset_tag = Asset::autoincrement_asset(); } - $asset = Asset::where(['asset_tag'=> $asset_tag])->first(); + $asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first(); if ($asset) { if (! $this->updating) { $this->log('A matching Asset '.$asset_tag.' already exists'); From 6bee4c1a75988a6c00729ae2b27761da52c86286 Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 29 Mar 2023 14:59:00 -0400 Subject: [PATCH 04/19] Updating Apple warranty link to match current Apple webpage --- resources/views/hardware/view.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index e5fc43b613..5dbfacc5a3 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -597,7 +597,7 @@ @if ($asset->serial && $asset->model->manufacturer) @if ((strtolower($asset->model->manufacturer->name) == "apple") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"appleinc"))) - + @elseif ((strtolower($asset->model->manufacturer->name) == "dell") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"dellinc"))) From e05546d1fa242320c5177da0733d6aa277fe1d76 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 29 Mar 2023 13:23:45 -0700 Subject: [PATCH 05/19] Display helpful messages when importing assets --- app/Http/Livewire/Importer.php | 4 ++++ resources/views/livewire/importer.blade.php | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php index 784d3b2982..1026a188b3 100644 --- a/app/Http/Livewire/Importer.php +++ b/app/Http/Livewire/Importer.php @@ -3,6 +3,7 @@ namespace App\Http\Livewire; use App\Models\CustomField; +use Illuminate\Support\Facades\Auth; use Livewire\Component; use App\Models\Import; @@ -16,6 +17,8 @@ class Importer extends Component { use AuthorizesRequests; + public bool $userIsSuperUser; + public $files; public $progress; //upload progress - '-1' means don't show @@ -250,6 +253,7 @@ class Importer extends Component public function mount() { $this->authorize('import'); + $this->userIsSuperUser = Auth::user()->isSuperUser(); $this->progress = -1; // '-1' means 'don't show the progressbar' $this->progress_bar_class = 'progress-bar-warning'; \Log::debug("Hey, we are calling MOUNT (in the importer-file) !!!!!!!!"); //fcuk diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index fbe5802d28..22663bc503 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -156,6 +156,11 @@ 'data-minimum-results-for-search' => '-1', // Remove this if the list gets long enough that we need to search 'data-livewire-component' => $_instance->id ]) }} + @if ($activeFile->import_type === 'asset' && $snipeSettings->auto_increment_assets == 0) + + Generating auto-incrementing asset tags is @if ($userIsSuperUser)disabled @else disabled @endif so all rows need to have the "Asset Tag" column populated. + + @endif @@ -163,6 +168,11 @@ @@ -344,7 +354,7 @@ 'import-update': !!@this.update, 'send-welcome': !!@this.send_welcome, 'import-type': @this.activeFile.import_type, - 'run-backup': !!@this.run_backup, + 'A': !!@this.run_backup, 'column-mappings': mappings }), headers: { From 863a346d6e1474921b96840cc4302105ace42675 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 29 Mar 2023 13:37:14 -0700 Subject: [PATCH 06/19] Translate strings --- resources/lang/en/general.php | 2 ++ resources/views/livewire/importer.blade.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 99fa3bd304..aa2e85c2fe 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -422,6 +422,8 @@ return [ 'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)', 'clear_and_save' => 'Clear & Save', 'update_existing_values' => 'Update Existing Values?', + 'auto_incrementing_asset_tags_disabled_so_tags_required' => 'Generating auto-incrementing asset tags is disabled so all rows need to have the "Asset Tag" column populated.', + 'auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created' => 'Note: Generating auto-incrementing asset tags is enabled so assets will be created for rows that do not have "Asset Tag" populated. Rows that do have "Asset Tag" populated will be updated with the provided information.', 'send_welcome_email_to_users' => ' Send Welcome Email for new Users?', 'back_before_importing' => 'Backup before importing?', 'csv_header_field' => 'CSV Header Field', diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 22663bc503..033c231453 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -158,7 +158,7 @@ ]) }} @if ($activeFile->import_type === 'asset' && $snipeSettings->auto_increment_assets == 0) - Generating auto-incrementing asset tags is @if ($userIsSuperUser)disabled @else disabled @endif so all rows need to have the "Asset Tag" column populated. + {{ trans('general.auto_incrementing_asset_tags_disabled_so_tags_required') }} @endif @@ -170,7 +170,7 @@ {{ trans('general.update_existing_values') }} @if ($activeFile->import_type === 'asset' && $snipeSettings->auto_increment_assets == 1 && $update) - Note: Generating auto-incrementing asset tags is @if ($userIsSuperUser)disabled @else enabled @endif so assets will be created for rows that do not have "Asset Tag" populated. Rows that do have "Asset Tag" populated will be updated with the provided information. + {{ trans('general.auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created') }} @endif From 162b70d5a954752e9007e3e93ab7843a649e0e10 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 17:34:36 -0500 Subject: [PATCH 07/19] wireframed, needs a view and should work --- .../Controllers/Assets/BulkAssetsController.php | 16 ++++++++++++++++ resources/views/hardware/index.blade.php | 8 +++++--- .../views/partials/asset-bulk-actions.blade.php | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 7f9e812ab4..884996d22c 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -56,6 +56,14 @@ class BulkAssetsController extends Controller }); return view('hardware/bulk-delete')->with('assets', $assets); + + case 'restore': + $assets = Asset::with('assignedTo', 'location')->find($asset_ids); + $assets->each(function ($asset) { + $this->authorize('restore', $asset); + }); + + return view('hardware/bulk-restore')->with('assets', $assets); case 'edit': return view('hardware/bulk') ->with('assets', $asset_ids) @@ -320,5 +328,13 @@ class BulkAssetsController extends Controller } catch (ModelNotFoundException $e) { return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors()); } + + } + public function restore(Request $request) { + $assetIds = $request->get('ids'); + foreach ($assetIds as $key => $assetId) { + $asset = Asset::withTrashed()->find($assetId); + $asset->restore(); + } } } diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index a73b37f2ce..6f1a4944da 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -62,14 +62,16 @@
+ + - @if (Request::get('status')!='Deleted') + {{-- @if (Request::get('status')!='Deleted') --}} - @include('partials.asset-bulk-actions') + @include('partials.asset-bulk-actions', ['status' => Request::get('status')]) - @endif + {{-- @endif --}} From e4c76f454c6a5a419af18c7d6643ceb478fd0a54 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 18:24:56 -0500 Subject: [PATCH 08/19] this is good, just needs translations done in view --- .../Assets/BulkAssetsController.php | 7 ++- resources/lang/en/admin/hardware/form.php | 3 + .../views/hardware/bulk-restore.blade.php | 62 +++++++++++++++++++ routes/web/hardware.php | 7 ++- 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 resources/views/hardware/bulk-restore.blade.php diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 884996d22c..efa4078dad 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -49,6 +49,7 @@ class BulkAssetsController extends Controller ->with('settings', Setting::getSettings()) ->with('bulkedit', true) ->with('count', 0); + case 'delete': $assets = Asset::with('assignedTo', 'location')->find($asset_ids); $assets->each(function ($asset) { @@ -58,12 +59,13 @@ class BulkAssetsController extends Controller return view('hardware/bulk-delete')->with('assets', $assets); case 'restore': - $assets = Asset::with('assignedTo', 'location')->find($asset_ids); + $assets = Asset::withTrashed()->find($asset_ids); $assets->each(function ($asset) { - $this->authorize('restore', $asset); + $this->authorize('delete', $asset); }); return view('hardware/bulk-restore')->with('assets', $assets); + case 'edit': return view('hardware/bulk') ->with('assets', $asset_ids) @@ -336,5 +338,6 @@ class BulkAssetsController extends Controller $asset = Asset::withTrashed()->find($assetId); $asset->restore(); } + return redirect()->route('hardware.index')->with('success', 'Assets Restored'); } } diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 22aac61d07..789feb74fd 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -2,8 +2,11 @@ return [ 'bulk_delete' => 'Confirm Bulk Delete Assets', + 'bulk_restore' => 'Confirm Bulk Restore Assets', 'bulk_delete_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', + 'bulk_restore_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', 'bulk_delete_warn' => 'You are about to delete :asset_count assets.', + 'bulk_restore_warn' => 'You are about to restore :asset_count assets.', 'bulk_update' => 'Bulk Update Assets', 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', diff --git a/resources/views/hardware/bulk-restore.blade.php b/resources/views/hardware/bulk-restore.blade.php new file mode 100644 index 0000000000..663cd81026 --- /dev/null +++ b/resources/views/hardware/bulk-restore.blade.php @@ -0,0 +1,62 @@ +@extends('layouts/default') + +{{-- Page title --}} +@section('title') +{{ trans('admin/hardware/form.bulk_delete') }} +@parent +@stop + +@section('header_right') + + {{ trans('general.back') }} +@stop + +{{-- Page content --}} +@section('content') +
+ +
+

{{ trans('admin/hardware/form.bulk_delete_help') }}

+
+ {{csrf_field()}} +
+
+

{{ trans('admin/hardware/form.bulk_restore_warn', ['asset_count' => count($assets)]) }}

+
+ +
+
+ + + + + + + + + + @foreach ($assets as $asset) + + + + + + + @endforeach + +
{{ trans('admin/hardware/table.id') }}{{ trans('admin/hardware/table.name') }}{{ trans('admin/hardware/table.location')}}
{{ $asset->id }}{{ $asset->present()->name() }} + @if ($asset->location) + {{ $asset->location->name }} + @endif +
+
+ + +
+ + + +@stop diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 09811d17d7..690d8e0d1c 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -160,6 +160,11 @@ Route::group( [BulkAssetsController::class, 'destroy'] )->name('hardware/bulkdelete'); + Route::post( + 'bulkrestore', + [BulkAssetsController::class, 'restore'] + )->name('hardware/bulkrestore'); + Route::post( 'bulksave', [BulkAssetsController::class, 'update'] @@ -181,4 +186,4 @@ Route::resource('hardware', 'middleware' => ['auth'], 'parameters' => ['asset' => 'asset_id' ], -]); \ No newline at end of file +]); From d033733fc01f3143338b0cd32e7b42779f6cbfab Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 18:30:39 -0500 Subject: [PATCH 09/19] oops, remove a couple things --- resources/lang/en/admin/hardware/form.php | 3 --- resources/views/hardware/index.blade.php | 8 -------- 2 files changed, 11 deletions(-) diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 789feb74fd..22aac61d07 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -2,11 +2,8 @@ return [ 'bulk_delete' => 'Confirm Bulk Delete Assets', - 'bulk_restore' => 'Confirm Bulk Restore Assets', 'bulk_delete_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', - 'bulk_restore_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', 'bulk_delete_warn' => 'You are about to delete :asset_count assets.', - 'bulk_restore_warn' => 'You are about to restore :asset_count assets.', 'bulk_update' => 'Bulk Update Assets', 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index 6f1a4944da..a9a0dba580 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -63,16 +63,8 @@
- - - {{-- @if (Request::get('status')!='Deleted') --}} - - - @include('partials.asset-bulk-actions', ['status' => Request::get('status')]) - {{-- @endif --}} - Date: Wed, 29 Mar 2023 16:58:55 -0700 Subject: [PATCH 10/19] Remove unneeded variable --- app/Http/Livewire/Importer.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php index 1026a188b3..88c07cb793 100644 --- a/app/Http/Livewire/Importer.php +++ b/app/Http/Livewire/Importer.php @@ -17,8 +17,6 @@ class Importer extends Component { use AuthorizesRequests; - public bool $userIsSuperUser; - public $files; public $progress; //upload progress - '-1' means don't show @@ -253,7 +251,6 @@ class Importer extends Component public function mount() { $this->authorize('import'); - $this->userIsSuperUser = Auth::user()->isSuperUser(); $this->progress = -1; // '-1' means 'don't show the progressbar' $this->progress_bar_class = 'progress-bar-warning'; \Log::debug("Hey, we are calling MOUNT (in the importer-file) !!!!!!!!"); //fcuk From 0998c70a92f3ea056380283d88285dfb9f36bbab Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 29 Mar 2023 16:59:26 -0700 Subject: [PATCH 11/19] Remove unneeded import --- app/Http/Livewire/Importer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php index 88c07cb793..784d3b2982 100644 --- a/app/Http/Livewire/Importer.php +++ b/app/Http/Livewire/Importer.php @@ -3,7 +3,6 @@ namespace App\Http\Livewire; use App\Models\CustomField; -use Illuminate\Support\Facades\Auth; use Livewire\Component; use App\Models\Import; From 6beb3b551ac4101df69e3fc98b677ff4eef86760 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 29 Mar 2023 17:01:24 -0700 Subject: [PATCH 12/19] Fix typo --- resources/views/livewire/importer.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 033c231453..8c4b8f8806 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -354,7 +354,7 @@ 'import-update': !!@this.update, 'send-welcome': !!@this.send_welcome, 'import-type': @this.activeFile.import_type, - 'A': !!@this.run_backup, + 'run-backup': !!@this.run_backup, 'column-mappings': mappings }), headers: { From d622dbb9434bae2b599781cac68161c8864a3907 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 29 Mar 2023 18:37:47 -0600 Subject: [PATCH 13/19] Revert the php codeblock and replace it with a ternary --- resources/views/account/accept/index.blade.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index 9f11bdfa7b..f2a9bc56f2 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -1,11 +1,8 @@ @extends('layouts/default') -@php - !empty($user) ? $full_name = $user->present()->full_name : $full_name = ''; -@endphp {{-- Page title --}} @section('title') -{{ trans('general.accept_assets', array('name' => $full_name)) }} +{{ trans('general.accept_assets', array('name' => empty($user) ? '' : $user->present()->full_name)) }} @parent @stop From d5d50264c342d1fa22c14248d735b04cb096829a Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 19:53:04 -0500 Subject: [PATCH 14/19] fix permissions stuff + optional parameter --- resources/views/partials/asset-bulk-actions.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/views/partials/asset-bulk-actions.blade.php b/resources/views/partials/asset-bulk-actions.blade.php index 02e2b6b4bd..c57e232a1b 100644 --- a/resources/views/partials/asset-bulk-actions.blade.php +++ b/resources/views/partials/asset-bulk-actions.blade.php @@ -13,8 +13,10 @@