diff options
author | Joas Schilling <coding@schilljs.com> | 2021-04-09 10:32:45 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-04-09 10:32:45 +0200 |
commit | ca939214bd8c7f481da7bda290f82508d6a5792a (patch) | |
tree | 5ad657e6fb47b2c4bba754da6022c577963b4033 /apps/admin_audit/lib | |
parent | 4d390770d1c7834cad9b313db1797336a8997773 (diff) | |
download | nextcloud-server-ca939214bd8c7f481da7bda290f82508d6a5792a.tar.gz nextcloud-server-ca939214bd8c7f481da7bda290f82508d6a5792a.zip |
Allow apps to log actions into the audit_log
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/admin_audit/lib')
-rw-r--r-- | apps/admin_audit/lib/AppInfo/Application.php | 3 | ||||
-rw-r--r-- | apps/admin_audit/lib/Listener/AuditEventListener.php | 44 |
2 files changed, 47 insertions, 0 deletions
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index d7afb96ea87..47290e0525d 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -49,6 +49,7 @@ use OCA\AdminAudit\Actions\Sharing; use OCA\AdminAudit\Actions\Trashbin; use OCA\AdminAudit\Actions\UserManagement; use OCA\AdminAudit\Actions\Versions; +use OCA\AdminAudit\Listener\AuditEventListener; use OCP\App\ManagerEvent; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -61,6 +62,7 @@ use OCP\IGroupManager; use OCP\IPreview; use OCP\IServerContainer; use OCP\IUserSession; +use OCP\Log\AuditEvent; use OCP\Log\ILogFactory; use OCP\Share; use OCP\Util; @@ -78,6 +80,7 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { + $context->registerEventListener(AuditEvent::class, AuditEventListener::class); } public function boot(IBootContext $context): void { diff --git a/apps/admin_audit/lib/Listener/AuditEventListener.php b/apps/admin_audit/lib/Listener/AuditEventListener.php new file mode 100644 index 00000000000..0e2e5561858 --- /dev/null +++ b/apps/admin_audit/lib/Listener/AuditEventListener.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\AdminAudit\Listener; + +use OCA\AdminAudit\Actions\Action; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Log\AuditEvent; + +class AuditEventListener extends Action implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof AuditEvent)) { + return; + } + + $this->log( + $event->getLogMessage(), + $event->getParameters(), + array_keys($event->getParameters()), + $event->getObfuscateParameters() + ); + } +} |