From c0c8809f69dc55a780f8a55b1adf1f653c87f96f Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 19 Sep 2023 10:54:48 +0200 Subject: [PATCH 1/2] fix(sharing): set name to target name in sharing cache Fixes #39879. Signed-off-by: Max --- apps/files_sharing/lib/Cache.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index aa45b6ab43e0d..20d9765d597ea 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -154,6 +154,10 @@ protected function formatCacheEntry($entry, $path = null) { } else { $entry['permissions'] = $this->storage->getPermissions($entry['path']); } + + if ($this->storage->getShare()->getNodeId() === $entry['fileid']) { + $entry['name'] = basename($this->storage->getShare()->getTarget()); + } } catch (StorageNotAvailableException $e) { // thrown by FailedStorage e.g. when the sharer does not exist anymore // (IDE may say the exception is never thrown – false negative) From 6ea20ecb9b42f870243372766bb715bdff70f5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 18 Oct 2023 14:29:14 +0200 Subject: [PATCH 2/2] test(files_sharing): Test if recent files result use actual share target name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files_sharing/tests/CacheTest.php | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index f4f64bc6a328e..50e5433d10f56 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -88,6 +88,7 @@ protected function setUp(): void { $this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData); $this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData); $this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', ''); + $this->view->file_put_contents('simplefile.txt', $textData); [$this->ownerStorage,] = $this->view->resolvePath(''); $this->ownerCache = $this->ownerStorage->getCache(); @@ -302,6 +303,42 @@ public function testGetFolderContentsInSubdir() { ); } + /** + * This covers a bug where the share owners name was propagated + * to the recipient in the recent files API response where the + * share recipient has a different target set + * + * https://github.com/nextcloud/server/issues/39879 + */ + public function testShareRenameOriginalFileInRecentResults() { + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + + $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1); + $node = $rootFolder->get('simplefile.txt'); + $share = $this->shareManager->newShare(); + $share->setNode($node) + ->setShareType(IShare::TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER3) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER1) + ->setPermissions(\OCP\Constants::PERMISSION_READ); + $share = $this->shareManager->createShare($share); + $share->setStatus(IShare::STATUS_ACCEPTED); + $this->shareManager->updateShare($share); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + $node->move(self::TEST_FILES_SHARING_API_USER1 . '/files/simplefile2.txt'); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER3); + $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER3); + $recents = $rootFolder->getRecent(10); + self::assertEquals([ + 'welcome.txt', + 'simplefile.txt' + ], array_map(function($node) { + return $node->getFileInfo()['name']; + }, $recents)); + } + public function testGetFolderContentsWhenSubSubdirShared() { self::loginHelper(self::TEST_FILES_SHARING_API_USER1);