From 3ba5f1de95681cb2a2a04a02af4f632142e23ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 26 Jun 2023 15:54:46 +0200 Subject: [PATCH] Use the new OCP method to get user with access to a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/systemtags/lib/Activity/Listener.php | 23 ++++++++--------------- core/Command/Info/FileUtils.php | 13 +------------ 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/apps/systemtags/lib/Activity/Listener.php b/apps/systemtags/lib/Activity/Listener.php index ab897f3037af1..68145e21d29ea 100644 --- a/apps/systemtags/lib/Activity/Listener.php +++ b/apps/systemtags/lib/Activity/Listener.php @@ -29,7 +29,6 @@ use OCP\App\IAppManager; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\IRootFolder; -use OCP\Files\Node; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; @@ -171,22 +170,16 @@ public function mapperEvent(MapperEvent $event) { // Get all mount point owners $cache = $this->mountCollection->getMountCache(); - $mounts = $cache->getMountsForFileId($event->getObjectId()); - if (empty($mounts)) { - return; - } $users = []; - foreach ($mounts as $mount) { - $owner = $mount->getUser()->getUID(); - $ownerFolder = $this->rootFolder->getUserFolder($owner); - $nodes = $ownerFolder->getById($event->getObjectId()); - if (!empty($nodes)) { - /** @var Node $node */ - $node = array_shift($nodes); - $al = $this->shareHelper->getPathsForAccessList($node); - $users += $al['users']; - } + $filesPerUser = $cache->getFilesByUserId((int)$event->getComment()->getObjectId()); + if (empty($filesPerUser)) { + return; + } + foreach ($filesPerUser as $user => $files) { + /* Remove /user/files prefix */ + $sections = explode('/', reset($files)?->getPath() ?? '', 4); + $users[$user] = '/'.($sections[3] ?? ''); } $actor = $this->session->getUser(); diff --git a/core/Command/Info/FileUtils.php b/core/Command/Info/FileUtils.php index 1264dee5de21b..65a34a8bf2a35 100644 --- a/core/Command/Info/FileUtils.php +++ b/core/Command/Info/FileUtils.php @@ -72,18 +72,7 @@ public function getFilesByUser(FileInfo $file): array { return []; } - $mounts = $this->userMountCache->getMountsForFileId($id); - $result = []; - foreach ($mounts as $mount) { - if (isset($result[$mount->getUser()->getUID()])) { - continue; - } - - $userFolder = $this->rootFolder->getUserFolder($mount->getUser()->getUID()); - $result[$mount->getUser()->getUID()] = $userFolder->getById($id); - } - - return $result; + return $this->userMountCache->getNodesByUserForFileId($id); } /**