diff --git a/apps/files_external/lib/Migration/DummyUserSession.php b/apps/files_external/lib/Migration/DummyUserSession.php index e1b2b500188c5..a5956ed7bc837 100644 --- a/apps/files_external/lib/Migration/DummyUserSession.php +++ b/apps/files_external/lib/Migration/DummyUserSession.php @@ -28,11 +28,7 @@ use OCP\IUserSession; class DummyUserSession implements IUserSession { - - /** - * @var IUser - */ - private $user; + private ?IUser $user = null; public function login($uid, $password) { } @@ -44,6 +40,10 @@ public function setUser($user) { $this->user = $user; } + public function setVolatileActiveUser(?IUser $user): void { + $this->user = $user; + } + public function getUser() { return $this->user; } diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index 2dd2abe54085b..a85319a9fc216 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -272,13 +272,11 @@ public function accessToken(string $token): bool { } public function invokeTokenScope($userId): void { - \OC_User::setIncognitoMode(true); \OC_User::setUserId($userId); } public function revertTokenScope(): void { $this->userSession->setUser(null); - \OC_User::setIncognitoMode(false); } public function createToken($editorId, File $file, string $filePath, IShare $share = null): string { diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index e7a9980262e71..32391e35adfc4 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -181,6 +181,15 @@ public function setUser($user) { $this->activeUser = $user; } + /** + * Temporarily set the currently active user without persisting in the session + * + * @param IUser|null $user + */ + public function setVolatileActiveUser(?IUser $user): void { + $this->activeUser = $user; + } + /** * get the current active user * diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php index 7943be9d1c57d..768237f96c99f 100644 --- a/lib/private/legacy/OC_User.php +++ b/lib/private/legacy/OC_User.php @@ -39,7 +39,9 @@ use OC\User\LoginException; use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; +use OCP\ISession; use OCP\IUserManager; +use OCP\Server; use OCP\User\Events\BeforeUserLoggedInEvent; use OCP\User\Events\UserLoggedInEvent; @@ -349,7 +351,7 @@ public static function isAdminUser($uid) { * @return string|false uid or false */ public static function getUser() { - $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null; + $uid = Server::get(ISession::class)?->get('user_id'); if (!is_null($uid) && self::$incognitoMode === false) { return $uid; } else { diff --git a/lib/public/IUserSession.php b/lib/public/IUserSession.php index 7bc37cc67c6a1..7512a18fee42a 100644 --- a/lib/public/IUserSession.php +++ b/lib/public/IUserSession.php @@ -63,6 +63,14 @@ public function logout(); */ public function setUser($user); + /** + * Temporarily set the currently active user without persisting in the session + * + * @param IUser|null $user + * @since 27.1.12 + */ + public function setVolatileActiveUser(?IUser $user): void; + /** * get the current active user *