Skip to content

Commit fcca971

Browse files
authored
Merge pull request #41073 from nextcloud/backport/40495/stable25
[stable25] fix(sharing): set name to target name in sharing cache
2 parents 57def1e + 6ea20ec commit fcca971

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

apps/files_sharing/lib/Cache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ protected function formatCacheEntry($entry, $path = null) {
154154
} else {
155155
$entry['permissions'] = $this->storage->getPermissions($entry['path']);
156156
}
157+
158+
if ($this->storage->getShare()->getNodeId() === $entry['fileid']) {
159+
$entry['name'] = basename($this->storage->getShare()->getTarget());
160+
}
157161
} catch (StorageNotAvailableException $e) {
158162
// thrown by FailedStorage e.g. when the sharer does not exist anymore
159163
// (IDE may say the exception is never thrown – false negative)

apps/files_sharing/tests/CacheTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ protected function setUp(): void {
8888
$this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData);
8989
$this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
9090
$this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '<xml></xml>');
91+
$this->view->file_put_contents('simplefile.txt', $textData);
9192

9293
[$this->ownerStorage,] = $this->view->resolvePath('');
9394
$this->ownerCache = $this->ownerStorage->getCache();
@@ -302,6 +303,42 @@ public function testGetFolderContentsInSubdir() {
302303
);
303304
}
304305

306+
/**
307+
* This covers a bug where the share owners name was propagated
308+
* to the recipient in the recent files API response where the
309+
* share recipient has a different target set
310+
*
311+
* https://github.com/nextcloud/server/issues/39879
312+
*/
313+
public function testShareRenameOriginalFileInRecentResults() {
314+
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
315+
316+
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
317+
$node = $rootFolder->get('simplefile.txt');
318+
$share = $this->shareManager->newShare();
319+
$share->setNode($node)
320+
->setShareType(IShare::TYPE_USER)
321+
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
322+
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
323+
->setPermissions(\OCP\Constants::PERMISSION_READ);
324+
$share = $this->shareManager->createShare($share);
325+
$share->setStatus(IShare::STATUS_ACCEPTED);
326+
$this->shareManager->updateShare($share);
327+
328+
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
329+
$node->move(self::TEST_FILES_SHARING_API_USER1 . '/files/simplefile2.txt');
330+
331+
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
332+
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
333+
$recents = $rootFolder->getRecent(10);
334+
self::assertEquals([
335+
'welcome.txt',
336+
'simplefile.txt'
337+
], array_map(function($node) {
338+
return $node->getFileInfo()['name'];
339+
}, $recents));
340+
}
341+
305342
public function testGetFolderContentsWhenSubSubdirShared() {
306343
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
307344

0 commit comments

Comments
 (0)