Use DI for direct editing token handling

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-11-29 20:17:52 +01:00
Родитель c87396aa85
Коммит 6a3b6018d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
2 изменённых файлов: 10 добавлений и 11 удалений

Просмотреть файл

@ -28,6 +28,7 @@ namespace OCA\Text\Service;
use \InvalidArgumentException;
use OCA\Text\Db\Session;
use OCP\DirectEditing\IManager;
use OCP\IRequest;
use function json_encode;
use OC\Files\Node\File;
use OCA\Text\Db\Document;
@ -96,7 +97,7 @@ class DocumentService {
*/
private $appData;
public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, IAppData $appData, $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, ILogger $logger, ShareManager $shareManager) {
public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, IAppData $appData, $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, ILogger $logger, ShareManager $shareManager, IRequest $request, IManager $directManager) {
$this->documentMapper = $documentMapper;
$this->stepMapper = $stepMapper;
$this->userId = $userId;
@ -111,12 +112,10 @@ class DocumentService {
$this->appData->newFolder('documents');
}
// FIXME
$token = \OC::$server->getRequest()->getParam('token');
$token = $request->getParam('token');
if ($this->userId === null && $token !== null) {
$this->directManager = \OC::$server->query(IManager::class);
try {
$tokenObject = $this->directManager->getToken($token);
$tokenObject = $directManager->getToken($token);
$tokenObject->extend();
$tokenObject->useTokenScope();
$this->userId = $tokenObject->getUser();

Просмотреть файл

@ -32,6 +32,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DirectEditing\IManager;
use OCP\IAvatar;
use OCP\IAvatarManager;
use OCP\IRequest;
use OCP\Security\ISecureRandom;
class SessionService {
@ -47,23 +48,22 @@ class SessionService {
/** @var Session cache current session in the request */
private $session = null;
public function __construct(SessionMapper $sessionMapper, ISecureRandom $secureRandom, ITimeFactory $timeFactory, IAvatarManager $avatarManager, $userId) {
public function __construct(SessionMapper $sessionMapper, ISecureRandom $secureRandom, ITimeFactory $timeFactory, IAvatarManager $avatarManager, IRequest $request, IManager $directManager, $userId) {
$this->sessionMapper = $sessionMapper;
$this->secureRandom = $secureRandom;
$this->timeFactory = $timeFactory;
$this->avatarManager = $avatarManager;
$this->userId = $userId;
// FIXME
$token = \OC::$server->getRequest()->getParam('token');
$token = $request->getParam('token');
if ($this->userId === null && $token !== null) {
$this->directManager = \OC::$server->query(IManager::class);
try {
$tokenObject = $this->directManager->getToken($token);
$tokenObject = $directManager->getToken($token);
$tokenObject->extend();
$tokenObject->useTokenScope();
$this->userId = $tokenObject->getUser();
} catch (\Exception $e) {}
}
$this->avatarManager = $avatarManager;
}
public function initSession($documentId, $guestName = null): Session {