From e763d0bb99778ab7e449636762be56e3efed3d64 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Fri, 4 Nov 2022 09:41:18 +0100 Subject: [PATCH] DirectEditing: Set session user for DirectSession editing to have it available for the file put activities event fixes https://github.com/nextcloud/android/issues/10237 fixes #2821 Signed-off-by: Marcel Klehr --- lib/Controller/DirectSessionController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Controller/DirectSessionController.php b/lib/Controller/DirectSessionController.php index aad732e57b2..93bf09f17ec 100644 --- a/lib/Controller/DirectSessionController.php +++ b/lib/Controller/DirectSessionController.php @@ -53,6 +53,8 @@ use OCP\DirectEditing\IManager; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; +use OCP\IUserManager; +use OCP\IUserSession; use OCP\Share\IShare; class DirectSessionController extends Controller { @@ -64,6 +66,8 @@ public function __construct(string $appName, IRequest $request, ApiService $apiS parent::__construct($appName, $request); $this->apiService = $apiService; $this->directManager = $directManager; + $this->userSession = $userSession; + $this->userManager = $userManager; } /** @@ -106,6 +110,7 @@ public function close(int $documentId, int $sessionId, string $sessionToken): Da * @PublicPage */ public function push(int $documentId, int $sessionId, string $sessionToken, int $version, array $steps, string $token): DataResponse { + $this->loginTokenUser($token); return $this->apiService->push($documentId, $sessionId, $sessionToken, $version, $steps, $token); } @@ -114,6 +119,7 @@ public function push(int $documentId, int $sessionId, string $sessionToken, int * @PublicPage */ public function sync(string $token, int $documentId, int $sessionId, string $sessionToken, int $version = 0, string $autosaveContent = null, bool $force = false, bool $manualSave = false): DataResponse { + $this->loginTokenUser($token); return $this->apiService->sync($documentId, $sessionId, $sessionToken, $version, $autosaveContent, $force, $manualSave, $token); } @@ -124,4 +130,12 @@ public function sync(string $token, int $documentId, int $sessionId, string $ses public function updateSession(int $documentId, int $sessionId, string $sessionToken, string $guestName) { return $this->apiService->updateSession($documentId, $sessionId, $sessionToken, $guestName); } + + private function loginTokenUser(string $token) { + $tokenObject = $this->directManager->getToken($token); + $user = $this->userManager->get($tokenObject->getUser()); + if ($user !== null) { + $this->userSession->setUser($user); + } + } }