Fix the SharesPlugin
Another attempt to fix all the typing and handling in the sharesplugin. In short we should probably have a lot more type hinting in several places. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
2afa1c5739
commit
c40228a65a
|
@ -29,6 +29,9 @@
|
||||||
|
|
||||||
namespace OCA\DAV\Connector\Sabre;
|
namespace OCA\DAV\Connector\Sabre;
|
||||||
|
|
||||||
|
use OCA\DAV\Connector\Sabre\Node as DavNode;
|
||||||
|
use OCP\Files\Folder;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
use Sabre\DAV\PropFind;
|
use Sabre\DAV\PropFind;
|
||||||
|
@ -49,29 +52,22 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
*/
|
*/
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
/**
|
/** @var \OCP\Share\IManager */
|
||||||
* @var \OCP\Share\IManager
|
|
||||||
*/
|
|
||||||
private $shareManager;
|
private $shareManager;
|
||||||
|
|
||||||
/**
|
/** @var \Sabre\DAV\Tree */
|
||||||
* @var \Sabre\DAV\Tree
|
|
||||||
*/
|
|
||||||
private $tree;
|
private $tree;
|
||||||
|
|
||||||
/**
|
/** @var string */
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $userId;
|
private $userId;
|
||||||
|
|
||||||
/**
|
/** @var \OCP\Files\Folder */
|
||||||
* @var \OCP\Files\Folder
|
|
||||||
*/
|
|
||||||
private $userFolder;
|
private $userFolder;
|
||||||
|
|
||||||
/** @var IShare[] */
|
/** @var IShare[][] */
|
||||||
private $cachedShares = [];
|
private $cachedShares = [];
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
private $cachedFolders = [];
|
private $cachedFolders = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,6 +108,10 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
$this->server->on('propFind', [$this, 'handleGetProperties']);
|
$this->server->on('propFind', [$this, 'handleGetProperties']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \OCP\Files\Node $node
|
||||||
|
* @return IShare[]
|
||||||
|
*/
|
||||||
private function getShare(\OCP\Files\Node $node): array {
|
private function getShare(\OCP\Files\Node $node): array {
|
||||||
$result = [];
|
$result = [];
|
||||||
$requestedShareTypes = [
|
$requestedShareTypes = [
|
||||||
|
@ -139,7 +139,11 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSharesFolder(\OCP\Files\Folder $node): array {
|
/**
|
||||||
|
* @param Folder $node
|
||||||
|
* @return IShare[][]
|
||||||
|
*/
|
||||||
|
private function getSharesFolder(Folder $node): array {
|
||||||
return $this->shareManager->getSharesInFolder(
|
return $this->shareManager->getSharesInFolder(
|
||||||
$this->userId,
|
$this->userId,
|
||||||
$node,
|
$node,
|
||||||
|
@ -147,7 +151,11 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getShares(\Sabre\DAV\INode $sabreNode): array {
|
/**
|
||||||
|
* @param DavNode $sabreNode
|
||||||
|
* @return IShare[]
|
||||||
|
*/
|
||||||
|
private function getShares(DavNode $sabreNode): array {
|
||||||
if (isset($this->cachedShares[$sabreNode->getId()])) {
|
if (isset($this->cachedShares[$sabreNode->getId()])) {
|
||||||
$shares = $this->cachedShares[$sabreNode->getId()];
|
$shares = $this->cachedShares[$sabreNode->getId()];
|
||||||
} else {
|
} else {
|
||||||
|
@ -157,7 +165,11 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
}
|
}
|
||||||
// if we already cached the folder this file is in we know there are no shares for this file
|
// if we already cached the folder this file is in we know there are no shares for this file
|
||||||
if (array_search($parentPath, $this->cachedFolders) === false) {
|
if (array_search($parentPath, $this->cachedFolders) === false) {
|
||||||
$node = $this->userFolder->get($sabreNode->getPath());
|
try {
|
||||||
|
$node = $this->userFolder->get($sabreNode->getPath());
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
$shares = $this->getShare($node);
|
$shares = $this->getShare($node);
|
||||||
$this->cachedShares[$sabreNode->getId()] = $shares;
|
$this->cachedShares[$sabreNode->getId()] = $shares;
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,19 +190,29 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
|
||||||
PropFind $propFind,
|
PropFind $propFind,
|
||||||
\Sabre\DAV\INode $sabreNode
|
\Sabre\DAV\INode $sabreNode
|
||||||
) {
|
) {
|
||||||
if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
|
if (!($sabreNode instanceof DavNode)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// need prefetch ?
|
// need prefetch ?
|
||||||
if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
|
if ($sabreNode instanceof Directory
|
||||||
&& $propFind->getDepth() !== 0
|
&& $propFind->getDepth() !== 0
|
||||||
&& (
|
&& (
|
||||||
!is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) ||
|
!is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) ||
|
||||||
!is_null($propFind->getStatus(self::SHAREES_PROPERTYNAME))
|
!is_null($propFind->getStatus(self::SHAREES_PROPERTYNAME))
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
$folderNode = $this->userFolder->get($sabreNode->getPath());
|
try {
|
||||||
|
$folderNode = $this->userFolder->get($sabreNode->getPath());
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
// If the folder can't be properly found just return
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!($folderNode instanceof Folder)) {
|
||||||
|
// Safety check
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->cachedFolders[] = $sabreNode->getPath();
|
$this->cachedFolders[] = $sabreNode->getPath();
|
||||||
$childShares = $this->getSharesFolder($folderNode);
|
$childShares = $this->getSharesFolder($folderNode);
|
||||||
|
|
Loading…
Reference in New Issue