Merge pull request #63305 from nextcloud/jtr/fix-auditLog-files-null

fix(admin_audit): handle audit reads for new files
pull/58890/merge
Côme Chilliet 2 days ago committed by GitHub
commit 231ec6717c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 46
      apps/admin_audit/lib/Actions/Action.php
  2. 24
      apps/admin_audit/lib/Actions/Files.php

@ -21,47 +21,43 @@ class Action {
* Log a single action with a log level of info
*
* @param string $text
* @param array $params
* @param array $elements
* @param array<string, scalar|null|\DateTimeInterface> $params
* @param list<string> $elements
* @param bool $obfuscateParameters
*/
public function log(string $text,
public function log(
string $text,
array $params,
array $elements,
bool $obfuscateParameters = false): void {
bool $obfuscateParameters = false,
): void {
foreach ($elements as $element) {
if (!isset($params[$element])) {
if ($obfuscateParameters) {
$this->logger->critical(
'$params["' . $element . '"] was missing.',
['app' => 'admin_audit']
);
} else {
$this->logger->critical(
'$params["' . $element . '"] was missing. Transferred value: {params}',
['app' => 'admin_audit', 'params' => $params]
);
if (!array_key_exists($element, $params)) {
$message = '$params["' . $element . '"] was missing.';
$context = ['app' => 'admin_audit'];
if (!$obfuscateParameters) {
$message .= ' Transferred value: {params}';
$context['params'] = $params;
}
$this->logger->critical($message, $context);
return;
}
}
$replaceArray = [];
foreach ($elements as $element) {
if ($params[$element] instanceof \DateTime) {
$params[$element] = $params[$element]->format('Y-m-d H:i:s');
$value = $params[$element];
if ($value instanceof \DateTimeInterface) {
$value = $value->format('Y-m-d H:i:s');
}
$replaceArray[] = $params[$element];
$replaceArray[] = $value;
}
$this->logger->info(
vsprintf(
$text,
$replaceArray
),
[
'app' => 'admin_audit'
]
vsprintf($text, $replaceArray),
['app' => 'admin_audit'],
);
}
}

@ -33,7 +33,7 @@ class Files extends Action {
try {
$node = $event->getNode();
$params = [
'id' => $node instanceof NonExistingFile ? null : $node->getId(),
'id' => $node instanceof NonExistingFile ? 'not-yet-assigned' : $node->getId(),
'path' => $node->getPath(),
];
} catch (InvalidPathException|NotFoundException $e) {
@ -80,9 +80,10 @@ class Files extends Action {
*/
public function create(NodeCreatedEvent $event): void {
try {
$node = $event->getNode();
$params = [
'id' => $event->getNode()->getId(),
'path' => $event->getNode()->getPath(),
'id' => $node->getId(),
'path' => $node->getPath(),
];
} catch (InvalidPathException|NotFoundException $e) {
Server::get(LoggerInterface::class)->error(
@ -105,11 +106,13 @@ class Files extends Action {
*/
public function copy(NodeCopiedEvent $event): void {
try {
$source = $event->getSource();
$target = $event->getTarget();
$params = [
'oldid' => $event->getSource()->getId(),
'newid' => $event->getTarget()->getId(),
'oldpath' => $event->getSource()->getPath(),
'newpath' => $event->getTarget()->getPath(),
'oldid' => $source->getId(),
'newid' => $target->getId(),
'oldpath' => $source->getPath(),
'newpath' => $target->getPath(),
];
} catch (InvalidPathException|NotFoundException $e) {
Server::get(LoggerInterface::class)->error(
@ -128,8 +131,8 @@ class Files extends Action {
* Logs writing of files
*/
public function write(NodeWrittenEvent $event): void {
$node = $event->getNode();
try {
$node = $event->getNode();
$params = [
'id' => $node->getId(),
'path' => $node->getPath(),
@ -156,9 +159,10 @@ class Files extends Action {
*/
public function delete(BeforeNodeDeletedEvent $event): void {
try {
$node = $event->getNode();
$params = [
'id' => $event->getNode()->getId(),
'path' => $event->getNode()->getPath(),
'id' => $node->getId(),
'path' => $node->getPath(),
];
} catch (InvalidPathException|NotFoundException $e) {
Server::get(LoggerInterface::class)->error(

Loading…
Cancel
Save