diff --git a/apps/admin_audit/lib/Actions/Action.php b/apps/admin_audit/lib/Actions/Action.php index bfd67f474f943..5926548026b00 100644 --- a/apps/admin_audit/lib/Actions/Action.php +++ b/apps/admin_audit/lib/Actions/Action.php @@ -31,10 +31,10 @@ use OCA\AdminAudit\IAuditLogger; class Action { - public function __construct( private IAuditLogger $logger, - ) {} + ) { + } /** * Log a single action with a log level of info @@ -49,23 +49,26 @@ public function log(string $text, array $elements, 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( - sprintf( - '$params["'.$element.'"] was missing. Transferred value: %s', - print_r($params, true) - ), - ['app' => 'admin_audit'] - ); - } - return; + if (isset($params[$element])) { + continue; } + + if ($obfuscateParameters) { + $this->logger->critical( + '$params["'.$element.'"] was missing.', + ['app' => 'admin_audit'] + ); + } else { + $this->logger->critical( + sprintf( + '$params["'.$element.'"] was missing. Transferred value: %s', + print_r($params, true) + ), + ['app' => 'admin_audit'] + ); + } + + return; } $replaceArray = []; diff --git a/apps/admin_audit/lib/Actions/AppManagement.php b/apps/admin_audit/lib/Actions/AppManagement.php index d6bc7d2c61f26..7bd8cf4e607b8 100644 --- a/apps/admin_audit/lib/Actions/AppManagement.php +++ b/apps/admin_audit/lib/Actions/AppManagement.php @@ -27,7 +27,6 @@ namespace OCA\AdminAudit\Actions; class AppManagement extends Action { - /** * @param string $appName */ diff --git a/apps/admin_audit/lib/Actions/GroupManagement.php b/apps/admin_audit/lib/Actions/GroupManagement.php index e79b86bb88bcc..0b548b981aba5 100644 --- a/apps/admin_audit/lib/Actions/GroupManagement.php +++ b/apps/admin_audit/lib/Actions/GroupManagement.php @@ -38,7 +38,6 @@ * @package OCA\AdminAudit\Actions */ class GroupManagement extends Action { - /** * log add user to group event * diff --git a/apps/admin_audit/lib/Actions/Sharing.php b/apps/admin_audit/lib/Actions/Sharing.php index 5cb3602deae7e..c8637e40335c7 100644 --- a/apps/admin_audit/lib/Actions/Sharing.php +++ b/apps/admin_audit/lib/Actions/Sharing.php @@ -44,136 +44,168 @@ class Sharing extends Action { * @param array $params */ public function shared(array $params): void { - if ($params['shareType'] === IShare::TYPE_LINK) { - $this->log( - 'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_USER) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_ROOM) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_EMAIL) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_DECK) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) { - $this->log( - 'The %s "%s" with ID "%s" has been shared to the ScienceMesh user "%s" with permissions "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'path', - 'itemSource', - 'shareWith', - 'permissions', - 'id', - ] - ); - } + match ($params['shareType']) { + IShare::TYPE_LINK => $this->sharedLinkType($params), + IShare::TYPE_USER => $this->sharedUserType($params), + IShare::TYPE_GROUP => $this->sharedGroupType($params), + IShare::TYPE_ROOM => $this->sharedRoomType($params), + IShare::TYPE_EMAIL => $this->sharedEmailType($params), + IShare::TYPE_CIRCLE => $this->sharedCircleType($params), + IShare::TYPE_REMOTE => $this->sharedRemoteType($params), + IShare::TYPE_REMOTE_GROUP => $this->sharedRemoteGroupType($params), + IShare::TYPE_DECK => $this->sharedDeckType($params), + IShare::TYPE_SCIENCEMESH => $this->sharedSciencemeshType($params), + default => null, + }; + } + + protected function sharedLinkType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'permissions', + 'id', + ] + ); + } + + protected function sharedUserType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedRoomType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedEmailType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedCircleType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedRemoteType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedRemoteGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedDeckType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); + } + + protected function sharedSciencemeshType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been shared to the ScienceMesh user "%s" with permissions "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'path', + 'itemSource', + 'shareWith', + 'permissions', + 'id', + ] + ); } /** @@ -182,126 +214,158 @@ public function shared(array $params): void { * @param array $params */ public function unshare(array $params): void { - if ($params['shareType'] === IShare::TYPE_LINK) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_USER) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_ROOM) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_EMAIL) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_DECK) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) { - $this->log( - 'The %s "%s" with ID "%s" has been unshared from the ScienceMesh user "%s" (Share ID: %s)', - $params, - [ - 'itemType', - 'fileTarget', - 'itemSource', - 'shareWith', - 'id', - ] - ); - } + match ($params['shareType']) { + IShare::TYPE_LINK => $this->unshareLinkType($params), + IShare::TYPE_USER => $this->unshareUserType($params), + IShare::TYPE_GROUP => $this->unshareGroupType($params), + IShare::TYPE_ROOM => $this->unshareRoomType($params), + IShare::TYPE_EMAIL => $this->unshareEmailType($params), + IShare::TYPE_CIRCLE => $this->unshareCircleType($params), + IShare::TYPE_REMOTE => $this->unshareRemoteType($params), + IShare::TYPE_REMOTE_GROUP => $this->unshareRemoteGroupType($params), + IShare::TYPE_DECK => $this->unshareDeckType($params), + IShare::TYPE_SCIENCEMESH => $this->unshareSciencemeshType($params), + default => null, + }; + } + + protected function unshareLinkType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'id', + ] + ); + } + + protected function unshareUserType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the user "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the group "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareRoomType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the room "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareEmailType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the email recipient "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareCircleType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the circle "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareRemoteType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the remote user "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareRemoteGroupType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the remote group "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareDeckType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the deck card "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); + } + + protected function unshareSciencemeshType(array $params): void { + $this->log( + 'The %s "%s" with ID "%s" has been unshare from the ScienceMesh user "%s" (Share ID: %s)', + $params, + [ + 'itemType', + 'fileTarget', + 'itemSource', + 'shareWith', + 'id', + ] + ); } /** diff --git a/apps/admin_audit/lib/Actions/UserManagement.php b/apps/admin_audit/lib/Actions/UserManagement.php index 02d5b60d2fa29..c66793d8a5b33 100644 --- a/apps/admin_audit/lib/Actions/UserManagement.php +++ b/apps/admin_audit/lib/Actions/UserManagement.php @@ -61,7 +61,7 @@ public function create(array $params): void { */ public function assign(string $uid): void { $this->log( - 'UserID assigned: "%s"', + 'UserID assigned: "%s"', [ 'uid' => $uid ], [ 'uid' ] ); diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 1daf9f18ef07b..1563ae53c188a 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -60,6 +60,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IGroupManager; +use OCP\IServerContainer; use OCP\IUserSession; use OCP\Log\Audit\CriticalActionPerformedEvent; use OCP\Log\ILogFactory; @@ -70,7 +71,6 @@ use Psr\Log\LoggerInterface; class Application extends App implements IBootstrap { - /** @var LoggerInterface */ protected $logger; diff --git a/apps/admin_audit/lib/AuditLogger.php b/apps/admin_audit/lib/AuditLogger.php index 0a7a330a7434e..6bb434c883797 100644 --- a/apps/admin_audit/lib/AuditLogger.php +++ b/apps/admin_audit/lib/AuditLogger.php @@ -31,9 +31,7 @@ * Logger that logs in the audit log file instead of the normal log file */ class AuditLogger implements IAuditLogger { - - /** @var LoggerInterface */ - private $parentLogger; + private LoggerInterface $parentLogger; public function __construct(ILogFactory $logFactory, IConfig $config) { $auditType = $config->getSystemValueString('log_type_audit', 'file'); @@ -50,39 +48,39 @@ public function __construct(ILogFactory $logFactory, IConfig $config) { $this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); } - public function emergency($message, array $context = array()) { + public function emergency($message, array $context = []): void { $this->parentLogger->emergency($message, $context); } - public function alert($message, array $context = array()) { + public function alert($message, array $context = []): void { $this->parentLogger->alert($message, $context); } - public function critical($message, array $context = array()) { + public function critical($message, array $context = []): void { $this->parentLogger->critical($message, $context); } - public function error($message, array $context = array()) { + public function error($message, array $context = []): void { $this->parentLogger->error($message, $context); } - public function warning($message, array $context = array()) { + public function warning($message, array $context = []): void { $this->parentLogger->warning($message, $context); } - public function notice($message, array $context = array()) { + public function notice($message, array $context = []): void { $this->parentLogger->notice($message, $context); } - public function info($message, array $context = array()) { + public function info($message, array $context = []): void { $this->parentLogger->info($message, $context); } - public function debug($message, array $context = array()) { + public function debug($message, array $context = []): void { $this->parentLogger->debug($message, $context); } - public function log($level, $message, array $context = array()) { + public function log($level, $message, array $context = []): void { $this->parentLogger->log($level, $message, $context); } }