mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-12-06 11:22:41 +01:00
Added dav plugin to be able to query organizationId and resourceId of filesystem node from frontend
This commit is contained in:
parent
dc10742476
commit
f7b3b2f255
5 changed files with 116 additions and 2 deletions
56
lib/Dav/PropFindPlugin.php
Normal file
56
lib/Dav/PropFindPlugin.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\OrganizationFolders\Dav;
|
||||
|
||||
use Sabre\DAV\Server;
|
||||
use Sabre\DAV\ServerPlugin;
|
||||
use Sabre\DAV\INode;
|
||||
use Sabre\DAV\PropFind;
|
||||
|
||||
use OCA\DAV\Connector\Sabre\Node;
|
||||
use OCA\GroupFolders\Folder\FolderManager;
|
||||
use OCA\GroupFolders\Mount\GroupMountPoint;
|
||||
|
||||
use OCA\OrganizationFolders\Service\ResourceService;
|
||||
|
||||
class PropFindPlugin extends ServerPlugin {
|
||||
public const ORGANIZATION_FOLDER_ID_PROPERTYNAME = '{http://verdigado.com/ns}organization-folder-id';
|
||||
public const ORGANIZATION_FOLDER_RESOURCE_ID_PROPERTYNAME = '{http://verdigado.com/ns}organization-folder-resource-id';
|
||||
|
||||
public function __construct(
|
||||
private FolderManager $folderManager,
|
||||
private ResourceService $resourceService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function initialize(Server $server): void {
|
||||
$server->on('propFind', $this->propFind(...));
|
||||
}
|
||||
|
||||
public function propFind(PropFind $propFind, INode $node): void {
|
||||
if (!$node instanceof Node) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fileInfo = $node->getFileInfo();
|
||||
$mount = $fileInfo->getMountPoint();
|
||||
|
||||
if (!$mount instanceof GroupMountPoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_ID_PROPERTYNAME, function () use ($fileInfo): int {
|
||||
return $this->folderManager->getFolderByPath($fileInfo->getPath());
|
||||
});
|
||||
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_RESOURCE_ID_PROPERTYNAME, function () use ($node): ?int {
|
||||
try {
|
||||
return $this->resourceService->findByFileId($node->getId())->getId();
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue