diff options
-rw-r--r-- | apps/comments/lib/Activity/Listener.php | 7 | ||||
-rw-r--r-- | apps/systemtags/lib/Activity/Listener.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 39 | ||||
-rw-r--r-- | lib/public/Files/Config/IUserMountCache.php | 9 |
4 files changed, 50 insertions, 13 deletions
diff --git a/apps/comments/lib/Activity/Listener.php b/apps/comments/lib/Activity/Listener.php index 5e79b5fda73..939f17dcd2e 100644 --- a/apps/comments/lib/Activity/Listener.php +++ b/apps/comments/lib/Activity/Listener.php @@ -37,10 +37,9 @@ class Listener { $cache = $this->mountCollection->getMountCache(); - $users = []; - $filesPerUser = $cache->getReadableNodesByUserForFileId((int)$event->getComment()->getObjectId()); - foreach ($filesPerUser as $user => $files) { - $users[$user] = $this->rootFolder->getUserFolder($user)->getRelativePath(reset($files)?->getPath() ?? ''); + $users = $cache->getReadablePathByUserForFileId((int)$event->getComment()->getObjectId()); + if (empty($users)) { + return; } $actor = $this->session->getUser(); diff --git a/apps/systemtags/lib/Activity/Listener.php b/apps/systemtags/lib/Activity/Listener.php index cfd5fefb08d..1fdad6f42c9 100644 --- a/apps/systemtags/lib/Activity/Listener.php +++ b/apps/systemtags/lib/Activity/Listener.php @@ -153,14 +153,10 @@ class Listener { // Get all mount point owners $cache = $this->mountCollection->getMountCache(); - $users = []; - $filesPerUser = $cache->getReadableNodesByUserForFileId((int)$event->getObjectId()); - if (empty($filesPerUser)) { + $users = $cache->getReadablePathByUserForFileId((int)$event->getObjectId()); + if (empty($users)) { return; } - foreach ($filesPerUser as $user => $files) { - $users[$user] = $this->rootFolder->getUserFolder($user)->getRelativePath(reset($files)?->getPath() ?? ''); - } $actor = $this->session->getUser(); if ($actor instanceof IUser) { diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 0d72e3a6d4f..2445f54c56a 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -395,12 +395,45 @@ class UserMountCache implements IUserMountCache { $rootFolder = Server::get(IRootFolder::class); $result = []; foreach ($mounts as $mount) { - if (isset($result[$mount->getUser()->getUID()])) { + $uid = $mount->getUser()->getUID(); + if (!isset($result[$uid])) { + $result[$uid] = []; + } + + $userFolder = $rootFolder->getUserFolder($uid); + $result[$uid] = array_merge($result[$uid], $userFolder->getById($fileId)); + } + + return array_filter($result); + } + + /** + * Get all users having read access to a file, with a path they see it as. + * They may see the same file under other paths, + * to get this information use the exhaustive getReadableNodesByUserForFileId + * + * @return array<string,string> Paths giving access to the given fileId, indexed by user ID + * @since 28.0.0 + */ + public function getReadablePathByUserForFileId(int $fileId): array { + $mounts = $this->getMountsForFileId($fileId); + $rootFolder = Server::get(IRootFolder::class); + $result = []; + foreach ($mounts as $mount) { + $uid = $mount->getUser()->getUID(); + if (isset($result[$uid])) { continue; } - $userFolder = $rootFolder->getUserFolder($mount->getUser()->getUID()); - $result[$mount->getUser()->getUID()] = $userFolder->getById($fileId); + $userFolder = $rootFolder->getUserFolder($uid); + $nodes = $userFolder->getById($fileId); + $node = reset($nodes); + if ($node) { + $path = $userFolder->getRelativePath($node->getPath()); + if ($path !== null) { + $result[$uid] = $path; + } + } } return $result; diff --git a/lib/public/Files/Config/IUserMountCache.php b/lib/public/Files/Config/IUserMountCache.php index 2ec368f80ad..5c4fcf83f4a 100644 --- a/lib/public/Files/Config/IUserMountCache.php +++ b/lib/public/Files/Config/IUserMountCache.php @@ -75,6 +75,15 @@ interface IUserMountCache { public function getReadableNodesByUserForFileId(int $fileId): array; /** + * Get all users having read access to a file, with a path they see it as. + * They may see the same file under other paths, to get this information use exhaustive getReadableNodesByUserForFileId + * + * @return array<string, string> Paths giving access to the given fileId, indexed by user ID + * @since 28.0.0 + */ + public function getReadablePathByUserForFileId(int $fileId): array; + + /** * Remove all cached mounts for a user * * @param IUser $user |