1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller\File; |
4
|
|
|
|
5
|
|
|
use App\Entity\File; |
6
|
|
|
use App\Service\FileService; |
7
|
|
|
use Ds\Component\Acl\Model\Permission; |
|
|
|
|
8
|
|
|
use Ds\Component\Acl\Voter\PropertyVoter; |
|
|
|
|
9
|
|
|
use LogicException; |
10
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
|
|
|
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
|
|
|
13
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
|
|
|
14
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
|
|
|
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
|
|
|
|
17
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
|
|
|
18
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class PresentationController |
22
|
|
|
* |
23
|
|
|
* @ApiResource |
24
|
|
|
*/ |
25
|
|
|
final class PresentationController |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var \Symfony\Component\HttpFoundation\RequestStack |
29
|
|
|
*/ |
30
|
|
|
private $requestStack; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \App\Service\FileService |
34
|
|
|
*/ |
35
|
|
|
private $fileService; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface |
39
|
|
|
*/ |
40
|
|
|
private $tokenStorage; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \Ds\Component\Acl\Voter\PropertyVoter |
44
|
|
|
*/ |
45
|
|
|
private $propertyVoter; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Constructor |
49
|
|
|
* |
50
|
|
|
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack |
51
|
|
|
* @param \App\Service\FileService $fileService |
52
|
|
|
* @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokenStorage |
53
|
|
|
* @param \Ds\Component\Acl\Voter\PropertyVoter $propertyVoter |
54
|
|
|
*/ |
55
|
|
|
public function __construct(RequestStack $requestStack, FileService $fileService, TokenStorageInterface $tokenStorage, PropertyVoter $propertyVoter) |
56
|
|
|
{ |
57
|
|
|
$this->requestStack = $requestStack; |
58
|
|
|
$this->fileService = $fileService; |
59
|
|
|
$this->tokenStorage = $tokenStorage; |
60
|
|
|
$this->propertyVoter = $propertyVoter; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Presentation |
65
|
|
|
* |
66
|
|
|
* @Route(path="/files/{slug}/presentation", methods={"GET"}) |
67
|
|
|
*/ |
68
|
|
|
public function get($slug) |
69
|
|
|
{ |
70
|
|
|
$request = $this->requestStack->getCurrentRequest(); |
71
|
|
|
$file = $this->fileService->getRepository()->findOneBy(['slug' => $slug]); |
72
|
|
|
|
73
|
|
|
if (!$file) { |
74
|
|
|
throw new NotFoundHttpException('File not found.'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$token = $this->tokenStorage->getToken(); |
78
|
|
|
$subject = new Subject; |
|
|
|
|
79
|
|
|
$subject |
80
|
|
|
->setType(Permission::PROPERTY) |
81
|
|
|
->setValue(File::class.'.presentation') |
82
|
|
|
->setEntity($file->getOwner()) |
83
|
|
|
->setEntityUuid($file->getOwnerUuid()); |
84
|
|
|
|
85
|
|
|
$vote = $this->propertyVoter->vote($token, $subject, [Permission::READ]); |
86
|
|
|
|
87
|
|
|
if (PropertyVoter::ACCESS_ABSTAIN === $vote) { |
88
|
|
|
throw new LogicException('Voter cannot abstain from voting.'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (PropertyVoter::ACCESS_GRANTED !== $vote) { |
92
|
|
|
throw new AccessDeniedException('Access denied.'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$presentation = $file->getPresentation(); |
96
|
|
|
$locale = $request->query->get('locale', null); |
97
|
|
|
|
98
|
|
|
if (!array_key_exists($locale, $presentation)) { |
99
|
|
|
throw new NotFoundHttpException('File locale not found.'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$presentation = base64_decode($presentation[$locale]); |
103
|
|
|
$type = $file->getType(); |
104
|
|
|
$response = new Response($presentation, Response::HTTP_OK, ['Content-Type' => $type]); |
105
|
|
|
|
106
|
|
|
return $response; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths