diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2024-07-25 19:41:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 19:41:20 +0200 |
commit | f02bbf8eb69a9554b9f2f0a967d918c200cea8bd (patch) | |
tree | 97faba2c91610c7d59e4e95d9ceb6985e3e89c70 /lib | |
parent | 942a91916aa6713a347717e451228d5417bd568e (diff) | |
parent | be5d40e3e277aac5fc6939922c8b18094c20c9b8 (diff) | |
download | nextcloud-server-f02bbf8eb69a9554b9f2f0a967d918c200cea8bd.tar.gz nextcloud-server-f02bbf8eb69a9554b9f2f0a967d918c200cea8bd.zip |
Merge pull request #46678 from nextcloud/backport/44295/stable28
[stable28] Allow injecting the user temporarily for direct editing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 2 | ||||
-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, 19 insertions, 3 deletions
diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index d1be1f50330..a527dcd6c9e 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -272,13 +272,11 @@ class Manager implements IManager { } 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 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..1174c492fef 100644 --- a/lib/private/legacy/OC_User.php +++ b/lib/private/legacy/OC_User.php @@ -39,6 +39,7 @@ use OC\Authentication\Token\IProvider; use OC\User\LoginException; use OCP\EventDispatcher\IEventDispatcher; use OCP\IGroupManager; +use OCP\ISession; use OCP\IUser; use OCP\IUserManager; use OCP\Server; @@ -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(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 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 |