diff options
author | Julius Härtl <jus@bitgrid.net> | 2024-03-19 11:12:03 +0100 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-07-22 12:44:21 +0000 |
commit | 1c75c5f1e098600c414915f22304436f25c974f7 (patch) | |
tree | 3ebf6de41cdc4d6da1c87d345bd367c300264a48 | |
parent | f413e80fedad5357723071983fc927a411b253dc (diff) | |
download | nextcloud-server-1c75c5f1e098600c414915f22304436f25c974f7.tar.gz nextcloud-server-1c75c5f1e098600c414915f22304436f25c974f7.zip |
fix: Implement option to temporarily set the user session
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | apps/files_external/lib/Migration/DummyUserSession.php | 9 | ||||
-rw-r--r-- | lib/private/User/Session.php | 9 | ||||
-rw-r--r-- | lib/private/legacy/OC_User.php | 3 | ||||
-rw-r--r-- | lib/public/IUserSession.php | 8 |
4 files changed, 24 insertions, 5 deletions
diff --git a/apps/files_external/lib/Migration/DummyUserSession.php b/apps/files_external/lib/Migration/DummyUserSession.php index e1b2b500188..ce987b3c575 100644 --- a/apps/files_external/lib/Migration/DummyUserSession.php +++ b/apps/files_external/lib/Migration/DummyUserSession.php @@ -29,10 +29,7 @@ use OCP\IUserSession; class DummyUserSession implements IUserSession { - /** - * @var IUser - */ - private $user; + private ?IUser $user = null; public function login($uid, $password) { } @@ -44,6 +41,10 @@ class DummyUserSession implements IUserSession { $this->user = $user; } + public function setVolatileActiveUser(?IUser $user): void { + $this->user = $user; + } + public function getUser() { return $this->user; } diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index dff3cefd0b9..c5a00aedcc6 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -183,6 +183,15 @@ class Session implements IUserSession, Emitter { } /** + * 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 * * @return IUser|null Current user, otherwise null diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php index 3d958814988..51bf0fd6049 100644 --- a/lib/private/legacy/OC_User.php +++ b/lib/private/legacy/OC_User.php @@ -41,6 +41,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; +use OCP\IUserSession; use OCP\Server; use OCP\User\Events\BeforeUserLoggedInEvent; use OCP\User\Events\UserLoggedInEvent; @@ -349,7 +350,7 @@ class OC_User { * @return string|false uid or false */ public static function getUser() { - $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null; + $uid = Server::get(IUserSession::class)->getUser()?->getUID(); if (!is_null($uid) && self::$incognitoMode === false) { return $uid; } else { diff --git a/lib/public/IUserSession.php b/lib/public/IUserSession.php index 7bc37cc67c6..dc6094550bc 100644 --- a/lib/public/IUserSession.php +++ b/lib/public/IUserSession.php @@ -64,6 +64,14 @@ interface IUserSession { public function setUser($user); /** + * Temporarily set the currently active user without persisting in the session + * + * @param IUser|null $user + * @since 29.0.0 + */ + public function setVolatileActiveUser(?IUser $user): void; + + /** * get the current active user * * @return \OCP\IUser|null Current user, otherwise null |