From 93cccf4f5f22ba44aee96702ea362764c47fc0be Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 13 Oct 2023 19:32:09 +0100 Subject: [PATCH 1/3] Handle case where value is deleted in history Signed-off-by: snipe --- .../Transformers/ActionlogsTransformer.php | 59 ++++++++++++++++--- app/Models/Asset.php | 3 +- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 1cc105e6a9..b04a737da2 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -10,6 +10,8 @@ use App\Models\Supplier; use App\Models\Location; use App\Models\AssetModel; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Contracts\Encryption\DecryptException; +use Illuminate\Support\Facades\Crypt; class ActionlogsTransformer { @@ -69,9 +71,36 @@ class ActionlogsTransformer if ($custom_field->db_column == $fieldname) { - if ($custom_field->field_encrypted == '1') { - $clean_meta[$fieldname]['old'] = "************"; - $clean_meta[$fieldname]['new'] = "************"; + if ($custom_field->field_encrypted == '1') { + + // Unset these fields. We need to decrypt them, since even if the decrypted value + // didn't change, their value in the DB will, so we have to compare the unencrypted version + // to see if the values actually did change + unset($clean_meta[$fieldname]); + unset($clean_meta[$fieldname]); + + $enc_old = ''; + $enc_new = ''; + + try { + $enc_old = \Crypt::decryptString($this->clean_field($fieldata->old)); + } catch (\Exception $e) { + \Log::debug('Could not decrypt field - maybe the key changed?'); + } + + try { + $enc_new = \Crypt::decryptString($this->clean_field($fieldata->new)); + } catch (\Exception $e) { + \Log::debug('Could not decrypt field - maybe the key changed?'); + } + + if ($enc_old != $enc_new) { + \Log::debug('custom fields do not match'); + $clean_meta[$fieldname]['old'] = "************"; + $clean_meta[$fieldname]['new'] = "************"; + } + + } } @@ -178,15 +207,31 @@ class ActionlogsTransformer 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']."] ". e($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']."] ". e($location->find($clean_meta['rtd_location_id']['new'])->name) : trans('general.unassigned'); + + $oldRtd = $location->find($clean_meta['rtd_location_id']['old']); + $oldRtdName = $oldRtd ? e($oldRtd->name) : trans('general.deleted'); + + $newRtd = $location->find($clean_meta['rtd_location_id']['new']); + $newRtdName = $newRtd ? e($newRtd->name) : trans('general.deleted'); + + $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $oldRtdName : 'foo'; + $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $newRtdName : 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']."] ".e($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']."] ".e($location->find($clean_meta['location_id']['new'])->name) : trans('general.unassigned'); + + $oldLocation = $location->find($clean_meta['location_id']['old']); + $oldLocationName = $oldLocation ? e($oldLocation->name) : trans('general.deleted'); + + $newLocation = $location->find($clean_meta['location_id']['new']); + $newLocationName = $newLocation ? e($newLocation->name) : trans('general.deleted'); + + + $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ". $oldLocationName : trans('general.deleted'); + $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ". $newLocationName : trans('general.unassigned'); $clean_meta['Current Location'] = $clean_meta['location_id']; unset($clean_meta['location_id']); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index e2ffb7ee99..1ce38bca01 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -72,8 +72,7 @@ class Asset extends Depreciable protected $casts = [ 'purchase_date' => 'date', - 'asset_eol_date' => 'date', - 'eol_explicit' => 'boolean', + 'eol_explicit' => 'boolean', 'last_checkout' => 'datetime', 'last_checkin' => 'datetime', 'expected_checkin' => 'date', From 8f23a45cb3467872267fb65cbc8fdc9df14dcaec Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 13 Oct 2023 19:49:03 +0100 Subject: [PATCH 2/3] Removed dummy text Signed-off-by: snipe --- 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 b04a737da2..403662f47b 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -214,7 +214,7 @@ class ActionlogsTransformer $newRtd = $location->find($clean_meta['rtd_location_id']['new']); $newRtdName = $newRtd ? e($newRtd->name) : trans('general.deleted'); - $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $oldRtdName : 'foo'; + $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $oldRtdName : ''; $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $newRtdName : trans('general.unassigned'); $clean_meta['Default Location'] = $clean_meta['rtd_location_id']; unset($clean_meta['rtd_location_id']); From a92a9d76166ff5f16e504f3f4781d9e599811615 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 13 Oct 2023 19:53:11 +0100 Subject: [PATCH 3/3] Removed duplicated deleted Signed-off-by: snipe --- app/Http/Transformers/ActionlogsTransformer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 403662f47b..d3af3bb753 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -215,7 +215,7 @@ class ActionlogsTransformer $newRtdName = $newRtd ? e($newRtd->name) : trans('general.deleted'); $clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $oldRtdName : ''; - $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $newRtdName : trans('general.unassigned'); + $clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $newRtdName : ''; $clean_meta['Default Location'] = $clean_meta['rtd_location_id']; unset($clean_meta['rtd_location_id']); } @@ -230,8 +230,8 @@ class ActionlogsTransformer $newLocationName = $newLocation ? e($newLocation->name) : trans('general.deleted'); - $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ". $oldLocationName : trans('general.deleted'); - $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ". $newLocationName : trans('general.unassigned'); + $clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ". $oldLocationName : ''; + $clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ". $newLocationName : ''; $clean_meta['Current Location'] = $clean_meta['location_id']; unset($clean_meta['location_id']); }