diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index d4ff0092ba..bad1947966 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -463,7 +463,7 @@ class AssetsController extends Controller { $this->authorize('view', Asset::class); $this->authorize('view', License::class); - $asset = Asset::where('id', $id)->withTrashed()->first(); + $asset = Asset::where('id', $id)->withTrashed()->firstorfail(); $licenses = $asset->licenses()->get(); return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count()); diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 7f9e812ab4..8cfbec849f 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) { @@ -56,6 +57,15 @@ class BulkAssetsController extends Controller }); return view('hardware/bulk-delete')->with('assets', $assets); + + case 'restore': + $assets = Asset::withTrashed()->find($asset_ids); + $assets->each(function ($asset) { + $this->authorize('delete', $asset); + }); + + return view('hardware/bulk-restore')->with('assets', $assets); + case 'edit': return view('hardware/bulk') ->with('assets', $asset_ids) @@ -320,5 +330,18 @@ 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'); + if (empty($assetIds)) { + return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.restore.nothing_updated')); + } else { + foreach ($assetIds as $key => $assetId) { + $asset = Asset::withTrashed()->find($assetId); + $asset->restore(); + } + return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.restore.success')); + } } } 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'); diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 22aac61d07..7548983463 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 restoration below. Once restored, these assets will not be associated with any users they were previously 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/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.php index fabbb63243..18f3b3fa24 100644 --- a/resources/lang/en/admin/hardware/message.php +++ b/resources/lang/en/admin/hardware/message.php @@ -23,6 +23,8 @@ return [ 'restore' => [ 'error' => 'Asset was not restored, please try again', 'success' => 'Asset restored successfully.', + 'bulk_success' => 'Asset restored successfully.', + 'nothing_updated' => 'No assets were selected, so nothing was restored.', ], 'audit' => [ 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/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index f97c6c5644..f2a9bc56f2 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -{{ trans('general.accept_assets', array('name' => $user->present()->fullName())) }} +{{ trans('general.accept_assets', array('name' => empty($user) ? '' : $user->present()->full_name)) }} @parent @stop diff --git a/resources/views/hardware/bulk-restore.blade.php b/resources/views/hardware/bulk-restore.blade.php new file mode 100644 index 0000000000..caabe9fab8 --- /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_restore') }} +@parent +@stop + +@section('header_right') + + {{ trans('general.back') }} +@stop + +{{-- Page content --}} +@section('content') +
+ +
+

{{ trans('admin/hardware/form.bulk_restore_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/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index a73b37f2ce..a9a0dba580 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -62,15 +62,9 @@
- - @if (Request::get('status')!='Deleted') - - - @include('partials.asset-bulk-actions') + @include('partials.asset-bulk-actions', ['status' => Request::get('status')]) - @endif - 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"))) diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index a7b9c3e51c..8c4b8f8806 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -156,26 +156,36 @@ '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) + + {{ trans('general.auto_incrementing_asset_tags_disabled_so_tags_required') }} + + @endif
-
-
-
@@ -379,4 +389,4 @@ });}) -@endpush \ No newline at end of file +@endpush diff --git a/resources/views/partials/asset-bulk-actions.blade.php b/resources/views/partials/asset-bulk-actions.blade.php index 6a94ad4871..c57e232a1b 100644 --- a/resources/views/partials/asset-bulk-actions.blade.php +++ b/resources/views/partials/asset-bulk-actions.blade.php @@ -13,6 +13,11 @@ 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 +]);