Revert lazy use of userId in ConfigService
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -32,6 +32,7 @@ use OCA\Deck\NoPermissionException;
|
|||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IGroup;
|
use OCP\IGroup;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IUserSession;
|
||||||
|
|
||||||
class ConfigService {
|
class ConfigService {
|
||||||
public const SETTING_BOARD_NOTIFICATION_DUE_OFF = 'off';
|
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;
|
public const SETTING_BOARD_NOTIFICATION_DUE_DEFAULT = self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
|
||||||
|
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private ?string $userId;
|
private ?string $userId = null;
|
||||||
private IGroupManager $groupManager;
|
private IGroupManager $groupManager;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager
|
||||||
?string $userId
|
|
||||||
) {
|
) {
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->userId = $userId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUserId(): ?string {
|
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;
|
return $this->userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class AppTest extends TestCase {
|
|||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->app = new \OCA\Deck\AppInfo\Application();
|
$this->app = \OCP\Server::get(\OCA\Deck\AppInfo\Application::class);
|
||||||
$this->container = $this->app->getContainer();
|
$this->container = $this->app->getContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user