diff options
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/RootCollection.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php | 28 | ||||
-rw-r--r-- | apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php | 26 |
3 files changed, 37 insertions, 19 deletions
diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index fd05ec2626f..f83b0495e1c 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -72,7 +72,7 @@ class RootCollection extends SimpleCollection { \OC::$server->getSystemTagObjectMapper(), \OC::$server->getUserSession(), \OC::$server->getGroupManager(), - \OC::$server->getRootFolder() + \OC::$server->getEventDispatcher() ); $commentsCollection = new Comments\RootCollection( \OC::$server->getCommentsManager(), diff --git a/apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php b/apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php index ae4b9d51a1b..f9ec3183f82 100644 --- a/apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php +++ b/apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php @@ -31,7 +31,6 @@ use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\IUserSession; use OCP\IGroupManager; -use OCP\Files\IRootFolder; /** * Collection containing object ids by object type @@ -64,9 +63,9 @@ class SystemTagsObjectTypeCollection implements ICollection { private $userSession; /** - * @var IRootFolder + * @var \Closure **/ - protected $fileRoot; + protected $childExistsFunction; /** * Constructor @@ -76,7 +75,7 @@ class SystemTagsObjectTypeCollection implements ICollection { * @param ISystemTagObjectMapper $tagMapper * @param IUserSession $userSession * @param IGroupManager $groupManager - * @param IRootFolder $fileRoot + * @param \Closure $childExistsFunction */ public function __construct( $objectType, @@ -84,19 +83,20 @@ class SystemTagsObjectTypeCollection implements ICollection { ISystemTagObjectMapper $tagMapper, IUserSession $userSession, IGroupManager $groupManager, - IRootFolder $fileRoot + \Closure $childExistsFunction ) { $this->tagManager = $tagManager; $this->tagMapper = $tagMapper; $this->objectType = $objectType; $this->userSession = $userSession; $this->groupManager = $groupManager; - $this->fileRoot = $fileRoot; + $this->childExistsFunction = $childExistsFunction; } /** * @param string $name * @param resource|string $data Initial payload + * @return null|string * @throws Forbidden */ function createFile($name, $data = null) { @@ -105,6 +105,7 @@ class SystemTagsObjectTypeCollection implements ICollection { /** * @param string $name + * @throws Forbidden */ function createDirectory($name) { throw new Forbidden('Permission denied to create collections'); @@ -112,6 +113,8 @@ class SystemTagsObjectTypeCollection implements ICollection { /** * @param string $objectId + * @return SystemTagsObjectMappingCollection + * @throws NotFound */ function getChild($objectId) { // make sure the object exists and is reachable @@ -133,17 +136,13 @@ class SystemTagsObjectTypeCollection implements ICollection { } /** + * Checks if a child-node with the specified name exists + * * @param string $name + * @return bool */ function childExists($name) { - // TODO: make this more abstract - if ($this->objectType === 'files') { - // make sure the object is reachable for the current user - $userId = $this->userSession->getUser()->getUID(); - $nodes = $this->fileRoot->getUserFolder($userId)->getById(intval($name)); - return !empty($nodes); - } - return true; + return call_user_func($this->childExistsFunction, $name); } function delete() { @@ -156,6 +155,7 @@ class SystemTagsObjectTypeCollection implements ICollection { /** * @param string $name + * @throws Forbidden */ function setName($name) { throw new Forbidden('Permission denied to rename this collection'); diff --git a/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php b/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php index 19db39d3f3a..7c4c613dc47 100644 --- a/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php +++ b/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php @@ -25,11 +25,12 @@ namespace OCA\DAV\SystemTag; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; +use OCP\SystemTag\SystemTagsEntityEvent; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\SimpleCollection; use OCP\IUserSession; use OCP\IGroupManager; -use OCP\Files\IRootFolder; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class SystemTagsRelationsCollection extends SimpleCollection { @@ -40,14 +41,14 @@ class SystemTagsRelationsCollection extends SimpleCollection { * @param ISystemTagObjectMapper $tagMapper * @param IUserSession $userSession * @param IGroupManager $groupManager - * @param IRootFolder $fileRoot + * @param EventDispatcherInterface $dispatcher */ public function __construct( ISystemTagManager $tagManager, ISystemTagObjectMapper $tagMapper, IUserSession $userSession, IGroupManager $groupManager, - IRootFolder $fileRoot + EventDispatcherInterface $dispatcher ) { $children = [ new SystemTagsObjectTypeCollection( @@ -56,10 +57,27 @@ class SystemTagsRelationsCollection extends SimpleCollection { $tagMapper, $userSession, $groupManager, - $fileRoot + function($name) { + $nodes = \OC::$server->getUserFolder()->getById(intval($name)); + return !empty($nodes); + } ), ]; + $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); + $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); + + foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { + $children[] = new SystemTagsObjectTypeCollection( + $entity, + $tagManager, + $tagMapper, + $userSession, + $groupManager, + $entityExistsFunction + ); + } + parent::__construct('root', $children); } |