Skip to content

Commit

Permalink
Merge pull request #1133 from nextcloud/fix/noid/get-user-folder
Browse files Browse the repository at this point in the history
using getUserFolder
  • Loading branch information
nickvergessen authored Apr 13, 2023
2 parents 9ab7716 + c894c0e commit 1d9925b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use OCP\IUser;
use OCP\Share\IShare;
use OCP\Share\IShareHelper;
use Psr\Log\LoggerInterface;

/**
* The class to handle the filesystem hooks
Expand Down Expand Up @@ -1249,6 +1250,8 @@ private function getAffectedUsersFromCachedMounts(int $fileId): array {
* @return string[] list of unrelated userIds
*/
private function getUnrelatedUsers(int $fileId, array $cachedMounts): array {
$logger = \OC::$server->get(LoggerInterface::class);

/** @var \OCA\GroupFolders\ACL\RuleManager $ruleManager */
try {
$ruleManager = \OC::$server->get(\OCA\GroupFolders\ACL\RuleManager::class);
Expand All @@ -1272,7 +1275,15 @@ private function getUnrelatedUsers(int $fileId, array $cachedMounts): array {
if (!array_key_exists($cachedMount['visiblePath'], $knownRules[$storageId])) {
// we need mountPoint and folderId to generate the correct path
try {
$node = $this->rootFolder->get($fullPath);

// nc23 specific
[$userId, $str, $relativePath] = explode('/', ltrim($fullPath, '/'), 3);
$logger->debug('exploding fullPath', ['app' => 'activity', 'fullPath' => $fullPath, 'userId' => $userId, 'str' => $str, 'relativePath' => $relativePath]);
if ($str !== 'files') {
throw new NotFoundException();
}
$node = $this->rootFolder->getUserFolder($userId)->get($relativePath);

$mountPoint = $node->getMountPoint();

if (!$mountPoint instanceof \OCA\GroupFolders\Mount\GroupMountPoint) {
Expand All @@ -1282,6 +1293,7 @@ private function getUnrelatedUsers(int $fileId, array $cachedMounts): array {
$folderPath = trim($mountPoint->getSourcePath(), '/');
$path = substr($fullPath, strlen($mountPoint->getMountPoint()));
} catch (\Exception $e) {
$logger->debug('exception during First check', ['app' => 'activity', 'exception' => $e]);

// in case of issue during the process, we can imagine the user have no access to the file
$usersToCheck[] = $cachedMount['userId'];
Expand Down Expand Up @@ -1351,15 +1363,26 @@ private function getUnrelatedUsers(int $fileId, array $cachedMounts): array {
}
}

$logger->debug('users to check', ['app' => 'activity', 'users' => $usersToCheck]);

// now that we have a list of eventuals filtered users, we confirm they have no access to the file
$filteredUsers = [];
foreach ($usersToCheck as $userId) {
try {
$node = $this->rootFolder->get($cachedPath[$userId]);
$path = $cachedPath[$userId];
if (substr($path, 0, strlen($userId) + 8) !== '/' . $userId . '/files/') {
$logger->debug('wrong path format', ['app' => 'activity', 'userId' => $userId, 'prefix' => substr($path, 0, strlen($userId) + 8), 'path' => $path]);
throw new NotFoundException();
}

$path = substr($path, strlen($userId) + 7);
$logger->debug('getUserFolder', ['app' => 'activity', 'userId' => $userId, 'path' => $path]);
$node = $this->rootFolder->getUserFolder($userId)->get($path);
if ($node->isReadable()) {
continue; // overkill ? as rootFolder->get() would throw an exception if file is not available
}
} catch (\Exception $e) {
$logger->debug('exception while getUserFolder', ['app' => 'activity', 'exception' => $e]);
}

$filteredUsers[] = $userId;
Expand Down

0 comments on commit 1d9925b

Please sign in to comment.