Skip to content

Commit

Permalink
Feature: remove support for UserInfo (method PutUserInfo and so on).
Browse files Browse the repository at this point in the history
See #35
  • Loading branch information
julienfastre committed Jan 10, 2023
1 parent 8d13544 commit 5a0137e
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions src/Service/Wopi.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
use ChampsLibres\WopiLib\Contract\Service\WopiInterface;
use DateTimeInterface;
use Psr\Cache\CacheItemPoolInterface;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
Expand All @@ -37,8 +36,6 @@ final class Wopi implements WopiInterface

private AuthorizationManagerInterface $authorizationManager;

private CacheItemPoolInterface $cache;

private DocumentManagerInterface $documentManager;

private LoggerInterface $logger;
Expand All @@ -57,7 +54,6 @@ final class Wopi implements WopiInterface

public function __construct(
AuthorizationManagerInterface $authorizationManager,
CacheItemPoolInterface $cache,
DocumentManagerInterface $documentManager,
LoggerInterface $logger,
ResponseFactoryInterface $responseFactory,
Expand All @@ -68,7 +64,6 @@ public function __construct(
PutFile $putFile
) {
$this->authorizationManager = $authorizationManager;
$this->cache = $cache;
$this->documentManager = $documentManager;
$this->logger = $logger;
$this->responseFactory = $responseFactory;
Expand Down Expand Up @@ -120,7 +115,7 @@ public function checkFileInfo(string $fileId, string $accessToken, RequestInterf
'UserCanRename' => $this->authorizationManager->userCanRename($accessToken, $document, $request),
'UserCanWrite' => $this->authorizationManager->userCanWrite($accessToken, $document, $request),
'UserCanNotWriteRelative' => $this->authorizationManager->userCannotWriteRelative($accessToken, $document, $request),
'SupportsUserInfo' => null !== $userIdentifier,
'SupportsUserInfo' => false,
'SupportsDeleteFile' => true,
'SupportsLocks' => true,
'SupportsGetLock' => true,
Expand All @@ -139,12 +134,6 @@ public function checkFileInfo(string $fileId, string $accessToken, RequestInterf
->format(DateTimeInterface::ATOM),
];

if (null !== $userIdentifier) {
$userCacheKey = sprintf('wopi_putUserInfo_%s', $userIdentifier);

$properties['UserInfo'] = (string) $this->cache->getItem($userCacheKey)->get();
}

return $this
->responseFactory
->createResponse()
Expand Down Expand Up @@ -448,26 +437,12 @@ public function putRelativeFile(

public function putUserInfo(string $fileId, string $accessToken, RequestInterface $request): ResponseInterface
{
$userIdentifier = $this->userManager->getUserId($accessToken, $fileId, $request);

if (null === $userIdentifier) {
$this->logger->error(self::LOG_PREFIX . 'user identifier not found');

return $this->responseFactory->createResponse(400)->withBody(
$this->streamFactory->createStream((string) json_encode([
'message' => 'user identifier not found',
]))
);
}
$userCacheKey = sprintf('wopi_putUserInfo_%s', $userIdentifier);
$this->logger->warning(self::LOG_PREFIX . 'user info called, but not implemented');

$cacheItem = $this->cache->getItem($userCacheKey);
$cacheItem->set((string) $request->getBody());
$this->cache->save($cacheItem);

return $this
->responseFactory
->createResponse();
return $this->responseFactory->createResponse(501)
->withBody($this->streamFactory->createStream((string) json_encode([
'message' => 'User info not implemented',
])));
}

public function refreshLock(
Expand Down

0 comments on commit 5a0137e

Please sign in to comment.