From 91e1b300bfcf01d794538e92cbb5f2a22e798cac Mon Sep 17 00:00:00 2001 From: Benjamin Frueh Date: Thu, 29 Jan 2026 16:41:18 +0100 Subject: [PATCH] feat(dav): allow extending propfind properties via event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Benjamin Frueh Update lib/public/Files/Events/BeforePropfindEvent.php Co-authored-by: Julius Knorr Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com> Update lib/public/Files/Events/BeforePropfindEvent.php Co-authored-by: Julius Knorr Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com> refactor: rename BeforePropfindEvent to BeforeRemotePropfindEvent Signed-off-by: Benjamin Frueh chore: update composer autoloader for new event class Signed-off-by: Benjamin Frueh Update lib/public/Files/Events/BeforeRemotePropfindEvent.php Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com> --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Files/Storage/DAV.php | 34 ++++++++++++++- .../Events/BeforeRemotePropfindEvent.php | 42 +++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 lib/public/Files/Events/BeforeRemotePropfindEvent.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index b7209606baf32..ad52fef210159 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -430,6 +430,7 @@ 'OCP\\Files\\Events\\BeforeFileScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileScannedEvent.php', 'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => $baseDir . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php', 'OCP\\Files\\Events\\BeforeFolderScannedEvent' => $baseDir . '/lib/public/Files/Events/BeforeFolderScannedEvent.php', + 'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => $baseDir . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php', 'OCP\\Files\\Events\\BeforeZipCreatedEvent' => $baseDir . '/lib/public/Files/Events/BeforeZipCreatedEvent.php', 'OCP\\Files\\Events\\FileCacheUpdated' => $baseDir . '/lib/public/Files/Events/FileCacheUpdated.php', 'OCP\\Files\\Events\\FileScannedEvent' => $baseDir . '/lib/public/Files/Events/FileScannedEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 7409cdf224d11..8162f4cbd25bc 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -471,6 +471,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Files\\Events\\BeforeFileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileScannedEvent.php', 'OCP\\Files\\Events\\BeforeFileSystemSetupEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFileSystemSetupEvent.php', 'OCP\\Files\\Events\\BeforeFolderScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeFolderScannedEvent.php', + 'OCP\\Files\\Events\\BeforeRemotePropfindEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeRemotePropfindEvent.php', 'OCP\\Files\\Events\\BeforeZipCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/BeforeZipCreatedEvent.php', 'OCP\\Files\\Events\\FileCacheUpdated' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileCacheUpdated.php', 'OCP\\Files\\Events\\FileScannedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/Events/FileScannedEvent.php', diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 2d166b5438da1..1721c6d25db5b 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -15,6 +15,8 @@ use OCP\AppFramework\Http; use OCP\Constants; use OCP\Diagnostics\IEventLogger; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\BeforeRemotePropfindEvent; use OCP\Files\FileInfo; use OCP\Files\ForbiddenException; use OCP\Files\IMimeTypeDetector; @@ -232,6 +234,34 @@ public function opendir(string $path) { return false; } + /** + * @return array + */ + protected function getPropfindProperties(): array { + $event = new BeforeRemotePropfindEvent(self::PROPFIND_PROPS); + Server::get(IEventDispatcher::class)->dispatchTyped($event); + return $event->getProperties(); + } + + /** + * Get property value from cached PROPFIND response. + * For accessing app-specific properties not included in getMetaData(). + * + * @param string $path + * @param string $propertyName + * @return mixed + */ + public function getPropfindPropertyValue(string $path, string $propertyName): mixed { + $path = $this->cleanPath($path); + $propfindResponse = $this->statCache->get($path); + + if (!is_array($propfindResponse)) { + return null; + } + + return $propfindResponse[$propertyName] ?? null; + } + /** * Propfind call with cache handling. * @@ -254,7 +284,7 @@ protected function propfind(string $path): array|false { try { $response = $this->client->propFind( $this->encodePath($path), - self::PROPFIND_PROPS + $this->getPropfindProperties() ); $this->statCache->set($path, $response); } catch (ClientHttpException $e) { @@ -818,7 +848,7 @@ public function getDirectoryContent(string $directory): \Traversable { try { $responses = $this->client->propFind( $this->encodePath($directory), - self::PROPFIND_PROPS, + $this->getPropfindProperties(), 1 ); diff --git a/lib/public/Files/Events/BeforeRemotePropfindEvent.php b/lib/public/Files/Events/BeforeRemotePropfindEvent.php new file mode 100644 index 0000000000000..959629addbd66 --- /dev/null +++ b/lib/public/Files/Events/BeforeRemotePropfindEvent.php @@ -0,0 +1,42 @@ + + * @since 32.0.6 + */ + public function getProperties(): array { + return $this->properties; + } + + /** + * @param array $properties + * @since 32.0.6 + */ + public function addProperties(array $properties): void { + array_push($this->properties, ...$properties); + } +}