From 78ae7e5bde8bb005ec27a62c5453d5bc3e414c3c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 17 Oct 2024 18:08:25 +0200 Subject: [PATCH 1/3] fix: store unmaked source permissions as scan_permissions when loading share cache items Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Cache.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 0c176d92db7c9..cd5ee7ad9b64b 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -168,6 +168,9 @@ public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader if ($data['storage_mtime'] == 0) { $data['storage_mtime'] = $data['mtime']; } + if (isset($data['f_permissions'])) { + $data['scan_permissions'] = $data['f_permissions']; + } $data['permissions'] = (int)$data['permissions']; if (isset($data['creation_time'])) { $data['creation_time'] = (int)$data['creation_time']; From 36d991204c99e809f2873e714888e81360f84b46 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 17 Oct 2024 18:08:56 +0200 Subject: [PATCH 2/3] fix: use scan_permissions when copying cache items Signed-off-by: Robin Appelman --- lib/private/Files/Cache/Cache.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index cd5ee7ad9b64b..9168f7ba3e81f 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -1186,7 +1186,7 @@ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, str } private function cacheEntryToArray(ICacheEntry $entry): array { - return [ + $data = [ 'size' => $entry->getSize(), 'mtime' => $entry->getMTime(), 'storage_mtime' => $entry->getStorageMTime(), @@ -1199,6 +1199,10 @@ private function cacheEntryToArray(ICacheEntry $entry): array { 'upload_time' => $entry->getUploadTime(), 'metadata_etag' => $entry->getMetadataEtag(), ]; + if ($entry instanceof CacheEntry && isset($entry['scan_permissions'])) { + $data['permissions'] = $entry['scan_permissions']; + } + return $data; } public function getQueryFilterForStorage(): ISearchOperator { From 5afec1c0981e83533592857b446c46daf7f92ec8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 17 Oct 2024 18:29:52 +0200 Subject: [PATCH 3/3] test: add test for permissions of copied share Signed-off-by: Robin Appelman --- .../files_sharing/tests/SharedStorageTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php index f6557d1711d7b..c11cc90f75c8a 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -10,6 +10,7 @@ use OCA\Files_Sharing\SharedStorage; use OCA\Files_Trashbin\AppInfo\Application; use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\Constants; use OCP\Files\NotFoundException; use OCP\Share\IShare; @@ -578,4 +579,30 @@ public function testInitWithNotFoundSource() { $this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage()); $this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache()); } + + public function testCopyPermissions(): void { + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + + $share = $this->share( + IShare::TYPE_USER, + $this->filename, + self::TEST_FILES_SHARING_API_USER1, + self::TEST_FILES_SHARING_API_USER2, + Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE - Constants::PERMISSION_DELETE + ); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + $view = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); + $this->assertTrue($view->file_exists($this->filename)); + + $this->assertTrue($view->copy($this->filename, '/target.txt')); + + $this->assertTrue($view->file_exists('/target.txt')); + + $info = $view->getFileInfo('/target.txt'); + $this->assertEquals(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, $info->getPermissions()); + + $this->view->unlink($this->filename); + $this->shareManager->deleteShare($share); + } }