2016-01-11 20:09:00 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-01-11 20:09:00 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-01-11 20:09:00 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Comments;
|
|
|
|
|
|
|
|
use OCP\Comments\ICommentsManager;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUserManager;
|
2016-01-30 01:23:16 +03:00
|
|
|
use OCP\IUserSession;
|
2016-01-11 20:09:00 +03:00
|
|
|
use Sabre\DAV\Exception\MethodNotAllowed;
|
2016-01-26 14:47:33 +03:00
|
|
|
use Sabre\DAV\Exception\NotFound;
|
2016-01-11 20:09:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class EntityTypeCollection
|
|
|
|
*
|
|
|
|
* This is collection on the type of things a user can leave comments on, for
|
|
|
|
* example: 'files'.
|
|
|
|
*
|
|
|
|
* Its children are instances of EntityCollection (representing a specific
|
|
|
|
* object, for example the file by id).
|
|
|
|
*
|
|
|
|
* @package OCA\DAV\Comments
|
|
|
|
*/
|
|
|
|
class EntityTypeCollection extends RootCollection {
|
|
|
|
|
|
|
|
/** @var ILogger */
|
|
|
|
protected $logger;
|
|
|
|
|
2016-02-24 15:23:44 +03:00
|
|
|
/** @var IUserManager */
|
|
|
|
protected $userManager;
|
|
|
|
|
|
|
|
/** @var \Closure */
|
|
|
|
protected $childExistsFunction;
|
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param ICommentsManager $commentsManager
|
|
|
|
* @param IUserManager $userManager
|
2016-01-30 01:23:16 +03:00
|
|
|
* @param IUserSession $userSession
|
2016-01-11 20:09:00 +03:00
|
|
|
* @param ILogger $logger
|
2016-02-24 15:23:44 +03:00
|
|
|
* @param \Closure $childExistsFunction
|
2016-01-11 20:09:00 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$name,
|
|
|
|
ICommentsManager $commentsManager,
|
|
|
|
IUserManager $userManager,
|
2016-01-30 01:23:16 +03:00
|
|
|
IUserSession $userSession,
|
2016-02-24 15:23:44 +03:00
|
|
|
ILogger $logger,
|
|
|
|
\Closure $childExistsFunction
|
2016-01-11 20:09:00 +03:00
|
|
|
) {
|
|
|
|
$name = trim($name);
|
2020-04-10 15:19:56 +03:00
|
|
|
if (empty($name) || !is_string($name)) {
|
2016-01-11 20:09:00 +03:00
|
|
|
throw new \InvalidArgumentException('"name" parameter must be non-empty string');
|
|
|
|
}
|
|
|
|
$this->name = $name;
|
|
|
|
$this->commentsManager = $commentsManager;
|
|
|
|
$this->logger = $logger;
|
|
|
|
$this->userManager = $userManager;
|
2016-01-30 01:23:16 +03:00
|
|
|
$this->userSession = $userSession;
|
2016-02-24 15:23:44 +03:00
|
|
|
$this->childExistsFunction = $childExistsFunction;
|
2016-01-11 20:09:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a specific child node, referenced by its name
|
|
|
|
*
|
|
|
|
* This method must throw Sabre\DAV\Exception\NotFound if the node does not
|
|
|
|
* exist.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return \Sabre\DAV\INode
|
2016-01-26 14:47:33 +03:00
|
|
|
* @throws NotFound
|
2016-01-11 20:09:00 +03:00
|
|
|
*/
|
2020-04-10 17:51:06 +03:00
|
|
|
public function getChild($name) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if (!$this->childExists($name)) {
|
2016-01-26 14:47:33 +03:00
|
|
|
throw new NotFound('Entity does not exist or is not available');
|
2016-01-11 20:09:00 +03:00
|
|
|
}
|
|
|
|
return new EntityCollection(
|
|
|
|
$name,
|
|
|
|
$this->name,
|
|
|
|
$this->commentsManager,
|
|
|
|
$this->userManager,
|
2016-01-30 01:23:16 +03:00
|
|
|
$this->userSession,
|
2016-01-11 20:09:00 +03:00
|
|
|
$this->logger
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array with all the child nodes
|
|
|
|
*
|
|
|
|
* @return \Sabre\DAV\INode[]
|
|
|
|
* @throws MethodNotAllowed
|
|
|
|
*/
|
2020-04-10 17:51:06 +03:00
|
|
|
public function getChildren() {
|
2016-01-11 20:09:00 +03:00
|
|
|
throw new MethodNotAllowed('No permission to list folder contents');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a child-node with the specified name exists
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return bool
|
|
|
|
*/
|
2020-04-10 17:51:06 +03:00
|
|
|
public function childExists($name) {
|
2016-02-24 15:23:44 +03:00
|
|
|
return call_user_func($this->childExistsFunction, $name);
|
2016-01-11 20:09:00 +03:00
|
|
|
}
|
|
|
|
}
|