Skip to content

Commit

Permalink
DirectEditing: Set session user for DirectSession editing
Browse files Browse the repository at this point in the history
to have it available for the file put activities event

fixes nextcloud/android#10237
fixes #2821

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr authored and backportbot-nextcloud[bot] committed Nov 7, 2022
1 parent 46e93fd commit 071865c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/Controller/DirectSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,25 @@
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 {
private IShare $share;
private ApiService $apiService;
private IManager $directManager;
private IUserSession $userSession;
/**
* @var \OCP\IUserManager
*/
private IUserManager $userManager;

public function __construct(string $appName, IRequest $request, ApiService $apiService, IManager $directManager) {
public function __construct(string $appName, IRequest $request, ApiService $apiService, IManager $directManager, IUserSession $userSession, IUserManager $userManager) {
parent::__construct($appName, $request);
$this->apiService = $apiService;
$this->directManager = $directManager;
$this->userSession = $userSession;
$this->userManager = $userManager;
}

/**
Expand Down Expand Up @@ -106,6 +114,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);
}

Expand All @@ -114,6 +123,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);
}

Expand All @@ -124,4 +134,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);
}
}
}

0 comments on commit 071865c

Please sign in to comment.