Skip to content

Commit 468f4e3

Browse files
committed
DirectEditing: Set session user for DirectSession editing
to have it available for the file put activities event fixes nextcloud/android#10237 fixes #2821 Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 242f36a commit 468f4e3

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/Controller/DirectSessionController.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,25 @@
5353
use OCP\DirectEditing\IManager;
5454
use OCP\AppFramework\Http\DataResponse;
5555
use OCP\IRequest;
56+
use OCP\IUserManager;
57+
use OCP\IUserSession;
5658
use OCP\Share\IShare;
5759

5860
class DirectSessionController extends Controller {
59-
private IShare $share;
6061
private ApiService $apiService;
6162
private IManager $directManager;
63+
private IUserSession $userSession;
64+
/**
65+
* @var \OCP\IUserManager
66+
*/
67+
private IUserManager $userManager;
6268

63-
public function __construct(string $appName, IRequest $request, ApiService $apiService, IManager $directManager) {
69+
public function __construct(string $appName, IRequest $request, ApiService $apiService, IManager $directManager, IUserSession $userSession, IUserManager $userManager) {
6470
parent::__construct($appName, $request);
6571
$this->apiService = $apiService;
6672
$this->directManager = $directManager;
73+
$this->userSession = $userSession;
74+
$this->userManager = $userManager;
6775
}
6876

6977
/**
@@ -106,6 +114,7 @@ public function close(int $documentId, int $sessionId, string $sessionToken): Da
106114
* @PublicPage
107115
*/
108116
public function push(int $documentId, int $sessionId, string $sessionToken, int $version, array $steps, string $token): DataResponse {
117+
$this->loginTokenUser($token);
109118
return $this->apiService->push($documentId, $sessionId, $sessionToken, $version, $steps, $token);
110119
}
111120

@@ -114,6 +123,7 @@ public function push(int $documentId, int $sessionId, string $sessionToken, int
114123
* @PublicPage
115124
*/
116125
public function sync(string $token, int $documentId, int $sessionId, string $sessionToken, int $version = 0, string $autosaveContent = null, bool $force = false, bool $manualSave = false): DataResponse {
126+
$this->loginTokenUser($token);
117127
return $this->apiService->sync($documentId, $sessionId, $sessionToken, $version, $autosaveContent, $force, $manualSave, $token);
118128
}
119129

@@ -124,4 +134,12 @@ public function sync(string $token, int $documentId, int $sessionId, string $ses
124134
public function updateSession(int $documentId, int $sessionId, string $sessionToken, string $guestName) {
125135
return $this->apiService->updateSession($documentId, $sessionId, $sessionToken, $guestName);
126136
}
137+
138+
private function loginTokenUser(string $token) {
139+
$tokenObject = $this->directManager->getToken($token);
140+
$user = $this->userManager->get($tokenObject->getUser());
141+
if ($user !== null) {
142+
$this->userSession->setUser($user);
143+
}
144+
}
127145
}

0 commit comments

Comments
 (0)