7777class ShareAPIController extends OCSController {
7878
7979 private ?Node $ lockedNode = null ;
80+ /** @var array<bool> $trustedServerCache */
8081 private array $ trustedServerCache = [];
8182
8283 /**
@@ -237,6 +238,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
237238 $ result ['expiration ' ] = $ expiration ->format ('Y-m-d 00:00:00 ' );
238239 }
239240
241+ $ currentUserPermissions = $ recipientNode ?->getPermissions() ?? Constants::PERMISSION_ALL ;
242+ $ userHasEnoughPermissions = ($ currentUserPermissions & $ share ->getPermissions ()) === $ share ->getPermissions ();
243+ $ token = $ userHasEnoughPermissions ? $ share ->getToken () : null ;
244+
240245 if ($ share ->getShareType () === IShare::TYPE_USER ) {
241246 $ sharedWith = $ this ->userManager ->get ($ share ->getSharedWith ());
242247 $ result ['share_with ' ] = $ share ->getSharedWith ();
@@ -262,6 +267,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
262267 $ result ['share_with ' ] = $ share ->getSharedWith ();
263268 $ result ['share_with_displayname ' ] = $ group !== null ? $ group ->getDisplayName () : $ share ->getSharedWith ();
264269 } elseif ($ share ->getShareType () === IShare::TYPE_LINK ) {
270+ $ url = $ token ? $ this ->urlGenerator ->linkToRouteAbsolute ('files_sharing.sharecontroller.showShare ' , ['token ' => $ token ]) : null ;
265271
266272 // "share_with" and "share_with_displayname" for passwords of link
267273 // shares was deprecated in Nextcloud 15, use "password" instead.
@@ -272,23 +278,23 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
272278
273279 $ result ['send_password_by_talk ' ] = $ share ->getSendPasswordByTalk ();
274280
275- $ result ['token ' ] = $ share -> getToken () ;
276- $ result ['url ' ] = $ this -> urlGenerator -> linkToRouteAbsolute ( ' files_sharing.sharecontroller.showShare ' , [ ' token ' => $ share -> getToken ()]) ;
281+ $ result ['token ' ] = $ token ;
282+ $ result ['url ' ] = $ url ;
277283 } elseif ($ share ->getShareType () === IShare::TYPE_REMOTE ) {
278284 $ result ['share_with ' ] = $ share ->getSharedWith ();
279285 $ result ['share_with_displayname ' ] = $ this ->getCachedFederatedDisplayName ($ share ->getSharedWith ());
280- $ result ['token ' ] = $ share -> getToken () ;
286+ $ result ['token ' ] = $ token ;
281287 } elseif ($ share ->getShareType () === IShare::TYPE_REMOTE_GROUP ) {
282288 $ result ['share_with ' ] = $ share ->getSharedWith ();
283289 $ result ['share_with_displayname ' ] = $ this ->getDisplayNameFromAddressBook ($ share ->getSharedWith (), 'CLOUD ' );
284- $ result ['token ' ] = $ share -> getToken () ;
290+ $ result ['token ' ] = $ token ;
285291 } elseif ($ share ->getShareType () === IShare::TYPE_EMAIL ) {
286292 $ result ['share_with ' ] = $ share ->getSharedWith ();
287293 $ result ['password ' ] = $ share ->getPassword ();
288294 $ result ['password_expiration_time ' ] = $ share ->getPasswordExpirationTime () !== null ? $ share ->getPasswordExpirationTime ()->format (\DateTime::ATOM ) : null ;
289295 $ result ['send_password_by_talk ' ] = $ share ->getSendPasswordByTalk ();
290296 $ result ['share_with_displayname ' ] = $ this ->getDisplayNameFromAddressBook ($ share ->getSharedWith (), 'EMAIL ' );
291- $ result ['token ' ] = $ share -> getToken () ;
297+ $ result ['token ' ] = $ token ;
292298 } elseif ($ share ->getShareType () === IShare::TYPE_CIRCLE ) {
293299 // getSharedWith() returns either "name (type, owner)" or
294300 // "name (type, owner) [id]", depending on the Teams app version.
0 commit comments