Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect permissions when copying shared files #48769

Merged
merged 3 commits into from
Dec 4, 2024
Merged
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
26 changes: 26 additions & 0 deletions apps/files_sharing/tests/SharedStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 8 additions & 1 deletion lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -1183,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(),
Expand All @@ -1196,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 {
Expand Down
Loading