Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] Allow injecting the user temporarily for direct editing #46677

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/files_external/lib/Migration/DummyUserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
use OCP\IUserSession;

class DummyUserSession implements IUserSession {

/**
* @var IUser
*/
private $user;
private ?IUser $user = null;

public function login($uid, $password) {
}
Expand All @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/private/DirectEditing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 3 additions & 1 deletion lib/private/legacy/OC_User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions lib/public/IUserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading