Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Use the new OCP method to get user with access to a file
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Sep 14, 2024
commit fd8c6ac9ede7b46ad1fd50f53e31b10e633b6384
23 changes: 8 additions & 15 deletions apps/systemtags/lib/Activity/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 @@ -153,22 +152,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->getReadableNodesByUserForFileId((int)$event->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 @@ -44,18 +44,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->getReadableNodesByUserForFileId($id);
}

/**
Expand Down