From 9c408d55f647d62f8c1bbe957cc88b4c30f01c4d 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 --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Files/Storage/DAV.php | 34 +++++++++++++++- .../Events/BeforeRemotePropfindEvent.php | 39 +++++++++++++++++++ 4 files changed, 73 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 dcb05293b0d9a..1e10b83e184df 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -440,6 +440,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 34e3bcced48c7..762cecd553f6d 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -481,6 +481,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..9739e9a897e88 --- /dev/null +++ b/lib/public/Files/Events/BeforeRemotePropfindEvent.php @@ -0,0 +1,39 @@ + + * @since 33.0.0 + */ + public function getProperties(): array { + return $this->properties; + } + + /** + * @param array $properties + * @since 33.0.0 + */ + public function addProperties(array $properties): void { + $this->properties = [...$this->properties, ...$properties]; + } +}