From 4d228803f7fb009882e3ea909c6998237503eb6f Mon Sep 17 00:00:00 2001 From: yemkareems Date: Tue, 9 Apr 2024 12:10:12 +0530 Subject: feat: include file id in audit logs Signed-off-by: yemkareems --- apps/admin_audit/lib/AppInfo/Application.php | 93 +++++++++++++++------------- 1 file changed, 49 insertions(+), 44 deletions(-) (limited to 'apps/admin_audit/lib/AppInfo/Application.php') diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 860b7b70ae6..be060dc89a0 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -33,7 +33,6 @@ declare(strict_types=1); */ namespace OCA\AdminAudit\AppInfo; -use OC\Files\Filesystem; use OC\Group\Manager as GroupManager; use OC\User\Session as UserSession; use OCA\AdminAudit\Actions\AppManagement; @@ -58,6 +57,13 @@ use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengeFailed; use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed; use OCP\Console\ConsoleEvent; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\Node\BeforeNodeReadEvent; +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; use OCP\IGroupManager; use OCP\IUserSession; @@ -195,58 +201,57 @@ class Application extends App implements IBootstrap { $eventDispatcher->addListener( BeforePreviewFetchedEvent::class, function (BeforePreviewFetchedEvent $event) use ($fileActions) { - $file = $event->getNode(); - $fileActions->preview([ - 'path' => mb_substr($file->getInternalPath(), 5), - 'width' => $event->getWidth(), - 'height' => $event->getHeight(), - 'crop' => $event->isCrop(), - 'mode' => $event->getMode() - ]); + $fileActions->preview($event); } ); - Util::connectHook( - Filesystem::CLASSNAME, - Filesystem::signal_post_rename, - $fileActions, - 'rename' + $eventDispatcher->addListener( + NodeRenamedEvent::class, + function (NodeRenamedEvent $event) use ($fileActions) { + $fileActions->rename($event); + } ); - Util::connectHook( - Filesystem::CLASSNAME, - Filesystem::signal_post_create, - $fileActions, - 'create' + + $eventDispatcher->addListener( + NodeCreatedEvent::class, + function (NodeCreatedEvent $event) use ($fileActions) { + $fileActions->create($event); + } ); - Util::connectHook( - Filesystem::CLASSNAME, - Filesystem::signal_post_copy, - $fileActions, - 'copy' + + $eventDispatcher->addListener( + NodeCopiedEvent::class, + function (NodeCopiedEvent $event) use ($fileActions) { + $fileActions->copy($event); + } ); - Util::connectHook( - Filesystem::CLASSNAME, - Filesystem::signal_post_write, - $fileActions, - 'write' + + $eventDispatcher->addListener( + BeforeNodeWrittenEvent::class, + function (BeforeNodeWrittenEvent $event) use ($fileActions) { + $fileActions->write($event); + } ); - Util::connectHook( - Filesystem::CLASSNAME, - Filesystem::signal_post_update, - $fileActions, - 'update' + + $eventDispatcher->addListener( + NodeWrittenEvent::class, + function (NodeWrittenEvent $event) use ($fileActions) { + $fileActions->update($event); + } ); - Util::connectHook( - Filesystem::CLASSNAME, - Filesystem::signal_read, - $fileActions, - 'read' + + $eventDispatcher->addListener( + BeforeNodeReadEvent::class, + function (BeforeNodeReadEvent $event) use ($fileActions) { + $fileActions->read($event); + } ); - Util::connectHook( - Filesystem::CLASSNAME, - Filesystem::signal_delete, - $fileActions, - 'delete' + + $eventDispatcher->addListener( + NodeDeletedEvent::class, + function (NodeDeletedEvent $event) use ($fileActions) { + $fileActions->delete($event); + } ); } -- cgit v1.2.3