-
-
-
- {{ $t('thirdparty.firstname') }}
-
-
- {{ $t('thirdparty.lastname') }}
+
+ {{ $t('thirdparty.name') }}
+
+
+
import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
-import { getThirdparty, postThirdparty } from '../../_api/OnTheFly';
+import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress';
+import { getThirdparty } from '../../_api/OnTheFly';
export default {
name: "OnTheFlyThirdParty",
props: ['id', 'type', 'action'],
components: {
ThirdPartyRenderBox,
+ AddAddress
},
- data: function() {
+ data() {
return {
+ //context: {}, <--
thirdparty: {
type: 'thirdparty'
+ },
+ addAddress: {
+ options: {
+ openPanesInModal: true,
+ onlyButton: false,
+ button: {
+ size: 'btn-sm'
+ },
+ title: {
+ create: 'add_an_address_title',
+ edit: 'edit_address'
+ }
+ }
}
}
},
+ computed: {
+ context() {
+ let context = {
+ target: {
+ name: this.type,
+ id: this.id
+ },
+ edit: false,
+ addressId: null
+ };
+ if ( typeof this.thirdparty.address !== 'undefined'
+ && this.thirdparty.address.address_id !== null
+ ) { // to complete
+ context.addressId = this.thirdparty.address.address_id;
+ context.edit = true;
+ }
+ console.log('context', context);
+ //this.context = context; <--
+ return context;
+ },
+ },
methods: {
- loadThirdparty(){
+ loadData(){
getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
this.thirdparty = thirdparty;
+ console.log('get thirdparty', thirdparty);
+ if (this.action !== 'show') {
+ // bof! we force getInitialAddress because addressId not available when mounted
+ this.$refs.addAddress.getInitialAddress(thirdparty.address.address_id);
+ }
resolve();
}));
},
- postData() {
- postThirdparty(this.thirdparty).then(thirdparty => new Promise((resolve, reject) => {
- this.thirdparty = thirdparty;
- resolve();
- }))
+ submitAddress(payload) {
+ console.log('submitAddress', payload);
+ if (typeof payload.addressId !== 'undefined') { // <--
+ this.context.edit = true;
+ this.context.addressId = payload.addressId; // bof! use legacy and not legacy in payload
+ this.thirdparty.address = payload.address; // <--
+ console.log('switch address to edit mode', this.context);
+ }
}
},
mounted() {
- if (this.action !== 'create'){
- this.loadThirdparty();
+ if (this.action !== 'create') {
+ this.loadData();
}
},
}
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js
new file mode 100644
index 000000000..37d09320d
--- /dev/null
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js
@@ -0,0 +1,11 @@
+const thirdpartyMessages = {
+ fr: {
+ thirdparty: {
+ name: "Dénomination",
+ email: "Courriel",
+ phonenumber: "Téléphone",
+ }
+ }
+};
+
+export { thirdpartyMessages };
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig
index fa9ad8b8b..1cd1a6257 100644
--- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig
@@ -51,7 +51,7 @@
{{ (tp.active ? '' : '')|raw }}
{{ tp.name }}
{% set types = [] %}
- {% for t in tp.type %}
+ {% for t in tp.types %}
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
{% endfor %}
{{ types|join(', ') }}
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig
index 002cc87e8..319083649 100644
--- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig
@@ -26,7 +26,7 @@
{{ form_row(form.profession) }}
{% endif %}
- {{ form_row(form.type) }}
+ {{ form_row(form.types) }}
{{ form_row(form.categories) }}
{{ form_row(form.telephone) }}
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig
index d711bdefa..a8dc587d7 100644
--- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig
@@ -48,7 +48,7 @@
{{ 'Type'|trans }}
{% set types = [] %}
- {% for t in thirdParty.type %}
+ {% for t in thirdParty.types %}
{% set types = types|merge( [ ('chill_3party.key_label.'~t)|trans ] ) %}
{% endfor %}
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig
index 01837db05..4433d934b 100644
--- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig
@@ -43,7 +43,7 @@
{{ form_row(form.profession) }}
{% endif %}
- {{ form_row(form.type) }}
+ {{ form_row(form.types) }}
{{ form_row(form.categories) }}
{{ form_row(form.telephone) }}
diff --git a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php
index a1ce94e25..ab78c7701 100644
--- a/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php
+++ b/src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php
@@ -56,11 +56,15 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
+ return true;
+
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
+
+ return true;
$centers = $this->authorizationHelper
->getReachableCenters($user, new Role($attribute));
diff --git a/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml b/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml
index 957bf9324..52db7589c 100644
--- a/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml
+++ b/src/Bundle/ChillThirdPartyBundle/chill.api.specs.yaml
@@ -8,17 +8,57 @@ servers:
- url: "/api"
description: "Your current dev server"
+components:
+ schemas:
+ Thirdparty:
+ type: object
+ properties:
+ id:
+ type: integer
+ readOnly: true
+ type:
+ type: string
+ enum:
+ - "thirdparty"
+ name:
+ type: string
+ email:
+ type: string
+ telephone:
+ type: string
+ address:
+ $ref: "#/components/schemas/Address"
+ Address:
+ type: object
+ properties:
+ id:
+ type: integer
+
+
paths:
/1.0/thirdparty/thirdparty.json:
- get:
+ post:
tags:
- thirdparty
- summary: Return a list of all thirdparty items
+ summary: Create a single thirdparty
+ requestBody:
+ description: "A thirdparty"
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Thirdparty"
responses:
200:
- description: "ok"
- 401:
+ description: "OK"
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Thirdparty"
+ 403:
description: "Unauthorized"
+ 422:
+ description: "Invalid data"
/1.0/thirdparty/thirdparty/{id}.json:
get:
@@ -41,3 +81,32 @@ paths:
description: "not found"
401:
description: "Unauthorized"
+ patch:
+ tags:
+ - thirdparty
+ summary: "Alter a thirdparty"
+ parameters:
+ - name: id
+ in: path
+ required: true
+ description: The thirdparty's id
+ schema:
+ type: integer
+ format: integer
+ minimum: 1
+ requestBody:
+ description: "A thirdparty"
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Thirdparty"
+ responses:
+ 401:
+ description: "Unauthorized"
+ 404:
+ description: "Not found"
+ 200:
+ description: "OK"
+ 422:
+ description: "Object with validation errors"
diff --git a/src/Bundle/ChillWopiBundle/composer.json b/src/Bundle/ChillWopiBundle/composer.json
index 7f7e6a4ed..41737c8b1 100644
--- a/src/Bundle/ChillWopiBundle/composer.json
+++ b/src/Bundle/ChillWopiBundle/composer.json
@@ -19,7 +19,7 @@
"php": ">= 7.4",
"champs-libres/wopi-bundle": "dev-master",
"nyholm/psr7": "^1.4",
- "php-opencloud/openstack": "^3.2.1"
+ "symfony/mime": "^4 || ^5"
},
"autoload": {
"psr-4": {
diff --git a/src/Bundle/ChillWopiBundle/src/Controller/Test.php b/src/Bundle/ChillWopiBundle/src/Controller/Test.php
index 202af20aa..283328f21 100644
--- a/src/Bundle/ChillWopiBundle/src/Controller/Test.php
+++ b/src/Bundle/ChillWopiBundle/src/Controller/Test.php
@@ -9,9 +9,10 @@ declare(strict_types=1);
namespace Chill\WopiBundle\Controller;
-use ChampsLibres\WopiLib\Configuration\WopiConfigurationInterface;
-use ChampsLibres\WopiLib\Discovery\WopiDiscoveryInterface;
-use Chill\DocStoreBundle\Repository\StoredObjectRepository;
+use ChampsLibres\WopiLib\Contract\Service\Configuration\ConfigurationInterface;
+use ChampsLibres\WopiLib\Contract\Service\Discovery\DiscoveryInterface;
+use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
+use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\WopiBundle\Service\Controller\ResponderInterface;
use Exception;
use loophp\psr17\Psr17Interface;
@@ -23,11 +24,11 @@ use Symfony\Component\Security\Core\Security;
final class Test
{
- private StoredObjectRepository $storedObjectRepository;
+ private DiscoveryInterface $wopiDiscovery;
- private WopiDiscoveryInterface $wopiDiscovery;
+ private DocumentManagerInterface $documentManager;
- private WopiConfigurationInterface $wopiConfiguration;
+ private ConfigurationInterface $wopiConfiguration;
private ResponderInterface $responder;
@@ -38,15 +39,15 @@ final class Test
private RouterInterface $router;
public function __construct(
- StoredObjectRepository $storedObjectRepository,
- WopiConfigurationInterface $wopiConfiguration,
- WopiDiscoveryInterface $wopiDiscovery,
+ ConfigurationInterface $wopiConfiguration,
+ DiscoveryInterface $wopiDiscovery,
+ DocumentManagerInterface $documentManager,
ResponderInterface $responder,
Security $security,
Psr17Interface $psr17,
RouterInterface $router
) {
- $this->storedObjectRepository = $storedObjectRepository;
+ $this->documentManager = $documentManager;
$this->wopiConfiguration = $wopiConfiguration;
$this->wopiDiscovery = $wopiDiscovery;
$this->responder = $responder;
@@ -58,11 +59,11 @@ final class Test
public function __invoke(string $fileId): Response
{
$configuration = $this->wopiConfiguration->jsonSerialize();
-
- $storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
+ /** @var StoredObject $storedObject */
+ $storedObject = $this->documentManager->findByDocumentId($fileId);
if (null === $storedObject) {
- throw new NotFoundHttpException(sprintf('Unable to find object named %s', $fileId));
+ throw new NotFoundHttpException(sprintf('Unable to find object %s', $fileId));
}
if ([] === $discoverExtension = $this->wopiDiscovery->discoverMimeType($storedObject->getType())) {
@@ -83,7 +84,7 @@ final class Test
->generate(
'checkFileInfo',
[
- 'fileId' => $storedObject->getFilename(),
+ 'fileId' => $this->documentManager->getDocumentId($storedObject),
],
UrlGeneratorInterface::ABSOLUTE_URL
),
diff --git a/src/Bundle/ChillWopiBundle/src/Resources/config/services.php b/src/Bundle/ChillWopiBundle/src/Resources/config/services.php
index 455e658e2..4925404b3 100644
--- a/src/Bundle/ChillWopiBundle/src/Resources/config/services.php
+++ b/src/Bundle/ChillWopiBundle/src/Resources/config/services.php
@@ -10,8 +10,10 @@ declare(strict_types=1);
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
-use ChampsLibres\WopiLib\Service\Contract\WopiInterface;
use Chill\WopiBundle\Service\Wopi\ChillWopi;
+use ChampsLibres\WopiBundle\Service\Wopi as CLWopi;
+use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
+use Chill\WopiBundle\Service\Wopi\ChillDocumentManager;
return static function (ContainerConfigurator $container) {
$services = $container
@@ -30,8 +32,14 @@ return static function (ContainerConfigurator $container) {
->tag('controller.service_arguments');
$services
- ->alias(WopiInterface::class, ChillWopi::class);
+ ->set(ChillWopi::class)
+ ->decorate(CLWopi::class)
+ ->arg('$wopi', service('.inner'));
+ $services
+ ->alias(DocumentManagerInterface::class, ChillDocumentManager::class);
+
+ // TODO: Move this into the async bundle (low priority)
$services
->alias(TempUrlGeneratorInterface::class, 'async_uploader.temp_url_generator');
};
diff --git a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php
new file mode 100644
index 000000000..ac3de1729
--- /dev/null
+++ b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillDocumentManager.php
@@ -0,0 +1,244 @@
+entityManager = $entityManager;
+ $this->psr17 = $psr17;
+ $this->storedObjectRepository = $storedObjectRepository;
+ $this->documentLockManager = $documentLockManager;
+ $this->tempUrlGenerator = $tempUrlGenerator;
+ $this->httpClient = $httpClient;
+ $this->request = $httpMessageFactory->createRequest($requestStack->getCurrentRequest());
+ }
+
+ public function create(array $data): Document
+ {
+ /** @var StoredObject $document */
+ $document = (new ObjectNormalizer())->denormalize([], StoredObject::class);
+
+ // Mime types / extension handling.
+ $mimeTypes = new MimeTypes();
+ $mimeTypes->getMimeTypes($data['extension']);
+ $document->setType(reset($mimeTypes));
+
+ $document->setFilename($data['name']);
+
+ $this->entityManager->persist($document);
+ $this->entityManager->flush($document);
+
+ // TODO : Ask proper mapping.
+ // Available: basename, name, extension, content, size
+ $this->setContent($document, $data['content']);
+
+ return $document;
+ }
+
+ public function deleteLock(Document $document): void {
+ $this->documentLockManager->deleteLock($document, $this->request);
+ }
+
+ /**
+ * @param string $documentFilename without extension !
+ */
+ public function findByDocumentFilename(string $documentFilename): ?Document {
+ return $this->storedObjectRepository->findOneBy(
+ [
+ 'filename' => $documentFilename,
+ ]
+ );
+ }
+
+ public function findByDocumentId(string $documentId): ?Document {
+ return $this->storedObjectRepository->findOneBy(
+ [
+ 'uuid' => Uuid::fromString($documentId),
+ ]
+ );
+ }
+
+ /**
+ * @param StoredObject $document
+ */
+ public function getCreationDate(Document $document): DateTimeInterface
+ {
+ return $document->getCreationDate();
+ }
+
+ /**
+ * @param StoredObject $document
+ */
+ public function getLastModifiedDate(Document $document): DateTimeInterface
+ {
+ // TODO: Add column 'LastModifiedDate' in StoredObject entity
+ return $document->getCreationDate();
+ }
+
+ public function getLock(Document $document): string {
+ return $this->documentLockManager->getLock($document, $this->request);
+ }
+
+ public function getVersion(Document $document): string {
+ // TODO ?
+ return '0';
+ }
+
+ public function hasLock(Document $document): bool {
+ return $this->documentLockManager->hasLock($document, $this->request);
+ }
+
+ public function lock(Document $document, string $lock): void {
+ $this->documentLockManager->setLock($document, $lock, $this->request);
+ }
+
+ public function remove(Document $document): void {
+ $entityIsDeleted = false;
+
+ try {
+ $this->entityManager->remove($document);
+ $entityIsDeleted = true;
+ } catch (Throwable $e) {
+ $entityIsDeleted = false;
+ }
+
+ if ($entityIsDeleted === true) {
+ $this->deleteContent($document);
+ }
+ }
+
+ public function write(Document $document, array $properties = []): void
+ {
+ $this->setContent($document, $properties['content']);
+ }
+
+ /**
+ * @param StoredObject $document
+ *
+ * @return string The document filename with its extension.
+ */
+ public function getBasename(Document $document): string {
+ $exts = (new MimeTypes())->getExtensions($document->getType());
+
+ if ([] === $exts) {
+ throw new Error('Unknown mimetype for stored document.');
+ }
+
+ return sprintf('%s.%s', $document->getFilename(), reset($exts));
+ }
+
+ /**
+ * @param StoredObject $document
+ */
+ public function getDocumentId(Document $document): string {
+ return (string) $document->getUuid();
+ }
+
+ public function getSha256(Document $document): string {
+ return base64_encode(hash('sha256', $this->getContent($document)));
+ }
+
+ public function getSize(Document $document): int {
+ return strlen($this->getContent($document));
+ }
+
+ public function read(Document $document): StreamInterface {
+ return $this
+ ->psr17
+ ->createStream($this->getContent($document));
+ }
+
+ private function deleteContent(StoredObject $storedObject): void
+ {
+ /** @var StdClass $object */
+ $object = $this->tempUrlGenerator->generate('DELETE', $storedObject->getFilename());
+
+ $response = $this->httpClient->request('DELETE', $object->url);
+
+ if (200 !== $response->getStatusCode())
+ {
+ throw new Error('Unable to delete stored object.');
+ }
+ }
+
+ private function getContent(StoredObject $storedObject): string
+ {
+ /** @var StdClass $object */
+ $object = $this->tempUrlGenerator->generate('GET', $storedObject->getFilename());
+
+ $response = $this->httpClient->request('GET', $object->url);
+
+ if (200 !== $response->getStatusCode())
+ {
+ throw new Error('Unable to retrieve stored object.');
+ }
+
+ return $response->getContent();
+ }
+
+ private function setContent(StoredObject $storedObject, string $content): void
+ {
+ // TODO: Add strict typing in champs-libres/async-uploader-bundle
+ /** @var StdClass $object */
+ $object = $this->tempUrlGenerator->generate('PUT', $storedObject->getFilename());
+
+ $response = $this->httpClient->request('PUT', $object->url, ['body' => $content]);
+
+ if (201 !== $response->getStatusCode())
+ {
+ throw new Error('Unable to save stored object.');
+ }
+ }
+
+}
diff --git a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php
index fc4e526a1..ba289630e 100644
--- a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php
+++ b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php
@@ -9,13 +9,10 @@ declare(strict_types=1);
namespace Chill\WopiBundle\Service\Wopi;
-use ChampsLibres\AsyncUploaderBundle\TempUrl\TempUrlGeneratorInterface;
-use ChampsLibres\WopiLib\Discovery\WopiDiscoveryInterface;
-use ChampsLibres\WopiLib\Service\Contract\WopiInterface;
-use Chill\DocStoreBundle\Repository\StoredObjectRepository;
-use Exception;
+use ChampsLibres\WopiLib\Contract\Service\DocumentManagerInterface;
+use ChampsLibres\WopiLib\Contract\Service\WopiInterface;
use loophp\psr17\Psr17Interface;
-use Psr\Http\Client\ClientInterface;
+use Psr\Cache\CacheItemPoolInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
@@ -23,32 +20,28 @@ use Symfony\Component\Security\Core\User\UserProviderInterface;
final class ChillWopi implements WopiInterface
{
+ private CacheItemPoolInterface $cache;
+
+ private DocumentManagerInterface $documentManager;
+
private Psr17Interface $psr17;
- private WopiDiscoveryInterface $wopiDiscovery;
-
- private StoredObjectRepository $storedObjectRepository;
-
- private ClientInterface $httpClient;
-
- private TempUrlGeneratorInterface $tempUrlGenerator;
-
private UserProviderInterface $userProvider;
+ private WopiInterface $wopi;
+
public function __construct(
+ CacheItemPoolInterface $cache,
+ DocumentManagerInterface $documentManager,
Psr17Interface $psr17,
- WopiDiscoveryInterface $wopiDiscovery,
- StoredObjectRepository $storedObjectRepository,
- ClientInterface $httpClient,
- TempUrlGeneratorInterface $tempUrlGenerator,
- UserProviderInterface $userProvider
+ UserProviderInterface $userProvider,
+ WopiInterface $wopi
) {
+ $this->cache = $cache;
+ $this->documentManager = $documentManager;
$this->psr17 = $psr17;
- $this->wopiDiscovery = $wopiDiscovery;
- $this->storedObjectRepository = $storedObjectRepository;
- $this->httpClient = $httpClient;
- $this->tempUrlGenerator = $tempUrlGenerator;
$this->userProvider = $userProvider;
+ $this->wopi = $wopi;
}
public function checkFileInfo(
@@ -64,17 +57,10 @@ final class ChillWopi implements WopiInterface
->createResponse(401);
}
- $storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
-
- if (null === $storedObject) {
- throw new Exception(sprintf('Unable to find object named %s', $fileId));
- }
-
- $mimeType = $storedObject->getType();
-
- if ([] === $this->wopiDiscovery->discoverMimeType($mimeType)) {
- throw new Exception(sprintf('Unable to find mime type %s', $mimeType));
- }
+ // @ TODO : Replace this with a call to decorated object once authentication is done.
+ $document = $this->documentManager->findByDocumentId($fileId);
+ $userIdentifier = $user->getUsername();
+ $userCacheKey = sprintf('wopi_putUserInfo_%s', $userIdentifier);
return $this
->psr17
@@ -82,33 +68,38 @@ final class ChillWopi implements WopiInterface
->withHeader('Content-Type', 'application/json')
->withBody($this->psr17->createStream((string) json_encode(
[
- 'BaseFileName' => $storedObject->getFilename(),
- 'OwnerId' => uniqid(),
- 'Size' => 0,
- 'UserId' => uniqid(),
-// 'Version' => 'v' . uniqid(),
+ 'BaseFileName' => $this->documentManager->getBasename($document),
+ 'OwnerId' => 'Symfony',
+ 'Size' => $this->documentManager->getSize($document),
+ 'UserId' => $userIdentifier,
'ReadOnly' => false,
+ 'UserCanAttend' => true,
+ 'UserCanPresent' => true,
+ 'UserCanRename' => true,
'UserCanWrite' => true,
- 'UserCanNotWriteRelative' => true,
- 'SupportsLocks' => false,
- 'UserFriendlyName' => sprintf('User %s', $user->getUsername()),
- 'UserExtraInfo' => [],
- 'LastModifiedTime' => date('Y-m-d\TH:i:s.u\Z', $storedObject->getCreationDate()->getTimestamp()),
- 'CloseButtonClosesWindow' => true,
- 'EnableInsertRemoteImage' => true,
- 'EnableShare' => false,
+ 'UserCanNotWriteRelative' => false,
+ 'SupportsUserInfo' => true,
+ 'SupportsDeleteFile' => true,
+ 'SupportsLocks' => true,
+ 'SupportsGetLock' => true,
+ 'SupportsExtendedLockLength' => true,
+ 'UserFriendlyName' => $userIdentifier,
'SupportsUpdate' => true,
- 'SupportsRename' => false,
+ 'SupportsRename' => true,
'DisablePrint' => false,
- 'DisableExport' => false,
- 'DisableCopy' => false,
+ 'AllowExternalMarketplace' => true,
+ 'SupportedShareUrlTypes' => [
+ 'ReadOnly',
+ ],
+ 'SHA256' => $this->documentManager->getSha256($document),
+ 'UserInfo' => (string) $this->cache->getItem($userCacheKey)->get(),
]
)));
}
public function deleteFile(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
{
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->deleteFile($fileId, $accessToken, $request);
}
public function enumerateAncestors(
@@ -116,57 +107,17 @@ final class ChillWopi implements WopiInterface
?string $accessToken,
RequestInterface $request
): ResponseInterface {
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->enumerateAncestors($fileId, $accessToken, $request);
}
public function getFile(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
{
- try {
- $user = $this->userProvider->loadUserByUsername($accessToken);
- } catch (UsernameNotFoundException $e) {
- return $this
- ->psr17
- ->createResponse(401);
- }
-
- $storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
-
- if (null === $storedObject) {
- return $this
- ->psr17
- ->createResponse(404);
- }
-
- // TODO: Add strict typing in champs-libres/async-uploader-bundle
- /** @var StdClass $object */
- $object = $this->tempUrlGenerator->generate('GET', $storedObject->getFilename());
-
- $response = $this->httpClient->sendRequest($this->psr17->createRequest('GET', $object->url));
-
- if (200 !== $response->getStatusCode())
- {
- return $this
- ->psr17
- ->createResponse(500);
- }
-
- return $this
- ->psr17
- ->createResponse()
- ->withHeader(
- 'Content-Type',
- 'application/octet-stream',
- )
- ->withHeader(
- 'Content-Disposition',
- sprintf('attachment; filename=%s', $storedObject->getFilename())
- )
- ->withBody($response->getBody());
+ return $this->wopi->getFile($fileId, $accessToken, $request);
}
public function getLock(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
{
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->getLock($fileId, $accessToken, $request);
}
public function getShareUrl(
@@ -174,7 +125,7 @@ final class ChillWopi implements WopiInterface
?string $accessToken,
RequestInterface $request
): ResponseInterface {
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->getShareUrl($fileId, $accessToken, $request);
}
public function lock(
@@ -183,7 +134,7 @@ final class ChillWopi implements WopiInterface
string $xWopiLock,
RequestInterface $request
): ResponseInterface {
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->lock($fileId, $accessToken, $xWopiLock, $request);
}
public function putFile(
@@ -193,49 +144,17 @@ final class ChillWopi implements WopiInterface
string $xWopiEditors,
RequestInterface $request
): ResponseInterface {
- try {
- $user = $this->userProvider->loadUserByUsername($accessToken);
- } catch (UsernameNotFoundException $e) {
- return $this
- ->psr17
- ->createResponse(401);
- }
-
- $storedObject = $this->storedObjectRepository->findOneBy(['filename' => $fileId]);
-
- if (null === $storedObject) {
- throw new Exception(sprintf('Unable to find object named %s', $fileId));
- }
-
- // TODO: Add strict typing in champs-libres/async-uploader-bundle
- /** @var StdClass $object */
- $object = $this->tempUrlGenerator->generate('PUT', $storedObject->getFilename());
-
- $response = $this->httpClient->sendRequest($this->psr17->createRequest('PUT', $object->url)->withBody($request->getBody()));
-
- if (201 !== $response->getStatusCode())
- {
- return $this
- ->psr17
- ->createResponse(500);
- }
-
- return $this
- ->psr17
- ->createResponse()
- ->withHeader('Content-Type', 'application/json')
- ->withAddedHeader('X-WOPI-Lock', $xWopiLock)
- ->withBody($this->psr17->createStream((string) json_encode([])));
+ return $this->wopi->putFile($fileId, $accessToken, $xWopiLock, $xWopiEditors, $request);
}
public function putRelativeFile(string $fileId, string $accessToken, ?string $suggestedTarget, ?string $relativeTarget, bool $overwriteRelativeTarget, int $size, RequestInterface $request): ResponseInterface
{
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->putRelativeFile($fileId, $accessToken, $suggestedTarget, $relativeTarget, $overwriteRelativeTarget, $size, $request);
}
public function putUserInfo(string $fileId, ?string $accessToken, RequestInterface $request): ResponseInterface
{
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->putUserInfo($fileId, $accessToken, $request);
}
public function refreshLock(
@@ -244,7 +163,7 @@ final class ChillWopi implements WopiInterface
string $xWopiLock,
RequestInterface $request
): ResponseInterface {
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->refreshLock($fileId, $accessToken, $xWopiLock, $request);
}
public function renameFile(
@@ -254,7 +173,7 @@ final class ChillWopi implements WopiInterface
string $xWopiRequestedName,
RequestInterface $request
): ResponseInterface {
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->renameFile($fileId, $accessToken, $xWopiLock, $xWopiRequestedName, $request);
}
public function unlock(
@@ -263,7 +182,7 @@ final class ChillWopi implements WopiInterface
string $xWopiLock,
RequestInterface $request
): ResponseInterface {
- return $this->getDebugResponse(__FUNCTION__, $request);
+ return $this->wopi->unlock($fileId, $accessToken, $xWopiLock, $request);
}
public function unlockAndRelock(
@@ -273,33 +192,6 @@ final class ChillWopi implements WopiInterface
string $xWopiOldLock,
RequestInterface $request
): ResponseInterface {
- return $this->getDebugResponse(__FUNCTION__, $request);
- }
-
- private function getDebugResponse(string $method, RequestInterface $request): ResponseInterface
- {
- $params = [];
- parse_str($request->getUri()->getQuery(), $params);
-
- $data = (string) json_encode(array_merge(
- ['method' => $method],
- $params,
- $request->getHeaders()
- ));
-
- return $this
- ->psr17
- ->createResponse()
- ->withHeader('content', 'application/json')
- ->withBody($this->psr17->createStream($data));
- }
-
- private function getLockFilepath(string $fileId): string
- {
- return sprintf(
- '%s/%s.lock',
- $this->filesRepository,
- $fileId
- );
+ return $this->wopi->unlockAndRelock($fileId, $accessToken, $xWopiLock, $xWopiOldLock, $request);
}
}