@@ -117,28 +117,24 @@ private function assertDocumentSession(ISessionAwareController $controller): voi
117117 */
118118 private function assertUserOrShareToken (ISessionAwareController $ controller ): void {
119119 $ documentId = (int )$ this ->request ->getParam ('documentId ' );
120- if (null !== $ userId = $ this ->userSession ->getUser ()?->getUID()) {
121- // Check if user has access to document
122- if (count ($ this ->rootFolder ->getUserFolder ($ userId )->getById ($ documentId )) === 0 ) {
123- throw new InvalidSessionException ();
124- }
125- $ controller ->setUserId ($ userId );
126- } elseif ('' !== $ shareToken = (string )$ this ->request ->getParam ('shareToken ' )) {
120+ $ shareToken = (string )$ this ->request ->getParam ('shareToken ' );
121+
122+ if ($ shareToken !== '' ) {
127123 try {
128124 $ share = $ this ->shareManager ->getShareByToken ($ shareToken );
129125 } catch (ShareNotFound ) {
130126 throw new InvalidSessionException ();
131127 }
132128
133- // Check if shareToken has access to document
134129 if (count ($ this ->rootFolder ->getUserFolder ($ share ->getShareOwner ())->getById ($ documentId )) === 0 ) {
135130 throw new InvalidSessionException ();
136131 }
137132
138133 /** @psalm-suppress RedundantConditionGivenDocblockType */
139134 if ($ share ->getPassword () !== null ) {
140- $ shareId = $ this ->session ->get ('public_link_authenticated ' );
141- if ($ share ->getId () !== $ shareId ) {
135+ $ shareIds = $ this ->session ->get ('public_link_authenticated ' );
136+ $ shareIds = is_array ($ shareIds ) ? $ shareIds : [$ shareIds ];
137+ if (!in_array ($ share ->getId (), $ shareIds , true )) {
142138 throw new InvalidSessionException ();
143139 }
144140 }
@@ -151,11 +147,21 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
151147 if ($ attributes !== null && $ attributes ->getAttribute ('permissions ' , 'download ' ) === false ) {
152148 throw new InvalidSessionException ();
153149 }
154- } else {
155- throw new InvalidSessionException ();
150+
151+ $ controller ->setDocumentId ($ documentId );
152+ return ;
156153 }
157154
158- $ controller ->setDocumentId ($ documentId );
155+ if (null !== $ userId = $ this ->userSession ->getUser ()?->getUID()) {
156+ if (count ($ this ->rootFolder ->getUserFolder ($ userId )->getById ($ documentId )) === 0 ) {
157+ throw new InvalidSessionException ();
158+ }
159+ $ controller ->setUserId ($ userId );
160+ $ controller ->setDocumentId ($ documentId );
161+ return ;
162+ }
163+
164+ throw new InvalidSessionException ();
159165 }
160166
161167 public function afterException ($ controller , $ methodName , \Exception $ exception ): JSONResponse |Response {
0 commit comments