34
34
use RENOLIT \ReintDownloadmanager \Domain \Repository \DownloadRepository ;
35
35
use TYPO3 \CMS \Core \Context \Context ;
36
36
use TYPO3 \CMS \Core \Database \Query \QueryBuilder ;
37
+ use TYPO3 \CMS \Core \Http \HtmlResponse ;
37
38
use TYPO3 \CMS \Core \Http \PropagateResponseException ;
38
39
use TYPO3 \CMS \Core \Messaging \FlashMessage ;
39
40
use TYPO3 \CMS \Core \Messaging \FlashMessageService ;
40
41
use TYPO3 \CMS \Core \Resource \Exception \FileDoesNotExistException ;
41
42
use TYPO3 \CMS \Core \Resource \File ;
42
43
use TYPO3 \CMS \Core \Resource \FileCollectionRepository ;
44
+ use TYPO3 \CMS \Core \Resource \FileReference ;
43
45
use TYPO3 \CMS \Core \Resource \FileRepository ;
44
46
use TYPO3 \CMS \Core \Resource \ResourceFactory ;
45
47
use TYPO3 \CMS \Core \Session \UserSessionManager ;
@@ -493,7 +495,7 @@ protected function loadCollectionsFromFlexform(): bool
493
495
* @param array $pageIds
494
496
* @throws
495
497
*/
496
- protected function getCollectionsFromPages ($ pageIds ): void
498
+ protected function getCollectionsFromPages (array $ pageIds ): void
497
499
{
498
500
$ table = 'sys_file_collection ' ;
499
501
$ languageAspect = GeneralUtility::makeInstance (Context::class)->getAspect ('language ' );
@@ -534,7 +536,7 @@ protected function getCollectionsFromPages($pageIds): void
534
536
* @return string
535
537
* @throws Exception
536
538
*/
537
- protected function getSysFileCollectionData ($ uid , $ fieldname = 'description_frontend ' ): string
539
+ protected function getSysFileCollectionData (int $ uid , string $ fieldname = 'description_frontend ' ): string
538
540
{
539
541
$ table = 'sys_file_collection ' ;
540
542
/** @var $queryBuilder QueryBuilder */
@@ -569,7 +571,7 @@ protected function setFileNotFound(): void
569
571
}
570
572
571
573
/**
572
- * sets the flashmessage for not found file
574
+ * sets the FlashMessage for not found file
573
575
*/
574
576
protected function setFileNoAccess (): void
575
577
{
@@ -596,7 +598,7 @@ protected function writeFlashMessage(string $errorFlashMessage): void
596
598
}
597
599
598
600
/**
599
- * @param integer $uid
601
+ * @param int $uid
600
602
* @return bool
601
603
* @throws Exception
602
604
*/
@@ -704,6 +706,22 @@ protected function downloadAction(): ResponseInterface
704
706
if ($ this ->request ->hasArgument ('downloaduid ' ) && $ this ->request ->hasArgument ('actionfrom ' )) {
705
707
$ returnToAction = $ this ->request ->getArgument ('actionfrom ' );
706
708
$ recordUid = (int )$ this ->request ->getArgument ('downloaduid ' );
709
+
710
+ $ this ->loadCollectionsFromFlexform ();
711
+ $ this ->loadCollectionsFromDb ();
712
+ $ files = [];
713
+ foreach ($ this ->collections as $ collection ) {
714
+ /** @var FileReference $fileReference */
715
+ foreach ($ collection as $ fileReference ) {
716
+ $ fUid = $ fileReference ->getOriginalFile ()->getUid ();
717
+ $ files [$ fUid ] = $ fUid ;
718
+ }
719
+ }
720
+ if (!in_array ($ recordUid , $ files )) {
721
+ $ this ->setFileNotFound ();
722
+ return $ this ->redirect ('list ' );
723
+ }
724
+
707
725
$ publicUri = '' ;
708
726
$ fileName = '' ;
709
727
$ fileModDate = '' ;
@@ -726,7 +744,7 @@ protected function downloadAction(): ResponseInterface
726
744
$ privateUri = $ this ->getPrivateUrlForNonPublic ($ file );
727
745
} else {
728
746
$ this ->setFileNotFound ();
729
- $ this ->redirect ($ returnToAction );
747
+ return $ this ->redirect ($ returnToAction );
730
748
}
731
749
if (!$ file ->isMissing () && is_file ($ privateUri ) && $ this ->feUserFileAccess ) {
732
750
/* update counter or set new */
@@ -735,15 +753,15 @@ protected function downloadAction(): ResponseInterface
735
753
} else {
736
754
if (!$ this ->feUserFileAccess ) {
737
755
$ this ->setFileNoAccess ();
738
- $ this ->redirect ($ returnToAction );
756
+ return $ this ->redirect ($ returnToAction );
739
757
} else {
740
758
$ this ->setFileNotFound ();
741
- $ this ->redirect ($ returnToAction );
759
+ return $ this ->redirect ($ returnToAction );
742
760
}
743
761
}
744
762
} else {
745
763
$ this ->setFileNotFound ();
746
- $ this ->redirect ('list ' );
764
+ return $ this ->redirect ('list ' );
747
765
}
748
766
}
749
767
return $ this ->responseFactory ->createResponse ();
@@ -761,7 +779,7 @@ protected function downloadAction(): ResponseInterface
761
779
* @return ResponseInterface
762
780
* @throws PropagateResponseException
763
781
*/
764
- protected function downloadFile ($ privateUri , $ fileName , $ publicUri , $ fileModDate = true ): ResponseInterface
782
+ protected function downloadFile (string $ privateUri , string $ fileName , string $ publicUri , bool $ fileModDate = true ): ResponseInterface
765
783
{
766
784
/* check if there is a setting to redirect only to the file */
767
785
if (isset ($ this ->settings ['redirecttofile ' ]) && (int )$ this ->settings ['redirecttofile ' ] === 1 ) {
0 commit comments