Skip to content

Commit b1f158b

Browse files
authored
Merge pull request #13749 from snipe/bug/sc-23473
Handle case where value is deleted in history
2 parents 04f6f39 + a92a9d7 commit b1f158b

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

app/Http/Transformers/ActionlogsTransformer.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use App\Models\Location;
1111
use App\Models\AssetModel;
1212
use Illuminate\Database\Eloquent\Collection;
13+
use Illuminate\Contracts\Encryption\DecryptException;
14+
use Illuminate\Support\Facades\Crypt;
1315

1416
class ActionlogsTransformer
1517
{
@@ -69,9 +71,36 @@ public function transformActionlog (Actionlog $actionlog, $settings = null)
6971

7072
if ($custom_field->db_column == $fieldname) {
7173

72-
if ($custom_field->field_encrypted == '1') {
73-
$clean_meta[$fieldname]['old'] = "************";
74-
$clean_meta[$fieldname]['new'] = "************";
74+
if ($custom_field->field_encrypted == '1') {
75+
76+
// Unset these fields. We need to decrypt them, since even if the decrypted value
77+
// didn't change, their value in the DB will, so we have to compare the unencrypted version
78+
// to see if the values actually did change
79+
unset($clean_meta[$fieldname]);
80+
unset($clean_meta[$fieldname]);
81+
82+
$enc_old = '';
83+
$enc_new = '';
84+
85+
try {
86+
$enc_old = \Crypt::decryptString($this->clean_field($fieldata->old));
87+
} catch (\Exception $e) {
88+
\Log::debug('Could not decrypt field - maybe the key changed?');
89+
}
90+
91+
try {
92+
$enc_new = \Crypt::decryptString($this->clean_field($fieldata->new));
93+
} catch (\Exception $e) {
94+
\Log::debug('Could not decrypt field - maybe the key changed?');
95+
}
96+
97+
if ($enc_old != $enc_new) {
98+
\Log::debug('custom fields do not match');
99+
$clean_meta[$fieldname]['old'] = "************";
100+
$clean_meta[$fieldname]['new'] = "************";
101+
}
102+
103+
75104
}
76105

77106
}
@@ -178,15 +207,31 @@ public function changedInfo(array $clean_meta)
178207

179208

180209
if(array_key_exists('rtd_location_id',$clean_meta)) {
181-
$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');
182-
$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');
210+
211+
$oldRtd = $location->find($clean_meta['rtd_location_id']['old']);
212+
$oldRtdName = $oldRtd ? e($oldRtd->name) : trans('general.deleted');
213+
214+
$newRtd = $location->find($clean_meta['rtd_location_id']['new']);
215+
$newRtdName = $newRtd ? e($newRtd->name) : trans('general.deleted');
216+
217+
$clean_meta['rtd_location_id']['old'] = $clean_meta['rtd_location_id']['old'] ? "[id: ".$clean_meta['rtd_location_id']['old']."] ". $oldRtdName : '';
218+
$clean_meta['rtd_location_id']['new'] = $clean_meta['rtd_location_id']['new'] ? "[id: ".$clean_meta['rtd_location_id']['new']."] ". $newRtdName : '';
183219
$clean_meta['Default Location'] = $clean_meta['rtd_location_id'];
184220
unset($clean_meta['rtd_location_id']);
185221
}
186222

223+
187224
if (array_key_exists('location_id', $clean_meta)) {
188-
$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');
189-
$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');
225+
226+
$oldLocation = $location->find($clean_meta['location_id']['old']);
227+
$oldLocationName = $oldLocation ? e($oldLocation->name) : trans('general.deleted');
228+
229+
$newLocation = $location->find($clean_meta['location_id']['new']);
230+
$newLocationName = $newLocation ? e($newLocation->name) : trans('general.deleted');
231+
232+
233+
$clean_meta['location_id']['old'] = $clean_meta['location_id']['old'] ? "[id: ".$clean_meta['location_id']['old']."] ". $oldLocationName : '';
234+
$clean_meta['location_id']['new'] = $clean_meta['location_id']['new'] ? "[id: ".$clean_meta['location_id']['new']."] ". $newLocationName : '';
190235
$clean_meta['Current Location'] = $clean_meta['location_id'];
191236
unset($clean_meta['location_id']);
192237
}

app/Models/Asset.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function declinedCheckout(User $declinedBy, $signature)
7272

7373
protected $casts = [
7474
'purchase_date' => 'date',
75-
'asset_eol_date' => 'date',
76-
'eol_explicit' => 'boolean',
75+
'eol_explicit' => 'boolean',
7776
'last_checkout' => 'datetime',
7877
'last_checkin' => 'datetime',
7978
'expected_checkin' => 'date',

0 commit comments

Comments
 (0)