Skip to content

Commit 577e6aa

Browse files
committed
feat(dav): Allow UploadHome to handle public shares
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 25f9984 commit 577e6aa

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

apps/dav/lib/RootCollection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public function __construct() {
160160
Server::get(CleanupService::class),
161161
$rootFolder,
162162
$userSession,
163+
$shareManager,
163164
);
164165
$uploadCollection->disableListing = $disableListing;
165166

apps/dav/lib/Upload/RootCollection.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use OCP\Files\IRootFolder;
1313
use OCP\IUserSession;
14+
use OCP\Share\IManager;
1415
use Sabre\DAVACL\AbstractPrincipalCollection;
1516
use Sabre\DAVACL\PrincipalBackend;
1617

@@ -22,6 +23,7 @@ public function __construct(
2223
private CleanupService $cleanupService,
2324
private IRootFolder $rootFolder,
2425
private IUserSession $userSession,
26+
private IManager $shareManager,
2527
) {
2628
parent::__construct($principalBackend, $principalPrefix);
2729
}
@@ -30,7 +32,13 @@ public function __construct(
3032
* @inheritdoc
3133
*/
3234
public function getChildForPrincipal(array $principalInfo): UploadHome {
33-
return new UploadHome($principalInfo, $this->cleanupService, $this->rootFolder, $this->userSession);
35+
return new UploadHome(
36+
$principalInfo,
37+
$this->cleanupService,
38+
$this->rootFolder,
39+
$this->userSession,
40+
$this->shareManager,
41+
);
3442
}
3543

3644
/**

apps/dav/lib/Upload/UploadHome.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ public function __construct(
2525
private readonly CleanupService $cleanupService,
2626
private readonly IRootFolder $rootFolder,
2727
private readonly IUserSession $userSession,
28+
private readonly \OCP\Share\IManager $shareManager,
2829
) {
29-
$user = $this->userSession->getUser();
30-
if (!$user) {
31-
throw new Forbidden('Not logged in');
32-
}
30+
[$prefix, $name] = \Sabre\Uri\split($principalInfo['uri']);
31+
if ($prefix === 'principals/shares') {
32+
$this->uid = $this->shareManager->getShareByToken($name)->getShareOwner();
33+
} else {
34+
$user = $this->userSession->getUser();
35+
if (!$user) {
36+
throw new Forbidden('Not logged in');
37+
}
3338

34-
$this->uid = $user->getUID();
39+
$this->uid = $user->getUID();
40+
}
3541
}
3642

3743
public function createFile($name, $data = null) {

0 commit comments

Comments
 (0)