mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Let ConvertController return a pdf file directly without trying to converting it
Those changes improve performance when the file is already in pdf format.
This commit is contained in:
parent
f90fae4e14
commit
9b661c3b8f
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\WopiBundle\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManager;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||
use Chill\WopiBundle\Service\WopiConverter;
|
||||
@ -41,7 +42,16 @@ class ConvertController
|
||||
throw new AccessDeniedHttpException('User must be authenticated');
|
||||
}
|
||||
|
||||
if (!$this->security->isGranted(StoredObjectRoleEnum::SEE->value, $storedObject)) {
|
||||
throw new AccessDeniedHttpException('not allowed to see this document');
|
||||
}
|
||||
|
||||
$content = $this->storedObjectManager->read($storedObject);
|
||||
|
||||
if ('application/pdf' === $storedObject->getType()) {
|
||||
return new Response($content, Response::HTTP_OK, ['Content-Type' => 'application/pdf']);
|
||||
}
|
||||
|
||||
$lang = $request->getLocale();
|
||||
|
||||
try {
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\WopiBundle\Tests\Controller;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||
use Chill\WopiBundle\Controller\ConvertController;
|
||||
use Chill\WopiBundle\Service\WopiConverter;
|
||||
@ -37,6 +38,7 @@ final class ConvertControllerTest extends TestCase
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
$security->isGranted(StoredObjectRoleEnum::SEE->value, $storedObject)->willReturn(true);
|
||||
|
||||
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
|
||||
$storeManager->read($storedObject)->willReturn('content');
|
||||
@ -67,6 +69,7 @@ final class ConvertControllerTest extends TestCase
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
$security->isGranted(StoredObjectRoleEnum::SEE->value, $storedObject)->willReturn(true);
|
||||
|
||||
$storeManager = $this->prophesize(StoredObjectManagerInterface::class);
|
||||
$storeManager->read($storedObject)->willReturn('content');
|
||||
|
Loading…
x
Reference in New Issue
Block a user