Skip to content

Commit 67558a9

Browse files
committed
feat(dav): allow extending propfind properties via event
Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com> Update lib/public/Files/Events/BeforePropfindEvent.php Co-authored-by: Julius Knorr <jus@bitgrid.net> Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com> Update lib/public/Files/Events/BeforePropfindEvent.php Co-authored-by: Julius Knorr <jus@bitgrid.net> Signed-off-by: Benjamin Früh <134610227+benjaminfrueh@users.noreply.github.com> refactor: rename BeforePropfindEvent to BeforeRemotePropfindEvent Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com> chore: update composer autoloader for new event class Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com>
1 parent ebfdbf8 commit 67558a9

4 files changed

Lines changed: 73 additions & 2 deletions

File tree

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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
* @since 33.0.0
16+
*/
17+
class BeforeRemotePropfindEvent extends Event {
18+
public function __construct(
19+
private array $properties
20+
) {
21+
parent::__construct();
22+
}
23+
24+
/**
25+
* @return array<string>
26+
* @since 33.0.0
27+
*/
28+
public function getProperties(): array {
29+
return $this->properties;
30+
}
31+
32+
/**
33+
* @param array<string> $properties
34+
* @since 33.0.0
35+
*/
36+
public function addProperties(array $properties): void {
37+
$this->properties = [...$this->properties, ...$properties];
38+
}
39+
}

0 commit comments

Comments
 (0)