Skip to content

Commit

Permalink
Use the new OCP method to get user with access to a file
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jun 26, 2023
1 parent ae378e5 commit 3ba5f1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
23 changes: 8 additions & 15 deletions apps/systemtags/lib/Activity/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 1 addition & 12 deletions core/Command/Info/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 3ba5f1d

Please sign in to comment.