From 66c6bc01b6032bc156a4cc139246a63d8f9cacd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 19 Jun 2023 09:35:46 +0200 Subject: [PATCH] fix(logging): user log condition feature Signed-off-by: Anna Larch --- lib/private/Log.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/private/Log.php b/lib/private/Log.php index 4ab647bc6c155..953f6071f4a8d 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -38,15 +38,16 @@ use Exception; use Nextcloud\LogNormalizer\Normalizer; -use OC\AppFramework\Bootstrap\Coordinator; -use OCP\Log\IDataLogger; -use Throwable; -use function array_merge; -use OC\Log\ExceptionSerializer; use OCP\ILogger; +use OCP\IUserSession; +use OCP\Log\IDataLogger; use OCP\Log\IFileBased; use OCP\Log\IWriter; use OCP\Support\CrashReport\IRegistry; +use OC\AppFramework\Bootstrap\Coordinator; +use OC\Log\ExceptionSerializer; +use Throwable; +use function array_merge; use function strtr; /** @@ -59,7 +60,6 @@ * MonoLog is an example implementing this interface. */ class Log implements ILogger, IDataLogger { - /** @var IWriter */ private $logger; @@ -247,7 +247,6 @@ public function getLogLevel($context) { // default to false to just process this once per request $this->logConditionSatisfied = false; if (!empty($logCondition)) { - // check for secret token in the request if (isset($logCondition['shared_secret'])) { $request = \OC::$server->getRequest(); @@ -268,10 +267,13 @@ public function getLogLevel($context) { // check for user if (isset($logCondition['users'])) { - $user = \OC::$server->getUserSession()->getUser(); + $user = \OCP\Server::get(IUserSession::class)->getUser(); - // if the user matches set the log condition to satisfied - if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) { + if ($user === null) { + // User is not known for this request yet + $this->logConditionSatisfied = null; + } elseif (in_array($user->getUID(), $logCondition['users'], true)) { + // if the user matches set the log condition to satisfied $this->logConditionSatisfied = true; } }