Skip to content

Commit

Permalink
Merge pull request #41073 from nextcloud/backport/40495/stable25
Browse files Browse the repository at this point in the history
[stable25] fix(sharing): set name to target name in sharing cache
  • Loading branch information
blizzz authored Dec 14, 2023
2 parents 57def1e + 6ea20ec commit fcca971
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/files_sharing/lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions apps/files_sharing/tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<xml></xml>');
$this->view->file_put_contents('simplefile.txt', $textData);

[$this->ownerStorage,] = $this->view->resolvePath('');
$this->ownerCache = $this->ownerStorage->getCache();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit fcca971

Please sign in to comment.