24
24
use Symfony \Component \HttpKernel \HttpKernelInterface ;
25
25
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
26
26
use Symfony \Component \Security \Core \Authorization \Voter \Voter ;
27
+ use Symfony \Component \Serializer \Exception \NotEncodableValueException ;
27
28
28
29
/**
29
30
* @author Daniel West <[email protected] >
@@ -63,10 +64,11 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token):
63
64
if (!$ request ) {
64
65
return true ;
65
66
}
67
+ // TODO: if the subject is publishable, we should also check if there is a published version and the pages that one is in.
68
+ // The draft will not be in any locations.
66
69
67
70
$ pagesGenerator = $ this ->getComponentPages ($ subject );
68
71
$ pages = iterator_to_array ($ pagesGenerator );
69
-
70
72
// Check if accessible via any route
71
73
$ routes = $ this ->getComponentRoutesFromPages ($ pages );
72
74
$ routeCount = 0 ;
@@ -104,6 +106,7 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token):
104
106
105
107
private function isRouteReachableResource (Route $ route , Request $ request ): bool
106
108
{
109
+ dump ($ route );
107
110
$ path = $ this ->iriConverter ->getIriFromResource ($ route );
108
111
109
112
return $ this ->isPathReachable ($ path , $ request );
@@ -118,13 +121,17 @@ private function isPageDataReachableResource(AbstractPageData $pageData, Request
118
121
119
122
private function isPathReachable (string $ path , Request $ request ): bool
120
123
{
124
+ $ serverVars = $ request ->server ->all ();
125
+ if (isset ($ serverVars ['HTTP_ACCEPT ' ])) {
126
+ $ serverVars ['HTTP_ACCEPT ' ] = 'application/ld+json,application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ' ;
127
+ }
121
128
$ subRequest = Request::create (
122
129
$ path ,
123
130
Request::METHOD_GET ,
124
131
[],
125
132
$ request ->cookies ->all (),
126
133
[],
127
- $ request -> server -> all () ,
134
+ $ serverVars ,
128
135
null
129
136
);
130
137
@@ -133,6 +140,10 @@ private function isPathReachable(string $path, Request $request): bool
133
140
134
141
return true ;
135
142
} catch (\Exception $ e ) {
143
+ // unsupported format requested
144
+ if ($ e instanceof NotEncodableValueException) {
145
+ return false ;
146
+ }
136
147
if (\in_array ($ e ->getCode (), [Response::HTTP_UNAUTHORIZED , Response::HTTP_FORBIDDEN ], true )) {
137
148
return false ;
138
149
}
0 commit comments