diff --git a/lib/CurrentUser.php b/lib/CurrentUser.php index ee1adf2a7..40256121a 100644 --- a/lib/CurrentUser.php +++ b/lib/CurrentUser.php @@ -17,13 +17,6 @@ class CurrentUser { - /** @var string|null */ - protected $identifier = null; - /** @var string|false|null */ - protected $cloudId = false; - /** @var string|false|null */ - protected $sessionUser = false; - public function __construct( protected IUserSession $userSession, protected IRequest $request, @@ -41,31 +34,23 @@ public function getUser(): ?IUser { * @return string */ public function getUserIdentifier() { - if ($this->identifier !== null) { - return $this->identifier; - } - $uid = $this->getUID(); if ($uid !== null) { - $this->identifier = $uid; - return $this->identifier; + return $uid; } $cloudId = $this->getCloudIDFromToken(); if ($cloudId !== null) { - $this->identifier = $cloudId; - return $this->identifier; + return $cloudId; } $nickname = htmlspecialchars($this->request->getHeader('X-NC-Nickname')); if ($nickname !== '') { - $this->identifier = $nickname . ' (' . $this->l10nFactory->get('comments')->t('remote user') . ')'; - return $this->identifier; + return $nickname . ' (' . $this->l10nFactory->get('comments')->t('remote user') . ')'; } // Nothing worked, fallback to empty string - $this->identifier = ''; - return $this->identifier; + return ''; } /** @@ -73,16 +58,11 @@ public function getUserIdentifier() { * @return string|null */ public function getUID() { - if ($this->sessionUser === false) { - $user = $this->userSession->getUser(); - if ($user instanceof IUser) { - $this->sessionUser = $user->getUID(); - } else { - $this->sessionUser = null; - } + $user = $this->userSession->getUser(); + if ($user instanceof IUser) { + return (string)$user->getUID(); } - - return $this->sessionUser; + return null; } /** @@ -90,16 +70,12 @@ public function getUID() { * @return string|null */ public function getCloudId() { - if ($this->cloudId === false) { - $user = $this->userSession->getUser(); - if ($user instanceof IUser) { - $this->cloudId = (string)$user->getCloudId(); - } else { - $this->cloudId = $this->getCloudIDFromToken(); - } + $user = $this->userSession->getUser(); + if ($user instanceof IUser) { + return (string)$user->getCloudId(); + } else { + return $this->getCloudIDFromToken(); } - - return $this->cloudId; } /** diff --git a/tests/CurrentUserTest.php b/tests/CurrentUserTest.php index db447a55f..d24c29f13 100644 --- a/tests/CurrentUserTest.php +++ b/tests/CurrentUserTest.php @@ -85,7 +85,6 @@ public static function dataGetUserIdentifier(): array { [null, null, null, ''], [null, 'uid', -1, 'uid'], [null, null, 'token', 'token'], - ['cached', -1, -1, 'cached'], ]; } @@ -96,8 +95,6 @@ public function testGetUserIdentifier(?string $cachedIdentifier, string|int|null 'getCloudIDFromToken', ]); - self::invokePrivate($instance, 'identifier', [$cachedIdentifier]); - $instance->expects($uidResult !== -1 ? $this->once() : $this->never()) ->method('getUID') ->willReturn($uidResult);