Skip to content

Commit

Permalink
Revert lazy use of userId in ConfigService
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed May 13, 2022
1 parent 3a783a7 commit ce7da62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserSession;

class ConfigService {
public const SETTING_BOARD_NOTIFICATION_DUE_OFF = 'off';
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/app/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit ce7da62

Please sign in to comment.