@@ -116,13 +116,9 @@ private function assertDocumentSession(ISessionAwareController $controller): voi
116116 */
117117 private function assertUserOrShareToken (ISessionAwareController $ controller ): void {
118118 $ documentId = (int )$ this ->request ->getParam ('documentId ' );
119- if (null !== $ userId = $ this ->userSession ->getUser ()?->getUID()) {
120- // Check if user has access to document
121- if (count ($ this ->rootFolder ->getUserFolder ($ userId )->getById ($ documentId )) === 0 ) {
122- throw new InvalidSessionException ();
123- }
124- $ controller ->setUserId ($ userId );
125- } elseif ('' !== $ shareToken = (string )$ this ->request ->getParam ('shareToken ' )) {
119+ $ shareToken = (string )$ this ->request ->getParam ('shareToken ' );
120+
121+ if ($ shareToken !== '' ) {
126122 try {
127123 $ share = $ this ->shareManager ->getShareByToken ($ shareToken );
128124 } catch (ShareNotFound ) {
@@ -136,8 +132,9 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
136132
137133 /** @psalm-suppress RedundantConditionGivenDocblockType */
138134 if ($ share ->getPassword () !== null ) {
139- $ shareId = $ this ->session ->get ('public_link_authenticated ' );
140- 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 )) {
141138 throw new InvalidSessionException ();
142139 }
143140 }
@@ -150,6 +147,12 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
150147 if ($ attributes !== null && $ attributes ->getAttribute ('permissions ' , 'download ' ) === false ) {
151148 throw new InvalidSessionException ();
152149 }
150+ } elseif (null !== $ userId = $ this ->userSession ->getUser ()?->getUID()) {
151+ // Check if user has access to document
152+ if (count ($ this ->rootFolder ->getUserFolder ($ userId )->getById ($ documentId )) === 0 ) {
153+ throw new InvalidSessionException ();
154+ }
155+ $ controller ->setUserId ($ userId );
153156 } else {
154157 throw new InvalidSessionException ();
155158 }
0 commit comments