From ce7da62a8807593b63a5f26a788dee8122b8278b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 12 May 2022 11:11:45 +0200 Subject: [PATCH] Revert lazy use of userId in ConfigService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/ConfigService.php | 14 ++++++++++---- tests/integration/app/AppTest.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 00a42030e..cceb4a43f 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -32,6 +32,7 @@ use OCA\Deck\NoPermissionException; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; +use OCP\IUserSession; class ConfigService { public const SETTING_BOARD_NOTIFICATION_DUE_OFF = 'off'; @@ -40,20 +41,25 @@ class ConfigService { public const SETTING_BOARD_NOTIFICATION_DUE_DEFAULT = self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED; private IConfig $config; - private ?string $userId; + private ?string $userId = null; private IGroupManager $groupManager; public function __construct( IConfig $config, - IGroupManager $groupManager, - ?string $userId + IGroupManager $groupManager ) { $this->groupManager = $groupManager; $this->config = $config; - $this->userId = $userId; } public function getUserId(): ?string { + if (!$this->userId) { + // We cannot use DI for the userId or UserSession as the ConfigService + // is initiated too early before the session is actually loaded + $user = \OCP\Server::get(IUserSession::class)->getUser(); + $this->userId = $user ? $user->getUID() : null; + } + return $this->userId; } diff --git a/tests/integration/app/AppTest.php b/tests/integration/app/AppTest.php index c25e0c513..399de955b 100644 --- a/tests/integration/app/AppTest.php +++ b/tests/integration/app/AppTest.php @@ -34,7 +34,7 @@ class AppTest extends TestCase { public function setUp(): void { parent::setUp(); - $this->app = new \OCA\Deck\AppInfo\Application(); + $this->app = \OCP\Server::get(\OCA\Deck\AppInfo\Application::class); $this->container = $this->app->getContainer(); }