aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-10-03 10:56:42 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-10-03 16:19:30 +0200
commitbc125c982b97f88b292c99687bf878d61585ec2f (patch)
tree26a87af6d22a4c4dccc0f080f867483b9dd80524
parentfaf9b891e68841b43e6af9654f511b8296967b50 (diff)
downloadnextcloud-server-bc125c982b97f88b292c99687bf878d61585ec2f.tar.gz
nextcloud-server-bc125c982b97f88b292c99687bf878d61585ec2f.zip
fix(admin_audit): Listen to the right eventsbackport/48548/stable30
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/admin_audit/lib/Actions/Files.php48
-rw-r--r--apps/admin_audit/lib/AppInfo/Application.php18
2 files changed, 10 insertions, 56 deletions
diff --git a/apps/admin_audit/lib/Actions/Files.php b/apps/admin_audit/lib/Actions/Files.php
index bba5b427aee..e31c4413f6b 100644
--- a/apps/admin_audit/lib/Actions/Files.php
+++ b/apps/admin_audit/lib/Actions/Files.php
@@ -8,12 +8,11 @@ declare(strict_types=1);
namespace OCA\AdminAudit\Actions;
use OC\Files\Node\NonExistingFile;
+use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
use OCP\Files\Events\Node\BeforeNodeReadEvent;
use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
-use OCP\Files\Events\Node\BeforeNodeWrittenEvent;
use OCP\Files\Events\Node\NodeCopiedEvent;
use OCP\Files\Events\Node\NodeCreatedEvent;
-use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\InvalidPathException;
@@ -29,10 +28,9 @@ use Psr\Log\LoggerInterface;
class Files extends Action {
private array $renamedNodes = [];
+
/**
* Logs file read actions
- *
- * @param BeforeNodeReadEvent $event
*/
public function read(BeforeNodeReadEvent $event): void {
try {
@@ -56,8 +54,6 @@ class Files extends Action {
/**
* Logs rename actions of files
- *
- * @param BeforeNodeRenamedEvent $event
*/
public function beforeRename(BeforeNodeRenamedEvent $event): void {
try {
@@ -73,8 +69,6 @@ class Files extends Action {
/**
* Logs rename actions of files
- *
- * @param NodeRenamedEvent $event
*/
public function afterRename(NodeRenamedEvent $event): void {
try {
@@ -102,8 +96,6 @@ class Files extends Action {
/**
* Logs creation of files
- *
- * @param NodeCreatedEvent $event
*/
public function create(NodeCreatedEvent $event): void {
try {
@@ -129,8 +121,6 @@ class Files extends Action {
/**
* Logs copying of files
- *
- * @param NodeCopiedEvent $event
*/
public function copy(NodeCopiedEvent $event): void {
try {
@@ -155,14 +145,12 @@ class Files extends Action {
/**
* Logs writing of files
- *
- * @param BeforeNodeWrittenEvent $event
*/
- public function write(BeforeNodeWrittenEvent $event): void {
+ public function write(NodeWrittenEvent $event): void {
$node = $event->getNode();
try {
$params = [
- 'id' => $node instanceof NonExistingFile ? null : $node->getId(),
+ 'id' => $node->getId(),
'path' => mb_substr($node->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
@@ -183,35 +171,9 @@ class Files extends Action {
}
/**
- * Logs update of files
- *
- * @param NodeWrittenEvent $event
- */
- public function update(NodeWrittenEvent $event): void {
- try {
- $params = [
- 'id' => $event->getNode()->getId(),
- 'path' => mb_substr($event->getNode()->getInternalPath(), 5),
- ];
- } catch (InvalidPathException|NotFoundException $e) {
- \OCP\Server::get(LoggerInterface::class)->error(
- "Exception thrown in file update: ".$e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
- );
- return;
- }
- $this->log(
- 'File with id "%s" updated: "%s"',
- $params,
- array_keys($params)
- );
- }
-
- /**
* Logs deletions of files
- *
- * @param NodeDeletedEvent $event
*/
- public function delete(NodeDeletedEvent $event): void {
+ public function delete(BeforeNodeDeletedEvent $event): void {
try {
$params = [
'id' => $event->getNode()->getId(),
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php
index 79c6640e2e2..a95ba0e684a 100644
--- a/apps/admin_audit/lib/AppInfo/Application.php
+++ b/apps/admin_audit/lib/AppInfo/Application.php
@@ -32,12 +32,11 @@ use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengeFailed;
use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed;
use OCP\Console\ConsoleEvent;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
use OCP\Files\Events\Node\BeforeNodeReadEvent;
use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
-use OCP\Files\Events\Node\BeforeNodeWrittenEvent;
use OCP\Files\Events\Node\NodeCopiedEvent;
use OCP\Files\Events\Node\NodeCreatedEvent;
-use OCP\Files\Events\Node\NodeDeletedEvent;
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\IConfig;
@@ -218,16 +217,9 @@ class Application extends App implements IBootstrap {
);
$eventDispatcher->addListener(
- BeforeNodeWrittenEvent::class,
- function (BeforeNodeWrittenEvent $event) use ($fileActions) {
- $fileActions->write($event);
- }
- );
-
- $eventDispatcher->addListener(
NodeWrittenEvent::class,
- function (NodeWrittenEvent $event) use ($fileActions) {
- $fileActions->update($event);
+ function (NodeWrittenEvent $event) use ($fileActions): void {
+ $fileActions->write($event);
}
);
@@ -239,8 +231,8 @@ class Application extends App implements IBootstrap {
);
$eventDispatcher->addListener(
- NodeDeletedEvent::class,
- function (NodeDeletedEvent $event) use ($fileActions) {
+ BeforeNodeDeletedEvent::class,
+ function (BeforeNodeDeletedEvent $event) use ($fileActions): void {
$fileActions->delete($event);
}
);