From c7f2acf2c6d41d4ec909861ef799fa59d188f57e Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 22 Aug 2023 11:39:38 -0700 Subject: [PATCH 1/8] removes encrypted info from change log, renames asset_eol_date in the change log --- .../Transformers/ActionlogsTransformer.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 2a592e9c83..30468c85e3 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -52,12 +52,18 @@ class ActionlogsTransformer if ($meta_array) { foreach ($meta_array as $fieldname => $fieldata) { - $clean_meta[$fieldname]['old'] = $this->clean_field($fieldata->old); - $clean_meta[$fieldname]['new'] = $this->clean_field($fieldata->new); - } + if ((strlen($this->clean_field($fieldata->old)) == 200) || (strlen($this->clean_field($fieldata->new))== 200)) { + $clean_meta[$fieldname]['old'] = "encrypted"; + $clean_meta[$fieldname]['new'] = "encrypted"; + } else { + $clean_meta[$fieldname]['old'] = $this->clean_field($fieldata->old); + $clean_meta[$fieldname]['new'] = $this->clean_field($fieldata->new); + } + } + \Log::info("Clean Meta is: " . print_r($clean_meta, true)); + $clean_meta = $this->changedInfo($clean_meta); } - $clean_meta= $this->changedInfo($clean_meta); } $file_url = ''; @@ -120,7 +126,7 @@ class ActionlogsTransformer 'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null, 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'), ]; - //\Log::info("Clean Meta is: ".print_r($clean_meta,true)); +// \Log::info("Clean Meta is: ".print_r($clean_meta,true)); //dd($array); return $array; @@ -176,6 +182,11 @@ class ActionlogsTransformer $clean_meta['Supplier'] = $clean_meta['supplier_id']; unset($clean_meta['supplier_id']); } + if(array_key_exists('asset_eol_date', $clean_meta)) { + + $clean_meta['EOL date'] = $clean_meta['asset_eol_date']; + unset($clean_meta['asset_eol_date']); + } return $clean_meta; From 9e438c3ed04da12b6df639c1e62be620837117dd Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 22 Aug 2023 12:34:45 -0700 Subject: [PATCH 2/8] eager loaded changedInfo queries, reworked encrypted data change log changes --- .../Transformers/ActionlogsTransformer.php | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 30468c85e3..19d299a83b 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -3,6 +3,7 @@ namespace App\Http\Transformers; use App\Helpers\Helper; use App\Models\Actionlog; +use App\Models\CustomField; use App\Models\Setting; use App\Models\Company; use App\Models\Supplier; @@ -42,6 +43,7 @@ class ActionlogsTransformer public function transformActionlog (Actionlog $actionlog, $settings = null) { $icon = $actionlog->present()->icon(); + $custom_field = CustomField::all(); if ($actionlog->filename!='') { $icon = e(\App\Helpers\Helper::filetype_icon($actionlog->filename)); } @@ -52,16 +54,19 @@ class ActionlogsTransformer if ($meta_array) { foreach ($meta_array as $fieldname => $fieldata) { - if ((strlen($this->clean_field($fieldata->old)) == 200) || (strlen($this->clean_field($fieldata->new))== 200)) { - $clean_meta[$fieldname]['old'] = "encrypted"; - $clean_meta[$fieldname]['new'] = "encrypted"; - } else { + if( str_starts_with($fieldname, '_snipeit_')){ + + if( $custom_field->where('name', '=', $fieldname)->where('field_encrypted', true)){ + $clean_meta[$fieldname]['old'] = "encrypted"; + $clean_meta[$fieldname]['new'] = "encrypted"; + } + } + else { $clean_meta[$fieldname]['old'] = $this->clean_field($fieldata->old); $clean_meta[$fieldname]['new'] = $this->clean_field($fieldata->new); } } - \Log::info("Clean Meta is: " . print_r($clean_meta, true)); $clean_meta = $this->changedInfo($clean_meta); } } @@ -150,40 +155,43 @@ class ActionlogsTransformer * @return array */ public function changedInfo(array $clean_meta) - { + { $location = Location::all(); + $company = Company::all(); + $supplier = Supplier::all(); + $model = AssetModel::all(); + if(array_key_exists('rtd_location_id',$clean_meta)) { - $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". Location::find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned'); - $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". Location::find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $location->find($clean_meta['rtd_location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $location->find($clean_meta['rtd_location_id']['new'])->name : trans('general.unassigned'); $clean_meta['Default Location'] = $clean_meta['rtd_location_id']; unset($clean_meta['rtd_location_id']); } if(array_key_exists('location_id', $clean_meta)) { - $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ".Location::find($clean_meta['location_id']['old'])->name : trans('general.unassigned'); - $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ".Location::find($clean_meta['location_id']['new'])->name : trans('general.unassigned'); + $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ".$location->find($clean_meta['location_id']['old'])->name : trans('general.unassigned'); + $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ".$location->find($clean_meta['location_id']['new'])->name : trans('general.unassigned'); $clean_meta['Current Location'] = $clean_meta['location_id']; unset($clean_meta['location_id']); } if(array_key_exists('model_id', $clean_meta)) { - $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."] ".AssetModel::find($clean_meta['model_id']['old'])->name; - $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."] ".AssetModel::find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ + $clean_meta['model_id']['old'] = "[id: ".$clean_meta['model_id']['old']."] ".$model->find($clean_meta['model_id']['old'])->name; + $clean_meta['model_id']['new'] = "[id: ".$clean_meta['model_id']['new']."] ".$model->find($clean_meta['model_id']['new'])->name; /* model is required at asset creation */ $clean_meta['Model'] = $clean_meta['model_id']; unset($clean_meta['model_id']); } if(array_key_exists('company_id', $clean_meta)) { - $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."]".Company::find($clean_meta['company_id']['old'])->name : trans('general.unassigned'); - $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."] ".Company::find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); + $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."]".$company->find($clean_meta['company_id']['old'])->name : trans('general.unassigned'); + $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."] ".$company->find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); $clean_meta['Company'] = $clean_meta['company_id']; unset($clean_meta['company_id']); } if(array_key_exists('supplier_id', $clean_meta)) { - $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."] ".Supplier::find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); - $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."] ".Supplier::find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); + $clean_meta['supplier_id']['old'] = $clean_meta['supplier_id']['old'] ? "[id: ".$clean_meta['supplier_id']['old']."] ".$supplier->find($clean_meta['supplier_id']['old'])->name : trans('general.unassigned'); + $clean_meta['supplier_id']['new'] = $clean_meta['supplier_id']['new'] ? "[id: ".$clean_meta['supplier_id']['new']."] ".$supplier->find($clean_meta['supplier_id']['new'])->name : trans('general.unassigned'); $clean_meta['Supplier'] = $clean_meta['supplier_id']; unset($clean_meta['supplier_id']); } if(array_key_exists('asset_eol_date', $clean_meta)) { - $clean_meta['EOL date'] = $clean_meta['asset_eol_date']; unset($clean_meta['asset_eol_date']); } From 1019287c760beee49139637837a11b12e9298505 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 22 Aug 2023 12:36:43 -0700 Subject: [PATCH 3/8] retarget key --- app/Http/Transformers/ActionlogsTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 19d299a83b..5d8d7e2d60 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -56,7 +56,7 @@ class ActionlogsTransformer foreach ($meta_array as $fieldname => $fieldata) { if( str_starts_with($fieldname, '_snipeit_')){ - if( $custom_field->where('name', '=', $fieldname)->where('field_encrypted', true)){ + if( $custom_field->where('db_column', '=', $fieldname)->where('field_encrypted', true)){ $clean_meta[$fieldname]['old'] = "encrypted"; $clean_meta[$fieldname]['new'] = "encrypted"; } From 92ddf8fc67f32cf628a5c8917829720ee63c3f5d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 22 Aug 2023 12:38:50 -0700 Subject: [PATCH 4/8] removed dead space --- app/Http/Transformers/ActionlogsTransformer.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 5d8d7e2d60..cb28ff8110 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -55,7 +55,6 @@ class ActionlogsTransformer if ($meta_array) { foreach ($meta_array as $fieldname => $fieldata) { if( str_starts_with($fieldname, '_snipeit_')){ - if( $custom_field->where('db_column', '=', $fieldname)->where('field_encrypted', true)){ $clean_meta[$fieldname]['old'] = "encrypted"; $clean_meta[$fieldname]['new'] = "encrypted"; @@ -65,7 +64,6 @@ class ActionlogsTransformer $clean_meta[$fieldname]['old'] = $this->clean_field($fieldata->old); $clean_meta[$fieldname]['new'] = $this->clean_field($fieldata->new); } - } $clean_meta = $this->changedInfo($clean_meta); } @@ -132,7 +130,6 @@ class ActionlogsTransformer 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'), ]; // \Log::info("Clean Meta is: ".print_r($clean_meta,true)); - //dd($array); return $array; } From ce60db009c51c41ce523b0818849528b4701e6a2 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 23 Aug 2023 00:32:43 -0700 Subject: [PATCH 5/8] adds soft deletes to eager loading --- app/Http/Transformers/ActionlogsTransformer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index cb28ff8110..e7ac55f523 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -152,10 +152,10 @@ class ActionlogsTransformer * @return array */ public function changedInfo(array $clean_meta) - { $location = Location::all(); - $company = Company::all(); - $supplier = Supplier::all(); - $model = AssetModel::all(); + { $location = Location::withTrashed()->all(); + $company = Company::withTrashed()->all(); + $supplier = Supplier::withTrashed()->all(); + $model = AssetModel::withTrashed()->get(); if(array_key_exists('rtd_location_id',$clean_meta)) { From 27488c1009c1a8f9d2156c414d7eb7b21ca14174 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 23 Aug 2023 00:32:43 -0700 Subject: [PATCH 6/8] adds soft deletes to eager loading --- app/Http/Transformers/ActionlogsTransformer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index cb28ff8110..dcccc92e6c 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -152,10 +152,10 @@ class ActionlogsTransformer * @return array */ public function changedInfo(array $clean_meta) - { $location = Location::all(); - $company = Company::all(); - $supplier = Supplier::all(); - $model = AssetModel::all(); + { $location = Location::withTrashed()->get(); + $company = Company::withTrashed()->get(); + $supplier = Supplier::withTrashed()->get(); + $model = AssetModel::withTrashed()->get(); if(array_key_exists('rtd_location_id',$clean_meta)) { From 0fc79ec936537b03fd81049b3a955a3d963715da Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 23 Aug 2023 00:40:59 -0700 Subject: [PATCH 7/8] fixes conflicts --- app/Http/Transformers/ActionlogsTransformer.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index e7ac55f523..99dd0c47e3 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -151,10 +151,11 @@ class ActionlogsTransformer * @param array $clean_meta * @return array */ - public function changedInfo(array $clean_meta) - { $location = Location::withTrashed()->all(); - $company = Company::withTrashed()->all(); - $supplier = Supplier::withTrashed()->all(); + public function changedInfo(array $clean_meta) { + + $location = Location::withTrashed()->get(); + $company = Company::withTrashed()->get(); + $supplier = Supplier::withTrashed()->get(); $model = AssetModel::withTrashed()->get(); From 74f45a44739c96d5c6776efa6238fdf64860e3ba Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 28 Aug 2023 19:35:46 -0700 Subject: [PATCH 8/8] reworks company queries for asset history --- app/Http/Transformers/ActionlogsTransformer.php | 11 ++++++++--- resources/lang/en/admin/companies/message.php | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 9198f89d00..16f413c7e7 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -153,7 +153,6 @@ class ActionlogsTransformer */ public function changedInfo(array $clean_meta) { $location = Location::withTrashed()->get(); - $company = Company::withTrashed()->get(); $supplier = Supplier::withTrashed()->get(); $model = AssetModel::withTrashed()->get(); @@ -179,8 +178,14 @@ class ActionlogsTransformer unset($clean_meta['model_id']); } if(array_key_exists('company_id', $clean_meta)) { - $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."]".$company->find($clean_meta['company_id']['old'])->name : trans('general.unassigned'); - $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."] ".$company->find($clean_meta['company_id']['new'])->name : trans('general.unassigned'); + $oldCompany = Company::find($clean_meta['company_id']['old']); + $oldCompanyName = $oldCompany->name ?? trans('admin/companies/message.deleted'); + + $newCompany = Company::find($clean_meta['company_id']['new']); + $newCompanyName = $newCompany->name ?? trans('admin/companies/message.deleted'); + + $clean_meta['company_id']['old'] = $clean_meta['company_id']['old'] ? "[id: ".$clean_meta['company_id']['old']."] ". $oldCompanyName : trans('general.unassigned'); + $clean_meta['company_id']['new'] = $clean_meta['company_id']['new'] ? "[id: ".$clean_meta['company_id']['new']."] ". $newCompanyName : trans('general.unassigned'); $clean_meta['Company'] = $clean_meta['company_id']; unset($clean_meta['company_id']); } diff --git a/resources/lang/en/admin/companies/message.php b/resources/lang/en/admin/companies/message.php index b44bdd4b85..e440b7ac5f 100644 --- a/resources/lang/en/admin/companies/message.php +++ b/resources/lang/en/admin/companies/message.php @@ -2,6 +2,7 @@ return [ 'does_not_exist' => 'Company does not exist.', + 'deleted' => 'Deleted company', 'assoc_users' => 'This company is currently associated with at least one model and cannot be deleted. Please update your models to no longer reference this company and try again. ', 'create' => [ 'error' => 'Company was not created, please try again.',