Unset the specific arrays we don’t want to keep

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2023-11-22 20:50:46 +00:00
parent a7f76f9860
commit 22246dd099

View file

@ -22,23 +22,24 @@ class UserObserver
if ($user->getRawOriginal()[$key] != $user->getAttributes()[$key]) { if ($user->getRawOriginal()[$key] != $user->getAttributes()[$key]) {
// Do not store the hashed password in changes
if ($key!='password') {
$changed[$key]['old'] = $user->getRawOriginal()[$key]; $changed[$key]['old'] = $user->getRawOriginal()[$key];
$changed[$key]['new'] = $user->getAttributes()[$key]; $changed[$key]['new'] = $user->getAttributes()[$key];
} else {
$changed[$key]['old'] = '*************'; // Do not store the hashed password in changes
$changed[$key]['new'] = '*************'; if ($key == 'password') {
$changed['password']['old'] = '*************';
$changed['password']['new'] = '*************';
} }
if ($key!='last_login') { // Do not store last login in changes
unset($changed['last_login']['old']); if ($key == 'last_login') {
unset($changed['last_login']['new']); unset($changed['last_login']);
unset($changed['last_login']);
} }
if ($key!='permissions') { if ($key == 'permissions') {
unset($changed['permissions']['old']); unset($changed['permissions']);
unset($changed['permissions']['new']); unset($changed['permissions']);
} }
} }
} }
@ -46,6 +47,8 @@ class UserObserver
$logAction = new Actionlog(); $logAction = new Actionlog();
$logAction->item_type = User::class; $logAction->item_type = User::class;
$logAction->item_id = $user->id; $logAction->item_id = $user->id;
$logAction->target_type = User::class; // can we instead say $logAction->item = $asset ?
$logAction->target_id = $user->id;
$logAction->created_at = date('Y-m-d H:i:s'); $logAction->created_at = date('Y-m-d H:i:s');
$logAction->user_id = Auth::id(); $logAction->user_id = Auth::id();
$logAction->log_meta = json_encode($changed); $logAction->log_meta = json_encode($changed);
@ -81,6 +84,8 @@ class UserObserver
$logAction = new Actionlog(); $logAction = new Actionlog();
$logAction->item_type = User::class; $logAction->item_type = User::class;
$logAction->item_id = $user->id; $logAction->item_id = $user->id;
$logAction->target_type = User::class; // can we instead say $logAction->item = $asset ?
$logAction->target_id = $user->id;
$logAction->created_at = date('Y-m-d H:i:s'); $logAction->created_at = date('Y-m-d H:i:s');
$logAction->user_id = Auth::id(); $logAction->user_id = Auth::id();
$logAction->logaction('delete'); $logAction->logaction('delete');
@ -97,6 +102,8 @@ class UserObserver
$logAction = new Actionlog(); $logAction = new Actionlog();
$logAction->item_type = User::class; $logAction->item_type = User::class;
$logAction->item_id = $user->id; $logAction->item_id = $user->id;
$logAction->target_type = User::class; // can we instead say $logAction->item = $asset ?
$logAction->target_id = $user->id;
$logAction->created_at = date('Y-m-d H:i:s'); $logAction->created_at = date('Y-m-d H:i:s');
$logAction->user_id = Auth::id(); $logAction->user_id = Auth::id();
$logAction->logaction('restore'); $logAction->logaction('restore');