@@ -182,7 +182,7 @@ public function showFile(string $fileid = null): Response {
182182 * @return TemplateResponse|RedirectResponse
183183 * @throws NotFoundException
184184 */
185- public function index ($ dir = '' , $ view = '' , $ fileid = null , $ fileNotFound = false ) {
185+ public function index ($ dir = '' , $ view = '' , $ fileid = null , $ fileNotFound = false , $ openfile = null ) {
186186 if ($ fileid !== null ) {
187187 try {
188188 return $ this ->redirectToFile ($ fileid );
@@ -331,6 +331,34 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
331331 $ policy ->addAllowedFrameDomain ('\'self \'' );
332332 $ response ->setContentSecurityPolicy ($ policy );
333333
334+ $ user = $ this ->userSession ->getUser ();
335+ if ($ openfile !== null && $ user != null ) {
336+ $ uid = $ user ->getUID ();
337+ $ userFolder = $ this ->rootFolder ->getUserFolder ($ uid );
338+ $ node = $ userFolder ->getById ($ openfile )[0 ];
339+
340+ // properly format full path and make sure
341+ // we're relative to the user home folder
342+ $ isRoot = $ node === $ userFolder ;
343+ $ path = $ userFolder ->getRelativePath ($ node ->getPath ());
344+ $ directory = $ userFolder ->getRelativePath ($ node ->getParent ()->getPath ());
345+
346+ // Prevent opening a file from another folder.
347+ if ($ dir === $ directory ) {
348+ $ this ->initialState ->provideInitialState (
349+ 'openFileInfo ' , [
350+ 'id ' => $ node ->getId (),
351+ 'name ' => $ isRoot ? '' : $ node ->getName (),
352+ 'path ' => $ path ,
353+ 'directory ' => $ directory ,
354+ 'mime ' => $ node ->getMimetype (),
355+ 'type ' => $ node ->getType (),
356+ 'permissions ' => $ node ->getPermissions (),
357+ ]
358+ );
359+ }
360+ }
361+
334362 return $ response ;
335363 }
336364
0 commit comments