Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(dav): improve readability of PropFindPlugin
- Minor docblock imporvements
- Extract mount path calculation to dedicated method

Signed-off-by: Josh <[email protected]>
  • Loading branch information
joshtrichards committed Dec 24, 2025
commit 9ac4b856d06e100940f0674275a234dc3674261b
44 changes: 31 additions & 13 deletions lib/DAV/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;

/**
* SabreDAV plugin that adds group folder metadata to PROPFIND responses.
*
* Adds the mount point and group folder ID as custom WebDAV properties for group folder nodes.
*/
class PropFindPlugin extends ServerPlugin {
private ?Folder $userFolder = null;

public const MOUNT_POINT_PROPERTYNAME = '{http://nextcloud.org/ns}mount-point';
public const GROUP_FOLDER_ID_PROPERTYNAME = '{http://nextcloud.org/ns}group-folder-id';

public function __construct(IRootFolder $rootFolder, IUserSession $userSession) {
public function __construct(
IRootFolder $rootFolder,
IUserSession $userSession
) {
$user = $userSession->getUser();
if ($user === null) {
return;
Expand All @@ -41,20 +49,30 @@ public function initialize(Server $server): void {
}

public function propFind(PropFind $propFind, INode $node): void {
if ($this->userFolder === null) {
if (!($node instanceof GroupFolderNode) || $this->userFolder === null) {
return;
}

if ($node instanceof GroupFolderNode) {
$propFind->handle(
self::MOUNT_POINT_PROPERTYNAME,
/** @psalm-suppress PossiblyNullReference Null already checked above */
fn () => $this->userFolder->getRelativePath($node->getFileInfo()->getMountPoint()->getMountPoint())
);
$propFind->handle(
self::GROUP_FOLDER_ID_PROPERTYNAME,
fn (): int => $node->getFolderId()
);
}
$propFind->handle(
self::MOUNT_POINT_PROPERTYNAME,
fn() => $this->getRelativeMountPointPath($node)
);
$propFind->handle(
self::GROUP_FOLDER_ID_PROPERTYNAME,
fn (): int => $node->getFolderId()
);
}

/**
* Compute the path of the mount point relative to the root of the current user's folder.
*
* TODO: This may be a candidate for a utility function in GF or API addition in core.
*/
private function getRelativeMountPointPath(GroupFolderNode $node): ?string {
// TODO: Seems there could be some more defensive null/error handling here (perhaps throwing a 404/not found + logging)
$fileInfo = $node->getFileInfo();
$mount = $fileInfo->getMountPoint();
$mountPointPath = $mount->getMountPoint();
return $this->userFolder->getRelativePath($mountPointPath);
}
}