From b300219d012405dfcb94402b25a4b4a197bcff70 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 9 Feb 2024 15:28:29 +0100 Subject: [PATCH 1/4] don't error if we can't find a trashbin item for a file when looking for relevant acl paths Signed-off-by: Robin Appelman --- lib/ACL/ACLManager.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ACL/ACLManager.php b/lib/ACL/ACLManager.php index 00055f14a..5f5a834d7 100644 --- a/lib/ACL/ACLManager.php +++ b/lib/ACL/ACLManager.php @@ -117,9 +117,11 @@ private function getRelevantPaths(string $path): array { if ($fromTrashbin && ($path === '__groupfolders/trash')) { /* We are in trash and hit the root folder, continue looking for ACLs on parent folders in original location */ $trashItemRow = $this->trashManager->getTrashItemByFileName($groupFolderId, $rootTrashedItemName, $rootTrashedItemDate); - $path = dirname('__groupfolders/' . $groupFolderId . '/' . $trashItemRow['original_location']); $fromTrashbin = false; - continue; + if ($trashItemRow) { + $path = dirname('__groupfolders/' . $groupFolderId . '/' . $trashItemRow['original_location']); + continue; + } } if ($path === '.' || $path === '/') { From 03be9e2cc3b11059c366a2e2bb6f4c73657135e2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 May 2024 15:37:00 +0200 Subject: [PATCH 2/4] fix: log when no trash item is found Signed-off-by: Robin Appelman --- lib/ACL/ACLManager.php | 4 ++++ lib/ACL/ACLManagerFactory.php | 3 +++ lib/AppInfo/Application.php | 1 + 3 files changed, 8 insertions(+) diff --git a/lib/ACL/ACLManager.php b/lib/ACL/ACLManager.php index 5f5a834d7..56c9d8d29 100644 --- a/lib/ACL/ACLManager.php +++ b/lib/ACL/ACLManager.php @@ -28,6 +28,7 @@ use OCP\Constants; use OCP\Files\IRootFolder; use OCP\IUser; +use Psr\Log\LoggerInterface; class ACLManager { private CappedMemoryCache $ruleCache; @@ -37,6 +38,7 @@ class ACLManager { public function __construct( private RuleManager $ruleManager, private TrashManager $trashManager, + private LoggerInterface $logger, private IUser $user, callable $rootFolderProvider, private ?int $rootStorageId = null, @@ -121,6 +123,8 @@ private function getRelevantPaths(string $path): array { if ($trashItemRow) { $path = dirname('__groupfolders/' . $groupFolderId . '/' . $trashItemRow['original_location']); continue; + } else { + $this->logger->warning("failed to find trash item for $rootTrashedItemName deleted at $rootTrashedItemDate in folder $groupFolderId", ['app' => 'groupfolders']); } } diff --git a/lib/ACL/ACLManagerFactory.php b/lib/ACL/ACLManagerFactory.php index 11ea7ddfb..f9ce57e77 100644 --- a/lib/ACL/ACLManagerFactory.php +++ b/lib/ACL/ACLManagerFactory.php @@ -26,6 +26,7 @@ use OCA\GroupFolders\Trash\TrashManager; use OCP\IConfig; use OCP\IUser; +use Psr\Log\LoggerInterface; class ACLManagerFactory { private $rootFolderProvider; @@ -34,6 +35,7 @@ public function __construct( private RuleManager $ruleManager, private TrashManager $trashManager, private IConfig $config, + private LoggerInterface $logger, callable $rootFolderProvider, ) { $this->rootFolderProvider = $rootFolderProvider; @@ -43,6 +45,7 @@ public function getACLManager(IUser $user, ?int $rootStorageId = null): ACLManag return new ACLManager( $this->ruleManager, $this->trashManager, + $this->logger, $user, $this->rootFolderProvider, $rootStorageId, diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 7cf1222bd..fe1040695 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -227,6 +227,7 @@ public function register(IRegistrationContext $context): void { $c->get(RuleManager::class), $c->get(TrashManager::class), $c->get(IConfig::class), + $c->get(LoggerInterface::class), $rootFolderProvider ); }); From 69f808dd7bfb7b117b7b85d4bf6290c29bbe24f0 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:48:47 +0200 Subject: [PATCH 3/4] fix: ACLManager tests Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> chore: optimize code Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> fix: call logger Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> fix: Add LoggerInterface Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> Fix: Typo Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- tests/ACL/ACLManagerTest.php | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/ACL/ACLManagerTest.php b/tests/ACL/ACLManagerTest.php index 1b0ea88dc..b733fb926 100644 --- a/tests/ACL/ACLManagerTest.php +++ b/tests/ACL/ACLManagerTest.php @@ -32,21 +32,18 @@ use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\IUser; +use Psr\Log\LoggerInterface; use Test\TestCase; class ACLManagerTest extends TestCase { - /** @var RuleManager */ - private $ruleManager; - /** @var TrashManager */ - private $trashManager; - /** @var IUser */ - private $user; - /** @var ACLManager */ - private $aclManager; - /** @var IUserMapping */ - private $dummyMapping; + private RuleManager $ruleManager; + private TrashManager $trashManager; + private LoggerInterface $logger; + private IUser $user; + private ACLManager $aclManager; + private IUserMapping $dummyMapping; /** @var Rule[] */ - private $rules = []; + private array $rules = []; protected function setUp(): void { parent::setUp(); @@ -54,6 +51,7 @@ protected function setUp(): void { $this->user = $this->createMock(IUser::class); $this->ruleManager = $this->createMock(RuleManager::class); $this->trashManager = $this->createMock(TrashManager::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->aclManager = $this->getAclManager(); $this->dummyMapping = $this->createMapping('dummy'); @@ -77,7 +75,7 @@ private function createMapping(string $id): IUserMapping { return $mapping; } - private function getAclManager(bool $perUserMerge = false) { + private function getAclManager(bool $perUserMerge = false): ACLManager { $rootMountPoint = $this->createMock(IMountPoint::class); $rootMountPoint->method('getNumericStorageId') ->willReturn(1); @@ -85,17 +83,17 @@ private function getAclManager(bool $perUserMerge = false) { $rootFolder->method('getMountPoint') ->willReturn($rootMountPoint); - return new ACLManager($this->ruleManager, $this->trashManager, $this->user, function () use ($rootFolder) { + return new ACLManager($this->ruleManager, $this->trashManager, $this->logger, $this->user, function () use ($rootFolder) { return $rootFolder; }, null, $perUserMerge); } - public function testGetACLPermissionsForPathNoRules() { + public function testGetACLPermissionsForPathNoRules(): void { $this->rules = []; $this->assertEquals(Constants::PERMISSION_ALL, $this->aclManager->getACLPermissionsForPath('foo')); } - public function testGetACLPermissionsForPath() { + public function testGetACLPermissionsForPath(): void { $this->rules = [ 'foo' => [ new Rule($this->createMapping('1'), 10, Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE, Constants::PERMISSION_READ), // read only @@ -121,7 +119,7 @@ public function testGetACLPermissionsForPath() { $this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE - Constants::PERMISSION_READ, $this->aclManager->getACLPermissionsForPath('foo/blocked2')); } - public function testGetACLPermissionsForPathInTrashbin() { + public function testGetACLPermissionsForPathInTrashbin(): void { $this->rules = [ '__groupfolders/1' => [ new Rule($this->dummyMapping, 10, Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE, Constants::PERMISSION_READ), // read only @@ -151,7 +149,7 @@ public function testGetACLPermissionsForPathInTrashbin() { - public function testGetACLPermissionsForPathPerUserMerge() { + public function testGetACLPermissionsForPathPerUserMerge(): void { $aclManager = $this->getAclManager(true); $this->rules = [ 'foo' => [ From 63ffb975e4e411baa3b6380b1ea87e6d4332216f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 30 Aug 2024 11:12:17 +0200 Subject: [PATCH 4/4] fix: stylelint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- src/settings/FolderGroups.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/settings/FolderGroups.scss b/src/settings/FolderGroups.scss index 8c5d3c49c..faee30512 100644 --- a/src/settings/FolderGroups.scss +++ b/src/settings/FolderGroups.scss @@ -17,7 +17,7 @@ } // Fit group selection - &[colspan="5"] { + &[colspan='5'] { padding: 0; .no-options-available { @@ -43,7 +43,7 @@ text-align: center; // Align checkboxes with close button and text - input[type="checkbox"] { + input[type='checkbox'] { vertical-align: middle; } }