Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Set IUserSession user in SessionController if available
fixes #2821

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr authored and max-nextcloud committed Nov 9, 2022
commit f927fa90b868e8b7c19f98c65414a5b161b26c15
35 changes: 34 additions & 1 deletion lib/Controller/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
namespace OCA\Text\Controller;

use OCA\Text\Service\ApiService;
use OCA\Text\Service\SessionService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;

class SessionController extends Controller {

Expand All @@ -38,9 +41,28 @@ class SessionController extends Controller {
*/
private $apiService;

public function __construct(string $appName, IRequest $request, ApiService $apiService) {
/**
* @var SessionService
*/
private $sessionService;

/**
* @var IUserManager
*/
private $userManager;

/**
* @var IUserSession
*/
private $userSession;


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

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

Expand All @@ -79,6 +102,16 @@ 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);
}

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);
}
}

}