mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-12-06 11:22:41 +01:00
Added organization folder update permissions DAV prop, improved PropFindPlugin performance
This commit is contained in:
parent
789a05c4c1
commit
e999d42d33
2 changed files with 60 additions and 9 deletions
|
@ -41,7 +41,7 @@ class ResourceController extends BaseController {
|
|||
}
|
||||
|
||||
if($this->shouldInclude(self::SUBRESOURCES_INCLUDE, $includes)) {
|
||||
$result["subresources"] = $this->getSubResources($resource->getId());
|
||||
$result["subResources"] = $this->getSubResources($resource->getId());
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
|
@ -13,16 +13,21 @@ use OCA\DAV\Connector\Sabre\Node;
|
|||
use OCA\GroupFolders\Folder\FolderManager;
|
||||
use OCA\GroupFolders\Mount\GroupMountPoint;
|
||||
|
||||
use OCA\OrganizationFolders\Db\Resource;
|
||||
use OCA\OrganizationFolders\Model\OrganizationFolder;
|
||||
use OCA\OrganizationFolders\Service\OrganizationFolderService;
|
||||
use OCA\OrganizationFolders\Service\ResourceService;
|
||||
use OCA\OrganizationFolders\Security\AuthorizationService;
|
||||
|
||||
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 const ORGANIZATION_FOLDER_RESOURCE_MANAGER_PERMISSIONS_PROPERTYNAME = '{http://verdigado.com/ns}organization-folder-resource-user-has-manager-permissions';
|
||||
public const ORGANIZATION_FOLDER_UPDATE_PERMISSIONS_PROPERTYNAME = '{http://verdigado.com/ns}organization-folder-user-has-update-permissions';
|
||||
public const ORGANIZATION_FOLDER_RESOURCE_UPDATE_PERMISSIONS_PROPERTYNAME = '{http://verdigado.com/ns}organization-folder-resource-user-has-update-permissions';
|
||||
|
||||
public function __construct(
|
||||
private FolderManager $folderManager,
|
||||
private OrganizationFolderService $organizationFolderService,
|
||||
private ResourceService $resourceService,
|
||||
private AuthorizationService $authorizationService,
|
||||
) {
|
||||
|
@ -44,26 +49,72 @@ class PropFindPlugin extends ServerPlugin {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var ?OrganizationFolder
|
||||
*/
|
||||
$organizationFolder = null;
|
||||
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_ID_PROPERTYNAME, function () use ($fileInfo): int {
|
||||
return $this->folderManager->getFolderByPath($fileInfo->getPath());
|
||||
});
|
||||
/**
|
||||
* @var ?Resource
|
||||
*/
|
||||
$resource = null;
|
||||
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_RESOURCE_ID_PROPERTYNAME, function () use ($node): ?int {
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_ID_PROPERTYNAME, function () use ($fileInfo, $organizationFolder): ?int {
|
||||
try {
|
||||
return $this->resourceService->findByFileId($node->getId())->getId();
|
||||
if(!isset($organizationFolder)) {
|
||||
$organizationFolder = $this->getOrganizationFolderFromPath($fileInfo->getPath());
|
||||
}
|
||||
|
||||
return $organizationFolder->getId();
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_RESOURCE_MANAGER_PERMISSIONS_PROPERTYNAME, function () use ($node) {
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_UPDATE_PERMISSIONS_PROPERTYNAME, function () use ($fileInfo, $organizationFolder): ?string {
|
||||
try {
|
||||
$resource = $this->resourceService->findByFileId($node->getId());
|
||||
if(!isset($organizationFolder)) {
|
||||
$organizationFolder = $this->getOrganizationFolderFromPath($fileInfo->getPath());
|
||||
}
|
||||
|
||||
return $this->authorizationService->isGranted(["UPDATE"], $organizationFolder) ? 'true' : 'false';
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_RESOURCE_ID_PROPERTYNAME, function () use ($node, $resource): ?int {
|
||||
try {
|
||||
if(!isset($resource)) {
|
||||
$resource = $this->resourceService->findByFileId($node->getId());
|
||||
}
|
||||
|
||||
return $resource->getId();
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
$propFind->handle(self::ORGANIZATION_FOLDER_RESOURCE_UPDATE_PERMISSIONS_PROPERTYNAME, function () use ($node, $resource) {
|
||||
try {
|
||||
if(!isset($resource)) {
|
||||
$resource = $this->resourceService->findByFileId($node->getId());
|
||||
}
|
||||
|
||||
return $this->authorizationService->isGranted(["UPDATE"], $resource) ? 'true' : 'false';
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function getOrganizationFolderFromPath($path): ?OrganizationFolder {
|
||||
$organizationFolderId = $this->folderManager->getFolderByPath($path);
|
||||
|
||||
if(isset($organizationFolderId)) {
|
||||
return $this->organizationFolderService->find($organizationFolderId);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue