diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2023-11-15 22:33:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 22:33:33 +0100 |
commit | 97f925bb41a917bd04c5574e3d9664a2d61b24f5 (patch) | |
tree | 6e29aa0f604a1e120dd0c63badd240847dbb8b30 /apps/files_sharing | |
parent | 1408509ee706a27bc5f9a04861c5e7f491444382 (diff) | |
parent | efda675b36784e693f4932cd723465dc7ddd8139 (diff) | |
download | nextcloud-server-97f925bb41a917bd04c5574e3d9664a2d61b24f5.tar.gz nextcloud-server-97f925bb41a917bd04c5574e3d9664a2d61b24f5.zip |
Merge pull request #41069 from nextcloud/backport/40495/stable27
[stable27] fix(sharing): set name to target name in sharing cache
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/Cache.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/tests/CacheTest.php | 37 |
2 files changed, 41 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index 594660661ca..af8e722c609 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -162,6 +162,10 @@ class Cache extends CacheJail { } else { $entry['permissions'] = $this->storage->getPermissions($entry['path']); } + + if ($this->share->getNodeId() === $entry['fileid']) { + $entry['name'] = basename($this->share->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) diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index f4f64bc6a32..50e5433d10f 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -88,6 +88,7 @@ class CacheTest extends TestCase { $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', '<xml></xml>'); + $this->view->file_put_contents('simplefile.txt', $textData); [$this->ownerStorage,] = $this->view->resolvePath(''); $this->ownerCache = $this->ownerStorage->getCache(); @@ -302,6 +303,42 @@ class CacheTest extends TestCase { ); } + /** + * 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); |