Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 10 additions & 4 deletions lib/ACL/ACLManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,24 @@ public function getPermissionsForTree(int $folderId, int $storageId, string $pat
$path = ltrim($path, '/');
$rules = $this->ruleManager->getRulesForPrefix($this->user, $storageId, $path);

// Both branches below can only remove permissions, so the starting value is a
// ceiling. Start from what the path itself resolves to rather than from the base
// permission: with "no permissions by default" the base is 0, which would deny
// every delete in the folder even where a rule grants it.
$treePermissions = $this->getACLPermissionsForPath($folderId, $storageId, $path);

if ($this->inheritMergePerUser) {
$pathsWithRules = array_keys($rules);
$permissions = $this->getBasePermission($folderId);
foreach ($pathsWithRules as $path) {
$permissions &= $this->getACLPermissionsForPath($folderId, $storageId, $path);
$permissions = $treePermissions;
foreach ($pathsWithRules as $rulePath) {
$permissions &= $this->getACLPermissionsForPath($folderId, $storageId, $rulePath);
}
return $permissions;
} else {
return array_reduce($rules, function (int $permissions, array $rules): int {
$mergedRule = Rule::mergeRules($rules);
return $mergedRule->applyDenyPermissions($permissions);
}, $this->getBasePermission($folderId));
}, $treePermissions);
}
}

Expand Down
31 changes: 31 additions & 0 deletions tests/ACL/ACLManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\GroupFolders\ACL\RuleManager;
use OCA\GroupFolders\ACL\UserMapping\IUserMapping;
use OCA\GroupFolders\ACL\UserMapping\IUserMappingManager;
use OCA\GroupFolders\Folder\FolderManager;
use OCP\Constants;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -336,4 +337,34 @@ public function testGetPermissionsForTree(): void {
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE, $perUserAclManager->getPermissionsForTree(0, 0, 'foo3'));
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE, $perUserAclManager->getPermissionsForTree(0, 0, 'foo3/bar'));
}

public function testGetPermissionsForTreeWithDefaultNoPermission(): void {
$folderManager = $this->createMock(FolderManager::class);
$folderManager->method('hasFolderACLDefaultNoPermission')->willReturn(true);
$folderManager->method('canManageACL')->willReturn(false);
$this->overwriteService(FolderManager::class, $folderManager);

try {
$this->rules = [
'foo' => [
new Rule($this->createMapping('1'), 10, Constants::PERMISSION_ALL, Constants::PERMISSION_ALL), // grant everything
],
];

foreach ([$this->getAclManager(), $this->getAclManager(true)] as $aclManager) {
$this->assertEquals(Constants::PERMISSION_ALL, $aclManager->getACLPermissionsForPath(0, 0, 'foo'));
$this->assertEquals(Constants::PERMISSION_ALL, $aclManager->getPermissionsForTree(0, 0, 'foo'));
}

$this->rules['foo/bar'] = [
new Rule($this->createMapping('1'), 10, Constants::PERMISSION_DELETE, 0), // remove delete
];

foreach ([$this->getAclManager(), $this->getAclManager(true)] as $aclManager) {
$this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE, $aclManager->getPermissionsForTree(0, 0, 'foo'));
}
} finally {
$this->restoreService(FolderManager::class);
}
}
}