Skip to content

Commit

Permalink
fix(logging): user log condition feature
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <[email protected]>
  • Loading branch information
come-nc authored and miaulalala committed Aug 28, 2023
1 parent 3ea5c47 commit 85ad59e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/private/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@

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\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IUserSession;
use OCP\Log\BeforeMessageLoggedEvent;
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;

/**
Expand Down Expand Up @@ -247,7 +250,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();
Expand All @@ -268,10 +270,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;
}
}
Expand Down

0 comments on commit 85ad59e

Please sign in to comment.