7474class ShareAPIController extends OCSController {
7575
7676 private ?Node $ lockedNode = null ;
77+ /** @var array<bool> $trustedServerCache */
7778 private array $ trustedServerCache = [];
7879
7980 /**
@@ -233,6 +234,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
233234 $ result ['expiration ' ] = $ expiration ->format ('Y-m-d 00:00:00 ' );
234235 }
235236
237+ $ currentUserPermissions = $ recipientNode ?->getPermissions() ?? Constants::PERMISSION_ALL ;
238+ $ userHasEnoughPermissions = ($ currentUserPermissions & $ share ->getPermissions ()) === $ share ->getPermissions ();
239+ $ token = $ userHasEnoughPermissions ? $ share ->getToken () : null ;
240+
236241 if ($ share ->getShareType () === IShare::TYPE_USER ) {
237242 $ sharedWith = $ this ->userManager ->get ($ share ->getSharedWith ());
238243 $ result ['share_with ' ] = $ share ->getSharedWith ();
@@ -258,6 +263,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
258263 $ result ['share_with ' ] = $ share ->getSharedWith ();
259264 $ result ['share_with_displayname ' ] = $ group !== null ? $ group ->getDisplayName () : $ share ->getSharedWith ();
260265 } elseif ($ share ->getShareType () === IShare::TYPE_LINK ) {
266+ $ url = $ token ? $ this ->urlGenerator ->linkToRouteAbsolute ('files_sharing.sharecontroller.showShare ' , ['token ' => $ token ]) : null ;
261267
262268 // "share_with" and "share_with_displayname" for passwords of link
263269 // shares was deprecated in Nextcloud 15, use "password" instead.
@@ -268,23 +274,23 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
268274
269275 $ result ['send_password_by_talk ' ] = $ share ->getSendPasswordByTalk ();
270276
271- $ result ['token ' ] = $ share -> getToken () ;
272- $ result ['url ' ] = $ this -> urlGenerator -> linkToRouteAbsolute ( ' files_sharing.sharecontroller.showShare ' , [ ' token ' => $ share -> getToken ()]) ;
277+ $ result ['token ' ] = $ token ;
278+ $ result ['url ' ] = $ url ;
273279 } elseif ($ share ->getShareType () === IShare::TYPE_REMOTE ) {
274280 $ result ['share_with ' ] = $ share ->getSharedWith ();
275281 $ result ['share_with_displayname ' ] = $ this ->getCachedFederatedDisplayName ($ share ->getSharedWith ());
276- $ result ['token ' ] = $ share -> getToken () ;
282+ $ result ['token ' ] = $ token ;
277283 } elseif ($ share ->getShareType () === IShare::TYPE_REMOTE_GROUP ) {
278284 $ result ['share_with ' ] = $ share ->getSharedWith ();
279285 $ result ['share_with_displayname ' ] = $ this ->getDisplayNameFromAddressBook ($ share ->getSharedWith (), 'CLOUD ' );
280- $ result ['token ' ] = $ share -> getToken () ;
286+ $ result ['token ' ] = $ token ;
281287 } elseif ($ share ->getShareType () === IShare::TYPE_EMAIL ) {
282288 $ result ['share_with ' ] = $ share ->getSharedWith ();
283289 $ result ['password ' ] = $ share ->getPassword ();
284290 $ result ['password_expiration_time ' ] = $ share ->getPasswordExpirationTime () !== null ? $ share ->getPasswordExpirationTime ()->format (\DateTime::ATOM ) : null ;
285291 $ result ['send_password_by_talk ' ] = $ share ->getSendPasswordByTalk ();
286292 $ result ['share_with_displayname ' ] = $ this ->getDisplayNameFromAddressBook ($ share ->getSharedWith (), 'EMAIL ' );
287- $ result ['token ' ] = $ share -> getToken () ;
293+ $ result ['token ' ] = $ token ;
288294 } elseif ($ share ->getShareType () === IShare::TYPE_CIRCLE ) {
289295 // getSharedWith() returns either "name (type, owner)" or
290296 // "name (type, owner) [id]", depending on the Teams app version.
0 commit comments