@@ -198,6 +198,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
198198 $ result ['expiration ' ] = $ expiration ->format ('Y-m-d 00:00:00 ' );
199199 }
200200
201+ $ currentUserPermissions = $ recipientNode ?->getPermissions() ?? Constants::PERMISSION_ALL ;
202+ $ userHasEnoughPermissions = ($ currentUserPermissions & $ share ->getPermissions ()) === $ share ->getPermissions ();
203+ $ token = $ userHasEnoughPermissions ? $ share ->getToken () : null ;
204+
201205 if ($ share ->getShareType () === IShare::TYPE_USER ) {
202206 $ sharedWith = $ this ->userManager ->get ($ share ->getSharedWith ());
203207 $ result ['share_with ' ] = $ share ->getSharedWith ();
@@ -223,6 +227,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
223227 $ result ['share_with ' ] = $ share ->getSharedWith ();
224228 $ result ['share_with_displayname ' ] = $ group !== null ? $ group ->getDisplayName () : $ share ->getSharedWith ();
225229 } elseif ($ share ->getShareType () === IShare::TYPE_LINK ) {
230+ $ url = ($ token !== null ) ? $ this ->urlGenerator ->linkToRouteAbsolute ('files_sharing.sharecontroller.showShare ' , ['token ' => $ token ]) : null ;
226231
227232 // "share_with" and "share_with_displayname" for passwords of link
228233 // shares was deprecated in Nextcloud 15, use "password" instead.
@@ -233,23 +238,23 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
233238
234239 $ result ['send_password_by_talk ' ] = $ share ->getSendPasswordByTalk ();
235240
236- $ result ['token ' ] = $ share -> getToken () ;
237- $ result ['url ' ] = $ this -> urlGenerator -> linkToRouteAbsolute ( ' files_sharing.sharecontroller.showShare ' , [ ' token ' => $ share -> getToken ()]) ;
241+ $ result ['token ' ] = $ token ;
242+ $ result ['url ' ] = $ url ;
238243 } elseif ($ share ->getShareType () === IShare::TYPE_REMOTE ) {
239244 $ result ['share_with ' ] = $ share ->getSharedWith ();
240245 $ result ['share_with_displayname ' ] = $ this ->getCachedFederatedDisplayName ($ share ->getSharedWith ());
241- $ result ['token ' ] = $ share -> getToken () ;
246+ $ result ['token ' ] = $ token ;
242247 } elseif ($ share ->getShareType () === IShare::TYPE_REMOTE_GROUP ) {
243248 $ result ['share_with ' ] = $ share ->getSharedWith ();
244249 $ result ['share_with_displayname ' ] = $ this ->getDisplayNameFromAddressBook ($ share ->getSharedWith (), 'CLOUD ' );
245- $ result ['token ' ] = $ share -> getToken () ;
250+ $ result ['token ' ] = $ token ;
246251 } elseif ($ share ->getShareType () === IShare::TYPE_EMAIL ) {
247252 $ result ['share_with ' ] = $ share ->getSharedWith ();
248253 $ result ['password ' ] = $ share ->getPassword ();
249254 $ result ['password_expiration_time ' ] = $ share ->getPasswordExpirationTime () !== null ? $ share ->getPasswordExpirationTime ()->format (\DateTime::ATOM ) : null ;
250255 $ result ['send_password_by_talk ' ] = $ share ->getSendPasswordByTalk ();
251256 $ result ['share_with_displayname ' ] = $ this ->getDisplayNameFromAddressBook ($ share ->getSharedWith (), 'EMAIL ' );
252- $ result ['token ' ] = $ share -> getToken () ;
257+ $ result ['token ' ] = $ token ;
253258 } elseif ($ share ->getShareType () === IShare::TYPE_CIRCLE ) {
254259 // getSharedWith() returns either "name (type, owner)" or
255260 // "name (type, owner) [id]", depending on the Teams app version.
0 commit comments