Skip to content

Commit 3f1b912

Browse files
authored
Merge pull request #58093 from nextcloud/backport/57914/stable33
[stable33] feat(dav): allow extending propfind properties via event
2 parents 19661b9 + b75a1bc commit 3f1b912

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@
440440
'OCP\\Files\\Events\\BeforeFileScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileScannedEvent.php',
441441
'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php',
442442
'OCP\\Files\\Events\\BeforeFolderScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFolderScannedEvent.php',
443+
'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => $baseDir . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php',
443444
'OCP\\Files\\Events\\BeforeZipCreatedEvent' => $baseDir . '/lib/public/Files/Events/BeforeZipCreatedEvent.php',
444445
'OCP\\Files\\Events\\FileCacheUpdated' => $baseDir . '/lib/public/Files/Events/FileCacheUpdated.php',
445446
'OCP\\Files\\Events\\FileScannedEvent' => $baseDir . '/lib/public/Files/Events/FileScannedEvent.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
481481
'OCP\\Files\\Events\\BeforeFileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileScannedEvent.php',
482482
'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php',
483483
'OCP\\Files\\Events\\BeforeFolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFolderScannedEvent.php',
484+
'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php',
484485
'OCP\\Files\\Events\\BeforeZipCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeZipCreatedEvent.php',
485486
'OCP\\Files\\Events\\FileCacheUpdated' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileCacheUpdated.php',
486487
'OCP\\Files\\Events\\FileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileScannedEvent.php',

lib/private/Files/Storage/DAV.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use OCP\AppFramework\Http;
1616
use OCP\Constants;
1717
use OCP\Diagnostics\IEventLogger;
18+
use OCP\EventDispatcher\IEventDispatcher;
19+
use OCP\Files\Events\BeforeRemotePropfindEvent;
1820
use OCP\Files\FileInfo;
1921
use OCP\Files\ForbiddenException;
2022
use OCP\Files\IMimeTypeDetector;
@@ -232,6 +234,34 @@ public function opendir(string $path) {
232234
return false;
233235
}
234236

237+
/**
238+
* @return array<string>
239+
*/
240+
protected function getPropfindProperties(): array {
241+
$event = new BeforeRemotePropfindEvent(self::PROPFIND_PROPS);
242+
Server::get(IEventDispatcher::class)->dispatchTyped($event);
243+
return $event->getProperties();
244+
}
245+
246+
/**
247+
* Get property value from cached PROPFIND response.
248+
* For accessing app-specific properties not included in getMetaData().
249+
*
250+
* @param string $path
251+
* @param string $propertyName
252+
* @return mixed
253+
*/
254+
public function getPropfindPropertyValue(string $path, string $propertyName): mixed {
255+
$path = $this->cleanPath($path);
256+
$propfindResponse = $this->statCache->get($path);
257+
258+
if (!is_array($propfindResponse)) {
259+
return null;
260+
}
261+
262+
return $propfindResponse[$propertyName] ?? null;
263+
}
264+
235265
/**
236266
* Propfind call with cache handling.
237267
*
@@ -254,7 +284,7 @@ protected function propfind(string $path): array|false {
254284
try {
255285
$response = $this->client->propFind(
256286
$this->encodePath($path),
257-
self::PROPFIND_PROPS
287+
$this->getPropfindProperties()
258288
);
259289
$this->statCache->set($path, $response);
260290
} catch (ClientHttpException $e) {
@@ -818,7 +848,7 @@ public function getDirectoryContent(string $directory): \Traversable {
818848
try {
819849
$responses = $this->client->propFind(
820850
$this->encodePath($directory),
821-
self::PROPFIND_PROPS,
851+
$this->getPropfindProperties(),
822852
1
823853
);
824854

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCP\Files\Events;
11+
12+
use OCP\EventDispatcher\Event;
13+
14+
/**
15+
* This event is fired before a PROPFIND request is sent to remote WebDAV storage
16+
* Used to extend the list of properties to request additional data from the remote server
17+
*
18+
* @since 33.0.0
19+
*/
20+
class BeforeRemotePropfindEvent extends Event {
21+
public function __construct(
22+
private array $properties,
23+
) {
24+
parent::__construct();
25+
}
26+
27+
/**
28+
* @return array<string>
29+
* @since 33.0.0
30+
*/
31+
public function getProperties(): array {
32+
return $this->properties;
33+
}
34+
35+
/**
36+
* @param array<string> $properties
37+
* @since 33.0.0
38+
*/
39+
public function addProperties(array $properties): void {
40+
array_push($this->properties, ...$properties);
41+
}
42+
}

0 commit comments

Comments
 (0)