Skip to content

Commit 24d2811

Browse files
committed
fixup! refactor(dav): Replace baseuri manipulation with RootCollection for public shares
1 parent bb6fc88 commit 24d2811

5 files changed

Lines changed: 32 additions & 13 deletions

File tree

apps/dav/lib/Connector/Sabre/Directory.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
1414
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
1515
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
16+
use OCA\DAV\Storage\PublicShareWrapper;
1617
use OCP\App\IAppManager;
18+
use OCP\Constants;
1719
use OCP\Files\FileInfo;
1820
use OCP\Files\Folder;
1921
use OCP\Files\ForbiddenException;
@@ -172,7 +174,19 @@ public function createDirectory($name) {
172174
* @throws \Sabre\DAV\Exception\ServiceUnavailable
173175
*/
174176
public function getChild($name, $info = null, ?IRequest $request = null, ?IL10N $l10n = null) {
175-
if (!$this->info->isReadable()) {
177+
$storage = $this->info->getStorage();
178+
$allowDirectory = false;
179+
if ($storage instanceof PublicShareWrapper) {
180+
$share = $storage->getShare();
181+
$allowDirectory =
182+
// Only allow directories for file drops
183+
($share->getPermissions() & Constants::PERMISSION_READ) !== Constants::PERMISSION_READ &&
184+
// And only allow it for directories which are a direct child of of the share root
185+
$this->info->getId() === $share->getNodeId();
186+
}
187+
188+
// For file drop we need to be allowed to read the directory with the nickname
189+
if (!$allowDirectory && !$this->info->isReadable()) {
176190
// avoid detecting files through this way
177191
throw new NotFound();
178192
}
@@ -198,6 +212,11 @@ public function getChild($name, $info = null, ?IRequest $request = null, ?IL10N
198212
if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
199213
$node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager);
200214
} else {
215+
// In case reading a directory was allowed but it turns out the node was a not a directory, reject it now.
216+
if (!$this->info->isReadable()) {
217+
throw new NotFound();
218+
}
219+
201220
$node = new File($this->fileView, $info, $this->shareManager, $request, $l10n);
202221
}
203222
if ($this->tree) {

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,15 @@ private function getMetadataFileAccessRight(Node $node, string $userId): int {
688688
*/
689689
public function sendFileIdHeader($filePath, ?\Sabre\DAV\INode $node = null) {
690690
// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
691-
if (!$this->server->tree->nodeExists($filePath)) {
692-
return;
693-
}
694-
$node = $this->server->tree->getNodeForPath($filePath);
695-
if ($node instanceof Node) {
696-
$fileId = $node->getFileId();
697-
if (!is_null($fileId)) {
698-
$this->server->httpResponse->setHeader('OC-FileId', $fileId);
691+
try {
692+
$node = $this->server->tree->getNodeForPath($filePath);
693+
if ($node instanceof Node) {
694+
$fileId = $node->getFileId();
695+
if (!is_null($fileId)) {
696+
$this->server->httpResponse->setHeader('OC-FileId', $fileId);
697+
}
699698
}
699+
} catch (NotFound) {
700700
}
701701
}
702702
}

apps/dav/lib/Connector/Sabre/ServerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public function createServer(
149149
\OC::$server->getL10NFactory(),
150150
);
151151

152+
// Mount the the share collection at /public.php/dav/shares/<share token>
152153
$rootCollection->addChild(new \OCA\DAV\Files\Sharing\RootCollection(
153-
$view,
154154
$root,
155155
$userPrincipalBackend,
156156
'principals/shares',

apps/dav/lib/Files/Sharing/FilesDropPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function beforeMethod(RequestInterface $request, ResponseInterface $respo
8585
}
8686

8787
$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
88-
$url = $request->getBaseUrl() . $newName;
88+
$url = $request->getBaseUrl() . 'files/' . $this->share->getToken() . $newName;
8989
$request->setUrl($url);
9090
}
9191

apps/dav/lib/Files/Sharing/RootCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-License-Identifier: AGPL-3.0-or-later
68
*/
79

810
namespace OCA\DAV\Files\Sharing;
911

10-
use OC\Files\View;
1112
use Sabre\DAV\INode;
1213
use Sabre\DAVACL\AbstractPrincipalCollection;
1314
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
1415

1516
class RootCollection extends AbstractPrincipalCollection {
1617
public function __construct(
17-
private View $view,
1818
private INode $root,
1919
BackendInterface $principalBackend,
2020
string $principalPrefix = 'principals',

0 commit comments

Comments
 (0)