Skip to content

Commit

Permalink
more debugging for 120
Browse files Browse the repository at this point in the history
  • Loading branch information
eldertek committed Jan 22, 2025
1 parent 1c7f070 commit 45a765e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 26 deletions.
22 changes: 17 additions & 5 deletions lib/Service/FileDuplicateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,32 @@ private function stripFilesWithoutAccessRights(
FileDuplicate $duplicate,
string $user
): FileDuplicate {
$this->logger->debug('Stripping files without access rights for user: {user}', ['user' => $user]);
$this->logger->debug('FileDuplicateService::stripFilesWithoutAccessRights - Starting', [
'user' => $user,
'hash' => $duplicate->getHash(),
'type' => $duplicate->getType()
]);

$files = $this->fileInfoService->findByHash($duplicate->getHash(), $duplicate->getType());
$accessibleFiles = [];
$this->logger->debug('FileDuplicateService::stripFilesWithoutAccessRights - Found files', [
'total_files' => count($files)
]);

$accessibleFiles = [];
foreach ($files as $fileInfo) {
$this->logger->debug('FileDuplicateService::stripFilesWithoutAccessRights - Checking file', [
'path' => $fileInfo->getPath(),
'owner' => $fileInfo->getOwner()
]);

if ($this->fileInfoService->hasAccessRight($fileInfo, $user)) {
$accessibleFiles[] = $fileInfo;
}
}

$this->logger->debug('Found {count} accessible files out of {total}', [
'count' => count($accessibleFiles),
'total' => count($files)
$this->logger->debug('FileDuplicateService::stripFilesWithoutAccessRights - Results', [
'accessible_count' => count($accessibleFiles),
'total_count' => count($files)
]);

$duplicate->setFiles($accessibleFiles);
Expand Down
31 changes: 27 additions & 4 deletions lib/Service/FileInfoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,17 +688,40 @@ private function disableAllLocks(?OutputInterface $output): void

public function hasAccessRight(FileInfo $fileInfo, string $user): bool
{
$this->logger->debug('FileInfoService::hasAccessRight - Starting access check', [
'user' => $user,
'file_owner' => $fileInfo->getOwner(),
'file_path' => $fileInfo->getPath()
]);

if ($fileInfo->getOwner() === $user) {
$this->logger->debug('FileInfoService::hasAccessRight - User is owner, granting access');
return true;
}

try {
$path = $this->shareService->hasAccessRight(
$this->folderService->getNodeByFileInfo($fileInfo, $user),
$user
);
$node = $this->folderService->getNodeByFileInfo($fileInfo, $user);
$this->logger->debug('FileInfoService::hasAccessRight - Got node for file', [
'node_path' => $node->getPath(),
'node_type' => get_class($node)
]);

$path = $this->shareService->hasAccessRight($node, $user);
$this->logger->debug('FileInfoService::hasAccessRight - Share service response', [
'has_access' => !is_null($path),
'resolved_path' => $path
]);
return !is_null($path);
} catch (NotFoundException $e) {
$this->logger->debug('FileInfoService::hasAccessRight - Node not found', [
'exception' => $e->getMessage()
]);
return false;
} catch (\Throwable $e) {
$this->logger->error('FileInfoService::hasAccessRight - Unexpected error', [
'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
return false;
}
}
Expand Down
49 changes: 32 additions & 17 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,40 @@ public function getShares(

public function hasAccessRight(Node $sharedNode, string $user) : ?string
{
$accessList = $this->shareManager->getAccessList($sharedNode, true, true);
if (isset($accessList['users']) && isset($accessList['users'][$user])) {
$node = $sharedNode;
$stripedFolders = 0;
while ($node) {
$shares = $this->getShares($user, $node, 1);
if (!empty($shares)) {
$this->logger->debug('Target Path: @'.$shares[0]->getTarget().'@ '.$shares[0]->getNodeType());
return PathConversionUtils::convertSharedPath(
$this->rootFolder->getUserFolder($user),
$this->rootFolder->getUserFolder($shares[0]->getSharedWith()),
$sharedNode,
$shares[0],
$stripedFolders
);
$this->logger->debug('ShareService::hasAccessRight - Checking access rights', [
'user' => $user,
'node_path' => $sharedNode->getPath(),
'node_owner' => $sharedNode->getOwner() ? $sharedNode->getOwner()->getUID() : 'null'
]);

try {
$accessList = $this->shareManager->getAccessList($sharedNode, true, true);
$this->logger->debug('ShareService::hasAccessRight - Access list retrieved', [
'has_user_access' => isset($accessList['users']) && isset($accessList['users'][$user]),
'access_list_users' => isset($accessList['users']) ? array_keys($accessList['users']) : []
]);

if (isset($accessList['users']) && isset($accessList['users'][$user])) {
$node = $sharedNode;
$stripedFolders = 0;
while ($node) {
$shares = $this->getShares($user, $node, 1);
if (!empty($shares)) {
$this->logger->debug('Target Path: @'.$shares[0]->getTarget().'@ '.$shares[0]->getNodeType());
return PathConversionUtils::convertSharedPath(
$this->rootFolder->getUserFolder($user),
$this->rootFolder->getUserFolder($shares[0]->getSharedWith()),
$sharedNode,
$shares[0],
$stripedFolders
);
}
$node = $node->getParent();
$stripedFolders++;
}
$node = $node->getParent();
$stripedFolders++;
}
} catch (\Throwable $e) {
$this->logger->error('Failed to check access rights', ['exception'=> $e]);
}
return null;
}
Expand Down

0 comments on commit 45a765e

Please sign in to comment.