Selectively show the additional metadata if it isn't in the display string at all
This commit is contained in:
parent
88987fb6c7
commit
68a654f9e8
5 changed files with 33 additions and 7 deletions
|
@ -21,7 +21,8 @@ class ActivityLogTransformer extends BaseClientTransformer
|
|||
'event' => $model->event,
|
||||
'ip' => $model->ip,
|
||||
'description' => $model->description,
|
||||
'properties' => $model->properties,
|
||||
'properties' => $model->properties ? $model->properties->toArray() : [],
|
||||
'has_additional_metadata' => $this->hasAdditionalMetadata($model),
|
||||
'timestamp' => $model->timestamp->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
@ -34,4 +35,32 @@ class ActivityLogTransformer extends BaseClientTransformer
|
|||
|
||||
return $this->item($model->actor, $this->makeTransformer(UserTransformer::class), User::RESOURCE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if there are any log properties that we've not already exposed
|
||||
* in the response language string and that are not just the IP address or
|
||||
* the browser useragent.
|
||||
*
|
||||
* This is used by the front-end to selectively display an "additional metadata"
|
||||
* button that is pointless if there is nothing the user can't already see from
|
||||
* the event description.
|
||||
*/
|
||||
protected function hasAdditionalMetadata(ActivityLog $model): bool
|
||||
{
|
||||
if (is_null($model->properties) || $model->properties->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$str = trans('activity.' . str_replace(':', '.', $model->event));
|
||||
preg_match_all('/:(?<key>[\w-]+)(?:\W?|$)/', $str, $matches);
|
||||
|
||||
$exclude = array_merge($matches['key'], ['ip', 'useragent']);
|
||||
foreach ($model->properties->keys() as $key) {
|
||||
if (!in_array($key, $exclude, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue