diff --git a/lib/Controller/SessionController.php b/lib/Controller/SessionController.php index 8e297ab49aa..9c6b66d5849 100644 --- a/lib/Controller/SessionController.php +++ b/lib/Controller/SessionController.php @@ -32,17 +32,23 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\Response; use OCP\IRequest; +use OCP\IUserManager; +use OCP\IUserSession; class SessionController extends Controller { private ApiService $apiService; private SessionService $sessionService; private NotificationService $notificationService; + private IUserManager $userManager; + private IUserSession $userSession; - public function __construct(string $appName, IRequest $request, ApiService $apiService, SessionService $sessionService, NotificationService $notificationService) { + public function __construct(string $appName, IRequest $request, ApiService $apiService, SessionService $sessionService, NotificationService $notificationService, IUserManager $userManager, IUserSession $userSession) { parent::__construct($appName, $request); $this->apiService = $apiService; $this->sessionService = $sessionService; $this->notificationService = $notificationService; + $this->userManager = $userManager; + $this->userSession = $userSession; } /** @@ -73,6 +79,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): DataResponse { + $this->loginSessionUser($documentId, $sessionId, $sessionToken); return $this->apiService->push($documentId, $sessionId, $sessionToken, $version, $steps); } @@ -81,6 +88,7 @@ public function push(int $documentId, int $sessionId, string $sessionToken, int * @PublicPage */ public function sync(int $documentId, int $sessionId, string $sessionToken, int $version = 0, string $autosaveContent = null, bool $force = false, bool $manualSave = false): DataResponse { + $this->loginSessionUser($documentId, $sessionId, $sessionToken); return $this->apiService->sync($documentId, $sessionId, $sessionToken, $version, $autosaveContent, $force, $manualSave); } @@ -102,4 +110,12 @@ public function mention(int $documentId, int $sessionId, string $sessionToken, s return new DataResponse($this->notificationService->mention($documentId, $mention)); } + + private function loginSessionUser(int $documentId, int $sessionId, string $sessionToken) { + $currentSession = $this->sessionService->getSession($documentId, $sessionId, $sessionToken); + $user = $this->userManager->get($currentSession->getUserId()); + if ($user !== null) { + $this->userSession->setUser($user); + } + } }