From 88c685f27c39e39f05da231968c53117a97aedfb 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 da798af46cdb3..aa60ad56334ee 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 6419de7accfdb0d870aeb5cf48ae9ce0ad3cfb43 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 aa60ad56334ee..cb841755efd03 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 e59ebafc877ef5e02f88915eeb0b30c91156e242 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 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php index a91931501b421..39ffec0908b69 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -579,4 +579,30 @@ public function testInitWithNotFoundSource(): void { $this->assertInstanceOf(FailedStorage::class, $storage->getSourceStorage()); $this->assertInstanceOf(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); + } }