Skip to content

Commit 3ba5f1d

Browse files
committed
Use the new OCP method to get user with access to a file
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent ae378e5 commit 3ba5f1d

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

apps/systemtags/lib/Activity/Listener.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use OCP\App\IAppManager;
3030
use OCP\Files\Config\IMountProviderCollection;
3131
use OCP\Files\IRootFolder;
32-
use OCP\Files\Node;
3332
use OCP\IConfig;
3433
use OCP\IGroup;
3534
use OCP\IGroupManager;
@@ -171,22 +170,16 @@ public function mapperEvent(MapperEvent $event) {
171170

172171
// Get all mount point owners
173172
$cache = $this->mountCollection->getMountCache();
174-
$mounts = $cache->getMountsForFileId($event->getObjectId());
175-
if (empty($mounts)) {
176-
return;
177-
}
178173

179174
$users = [];
180-
foreach ($mounts as $mount) {
181-
$owner = $mount->getUser()->getUID();
182-
$ownerFolder = $this->rootFolder->getUserFolder($owner);
183-
$nodes = $ownerFolder->getById($event->getObjectId());
184-
if (!empty($nodes)) {
185-
/** @var Node $node */
186-
$node = array_shift($nodes);
187-
$al = $this->shareHelper->getPathsForAccessList($node);
188-
$users += $al['users'];
189-
}
175+
$filesPerUser = $cache->getFilesByUserId((int)$event->getComment()->getObjectId());
176+
if (empty($filesPerUser)) {
177+
return;
178+
}
179+
foreach ($filesPerUser as $user => $files) {
180+
/* Remove /user/files prefix */
181+
$sections = explode('/', reset($files)?->getPath() ?? '', 4);
182+
$users[$user] = '/'.($sections[3] ?? '');
190183
}
191184

192185
$actor = $this->session->getUser();

core/Command/Info/FileUtils.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,7 @@ public function getFilesByUser(FileInfo $file): array {
7272
return [];
7373
}
7474

75-
$mounts = $this->userMountCache->getMountsForFileId($id);
76-
$result = [];
77-
foreach ($mounts as $mount) {
78-
if (isset($result[$mount->getUser()->getUID()])) {
79-
continue;
80-
}
81-
82-
$userFolder = $this->rootFolder->getUserFolder($mount->getUser()->getUID());
83-
$result[$mount->getUser()->getUID()] = $userFolder->getById($id);
84-
}
85-
86-
return $result;
75+
return $this->userMountCache->getNodesByUserForFileId($id);
8776
}
8877

8978
/**

0 commit comments

Comments
 (0)