Skip to content

Commit

Permalink
Added attributes blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean/Lychee committed Jul 19, 2018
1 parent 6009032 commit 6811970
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/HistoryObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function updating($model)
$changes = $model->getDirty();
$changed = [];
foreach ($changes as $key => $value) {
if(static::isIgnored($model, $key)) continue;

array_push($changed, ['key' => $key, 'old' => $model->getOriginal($key), 'new' => $model->$key]);
}

Expand Down Expand Up @@ -105,6 +107,14 @@ public static function getUserType()
return auth()->check() ? get_class(auth()->user()) : null;
}

public static function isIgnored($model, $key)
{
$blacklist = config('history.attributes_blacklist');
$name = get_class($model);
$array = $blacklist[$name];
return !empty($array) && in_array($key, $array);
}

public static function filter($action)
{
if(!auth()->check()) {
Expand Down
17 changes: 16 additions & 1 deletion src/config/history.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,28 @@
'created', 'updating', 'deleting', 'restored',
],

/*
|--------------------------------------------------------------
| Attributes blacklist
|--------------------------------------------------------------
|
| Please add the whole class names. Example: \App\User:class
| For each model, attributes in its respect array will NOT be recorded into meta when performing update operation.
|
*/
'attributes_blacklist' => [
// \App\User::class => [
// 'password'
// ],
],

/*
|--------------------------------------------------------------
| User blacklist
|--------------------------------------------------------------
|
| Operations performed by users in this array will NOT be recorded.
| Please add the whole class names. Example: \App\User
| Please add the whole class names. Example: \App\User:class
| Use 'nobody' to bypass unauthenticated operations
|
*/
Expand Down

0 comments on commit 6811970

Please sign in to comment.