@@ -309,7 +309,7 @@ public function uploadAttachment(int $documentId, string $newFileName, $newFileR
309309 * @throws InvalidPathException
310310 * @throws NoUserException
311311 */
312- public function uploadAttachmentPublic (? int $ documentId , string $ newFileName , $ newFileResource , string $ shareToken ): array {
312+ public function uploadAttachmentPublic (int $ documentId , string $ newFileName , $ newFileResource , string $ shareToken ): array {
313313 try {
314314 $ share = $ this ->shareManager ->getShareByToken ($ shareToken );
315315 } catch (ShareNotFound ) {
@@ -541,32 +541,23 @@ private function getTextFile(int $documentId, string $userId): File {
541541 *
542542 * @throws NotFoundException
543543 */
544- private function getTextFilePublic (? int $ documentId , string $ shareToken ): File {
545- // is the file shared with this token?
544+ private function getTextFilePublic (int $ documentId , string $ shareToken ): File {
545+ // TODO: Lazy load the context and enable these additional checks inside the context
546546 try {
547547 $ share = $ this ->shareManager ->getShareByToken ($ shareToken );
548- if (in_array ($ share ->getShareType (), [IShare::TYPE_LINK , IShare::TYPE_EMAIL ])) {
549- // shared file or folder?
550- if ($ share ->getNodeType () === 'file ' ) {
551- $ textFile = $ share ->getNode ();
552- if ($ textFile instanceof File
553- && !$ this ->isDownloadDisabled ($ textFile )
554- && $ textFile ->getId () === $ documentId
555- ) {
556- return $ textFile ;
557- }
558- } elseif ($ documentId !== null && $ share ->getNodeType () === 'folder ' ) {
559- $ folder = $ share ->getNode ();
560- if ($ folder instanceof Folder) {
561- $ textFile = $ folder ->getFirstNodeById ($ documentId );
562- if ($ textFile instanceof File && !$ this ->isDownloadDisabled ($ textFile )) {
563- return $ textFile ;
564- }
565- }
566- }
567- }
568548 } catch (ShareNotFound ) {
569- // same as below
549+ throw new NotFoundException ();
550+ }
551+ if (!in_array ($ share ->getShareType (), [IShare::TYPE_LINK , IShare::TYPE_EMAIL ])) {
552+ throw new NotFoundException ();
553+ }
554+ $ document = $ this ->documentMapper ->find ($ documentId );
555+ $ type = $ document ->getContextType ();
556+ $ id = $ document ->getContextId ();
557+ $ context = $ this ->contextManager ->getContext ($ type , $ id , $ shareToken );
558+ $ file = $ context ->getFile ();
559+ if ($ file instanceof File && !$ this ->isDownloadDisabled ($ file )) {
560+ return $ file ;
570561 }
571562 throw new NotFoundException ('Text file with id= ' . (string )$ documentId . ' and shareToken ' . $ shareToken . ' was not found. ' );
572563 }
0 commit comments