Added dav endpoints for system tags

This commit is contained in:
Vincent Petry 2015-11-27 12:54:31 +01:00
parent 2d1cc8aaeb
commit cc72c6a30d
10 changed files with 893 additions and 0 deletions

View File

@ -33,6 +33,13 @@ class RootCollection extends SimpleCollection {
$caldavBackend = new CalDavBackend($db); $caldavBackend = new CalDavBackend($db);
$calendarRoot = new CalendarRoot($principalBackend, $caldavBackend, 'principals/users'); $calendarRoot = new CalendarRoot($principalBackend, $caldavBackend, 'principals/users');
$calendarRoot->disableListing = $disableListing; $calendarRoot->disableListing = $disableListing;
$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
\OC::$server->getSystemTagManager()
);
$systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
\OC::$server->getSystemTagManager(),
\OC::$server->getSystemTagObjectMapper()
);
$usersCardDavBackend = new CardDavBackend($db, $principalBackend); $usersCardDavBackend = new CardDavBackend($db, $principalBackend);
$usersAddressBookRoot = new AddressBookRoot($principalBackend, $usersCardDavBackend, 'principals/users'); $usersAddressBookRoot = new AddressBookRoot($principalBackend, $usersCardDavBackend, 'principals/users');
@ -51,6 +58,8 @@ class RootCollection extends SimpleCollection {
new SimpleCollection('addressbooks', [ new SimpleCollection('addressbooks', [
$usersAddressBookRoot, $usersAddressBookRoot,
$systemAddressBookRoot]), $systemAddressBookRoot]),
$systemTagCollection,
$systemTagRelationsCollection,
]; ];
parent::__construct('root', $children); parent::__construct('root', $children);

View File

@ -60,6 +60,9 @@ class Server {
// addressbook plugins // addressbook plugins
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
// system tags plugins
$this->server->addPlugin(new \OCA\DAV\SystemTag\SystemTagPlugin(\OC::$server->getSystemTagManager()));
// Finder on OS X requires Class 2 WebDAV support (locking), since we do // Finder on OS X requires Class 2 WebDAV support (locking), since we do
// not provide locking we emulate it using a fake locking plugin. // not provide locking we emulate it using a fake locking plugin.
if($request->isUserAgent(['/WebDAVFS/'])) { if($request->isUserAgent(['/WebDAVFS/'])) {

View File

@ -0,0 +1,81 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\SystemTag;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\MethodNotAllowed;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\TagNotFoundException;
/**
* Mapping node for system tag to object id
*/
class SystemTagMappingNode extends SystemTagNode {
/**
* @var ISystemTagObjectMapper
*/
private $tagMapper;
/**
* @var string
*/
private $objectId;
/**
* @var string
*/
private $objectType;
/**
* Sets up the node, expects a full path name
*
* @param ISystemTag $tag system tag
*/
public function __construct(
ISystemTag $tag,
$objectId,
$objectType,
ISystemTagManager $tagManager,
ISystemTagObjectMapper $tagMapper
) {
$this->objectId = $objectId;
$this->objectType = $objectType;
$this->tagMapper = $tagMapper;
parent::__construct($tag, $tagManager);
}
/**
* Delete tag to object association
*/
public function delete() {
try {
$this->tagMapper->unassignTags($this->objectId, $this->objectType, $this->tag->getId());
} catch (TagNotFoundException $e) {
// can happen if concurrent deletion occurred
throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e);
}
}
}

View File

@ -0,0 +1,112 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\SystemTag;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\Conflict;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\TagNotFoundException;
class SystemTagNode implements \Sabre\DAV\INode {
/**
* @var ISystemTag
*/
protected $tag;
/**
* @var ISystemTagManager
*/
protected $tagManager;
/**
* Sets up the node, expects a full path name
*
* @param ISystemTag $tag system tag
*/
public function __construct(ISystemTag $tag, ISystemTagManager $tagManager) {
$this->tag = $tag;
$this->tagManager = $tagManager;
}
/**
* Returns the id of the tag
*
* @return string
*/
public function getName() {
return $this->tag->getId();
}
/**
* Returns the system tag represented by this node
*
* @return ISystemTag system tag
*/
public function getSystemTag() {
return $this->tag;
}
/**
* Renames the node
*
* @param string $name The new name
*
* @throws \Sabre\DAV\Exception\MethodNotAllowed
*/
public function setName($name) {
throw new MethodNotAllowed();
}
/**
* @param string $name new tag name
* @param bool $userVisible user visible
* @param bool $userAssignable user assignable
*/
public function update($name, $userVisible, $userAssignable) {
try {
$this->tagManager->updateTag($name, $userVisible, $userAssignable);
} catch (TagAlreadyExistsException $e) {
throw new Conflict('Tag with the properties "' . $name . '", ' . $userVisible, ', ' . $userAssignable . ' already exists');
}
}
/**
* Returns null, not supported
*
*/
public function getLastModified() {
return null;
}
public function delete() {
try {
$this->tagManager->deleteTags($this->tag->getId());
} catch (TagNotFoundException $e) {
// can happen if concurrent deletion occurred
throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e);
}
}
}

View File

@ -0,0 +1,241 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\SystemTag;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\UnsupportedMediaType;
use Sabre\DAV\Exception\Conflict;
use OCA\DAV\SystemTag\SystemTagNode;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\TagAlreadyExistsException;
class SystemTagPlugin extends \Sabre\DAV\ServerPlugin {
// namespace
const NS_OWNCLOUD = 'http://owncloud.org/ns';
const ID_PROPERTYNAME = '{http://owncloud.org/ns}id';
const DISPLAYNAME_PROPERTYNAME = '{http://owncloud.org/ns}display-name';
const USERVISIBLE_PROPERTYNAME = '{http://owncloud.org/ns}user-visible';
const USERASSIGNABLE_PROPERTYNAME = '{http://owncloud.org/ns}user-assignable';
/**
* @var \Sabre\DAV\Server $server
*/
private $server;
/**
* @var ISystemTagManager
*/
protected $tagManager;
/**
* System tags plugin
*
* @param ISystemTagManager $tagManager tag manager
*/
public function __construct(ISystemTagManager $tagManager) {
$this->tagManager = $tagManager;
}
/**
* This initializes the plugin.
*
* This function is called by \Sabre\DAV\Server, after
* addPlugin is called.
*
* This method should set up the required event subscriptions.
*
* @param \Sabre\DAV\Server $server
* @return void
*/
public function initialize(\Sabre\DAV\Server $server) {
$server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc';
$server->protectedProperties[] = self::ID_PROPERTYNAME;
$server->on('propFind', array($this, 'handleGetProperties'));
$server->on('propPatch', array($this, 'handleUpdateProperties'));
$server->on('method:POST', [$this, 'httpPost']);
$this->server = $server;
}
/**
* We intercept this to handle POST requests on calendars.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @return null|false
*/
function httpPost(RequestInterface $request, ResponseInterface $response) {
$path = $request->getPath();
// Making sure the node exists
try {
$node = $this->server->tree->getNodeForPath($path);
} catch (NotFound $e) {
return;
}
if ($node instanceof SystemTagsByIdCollection || $node instanceof SystemTagsObjectMappingCollection) {
$data = $request->getBodyAsString();
$tag = $this->createTag($data, $request->getHeader('Content-Type'));
if ($node instanceof SystemTagsObjectMappingCollection) {
// also add to collection
$node->createFile($tag->getId());
$url = $request->getBaseUrl() . 'systemtags/';
} else {
$url = $request->getUrl();
}
if ($url[strlen($url) - 1] !== '/') {
$url .= '/';
}
$response->setHeader('Location', $url . $tag->getId());
// created
$response->setStatus(201);
return false;
}
}
/**
* Creates a new tag
*
* @param string $data
* @param string $contentType content type of the data
*
* @return ISystemTag newly created system tag
*
* @throws UnsupportedMediaType if the content type is not supported
* @throws BadRequest if a field was missing
*/
private function createTag($data, $contentType = 'application/json') {
if ($contentType === 'application/json') {
$data = json_decode($data, true);
// TODO: application/x-www-form-urlencoded ?
} else {
throw new UnsupportedMediaType();
}
if (!isset($data['name'])) {
throw new BadRequest('Missing "name" attribute');
}
$tagName = $data['name'];
$userVisible = true;
$userAssignable = true;
if (isset($data['userVisible'])) {
$userVisible = (bool)$data['userVisible'];
}
if (isset($data['userAssignable'])) {
$userVisible = (bool)$data['userAssignable'];
}
try {
return $this->tagManager->createTag($tagName, $userVisible, $userAssignable);
} catch (TagAlreadyExistsException $e) {
throw new Conflict('Tag already exists');
}
}
/**
* Retrieves system tag properties
*
* @param PropFind $propFind
* @param \Sabre\DAV\INode $node
*/
public function handleGetProperties(
PropFind $propFind,
\Sabre\DAV\INode $node
) {
if (!($node instanceof SystemTagNode)) {
return;
}
$propFind->handle(self::ID_PROPERTYNAME, function() use ($node) {
return $node->getSystemTag()->getId();
});
$propFind->handle(self::DISPLAYNAME_PROPERTYNAME, function() use ($node) {
return $node->getSystemTag()->getName();
});
$propFind->handle(self::USERVISIBLE_PROPERTYNAME, function() use ($node) {
return (int)$node->getSystemTag()->isUserVisible();
});
$propFind->handle(self::USERASSIGNABLE_PROPERTYNAME, function() use ($node) {
return (int)$node->getSystemTag()->isUserAssignable();
});
}
/**
* Updates tag attributes
*
* @param string $path
* @param PropPatch $propPatch
*
* @return void
*/
public function handleUpdateProperties($path, PropPatch $propPatch) {
$propPatch->handle([
self::DISPLAYNAME_PROPERTYNAME,
self::USERVISIBLE_PROPERTYNAME,
self::USERASSIGNABLE_PROPERTYNAME,
], function($props) use ($path) {
$node = $this->tree->getNodeForPath($path);
if (!($node instanceof SystemTagNode)) {
return;
}
$tag = $node->getTag();
$name = $tag->getName();
$userVisible = $tag->getUserVisible();
$userAssignable = $tag->getUserAssignable();
if (isset($props[self::DISPLAYNAME_PROPERTYNAME])) {
$name = $props[self::DISPLAYNAME_PROPERTYNAME];
}
if (isset($props[self::USERVISIBLE_PROPERTYNAME])) {
$userVisible = (bool)$props[self::USERVISIBLE_PROPERTYNAME];
}
if (isset($props[self::USERASSIGNABLE_PROPERTYNAME])) {
$userAssignable = (bool)$props[self::USERASSIGNABLE_PROPERTYNAME];
}
$node->update($name, $userVisible, $userAssignable);
return true;
});
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\SystemTag;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\ICollection;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\TagNotFoundException;
use OC\SystemTag\SystemTag;
class SystemTagsByIdCollection implements ICollection {
/**
* @var ISystemTagManager
*/
private $tagManager;
/**
* SystemTagsByIdCollection constructor.
*
* @param ISystemTagManager $tagManager
*/
public function __construct($tagManager) {
$this->tagManager = $tagManager;
}
function createFile($name, $data = null) {
throw new Forbidden('Cannot create tags by id');
}
function createDirectory($name) {
throw new Forbidden('Permission denied to create collections');
}
function getChild($name) {
try {
$tags = $this->tagManager->getTagsById($name);
return $this->makeNode(current($tags));
} catch (\InvalidArgumentException $e) {
throw new BadRequest('Invalid tag id', 0, $e);
} catch (TagNotFoundException $e) {
throw new NotFound('Tag with id ' . $name . ' not found', 0, $e);
}
}
function getChildren() {
// TODO: set visibility filter based on principal/permissions ?
$tags = $this->tagManager->getAllTags(true);
return array_map(function($tag) {
return $this->makeNode($tag);
}, $tags);
}
function childExists($name) {
try {
$this->tagManager->getTagsById($name);
return true;
} catch (\InvalidArgumentException $e) {
throw new BadRequest('Invalid tag id', 0, $e);
} catch (TagNotFoundException $e) {
return false;
}
}
function delete() {
throw new Forbidden('Permission denied to delete this collection');
}
function getName() {
return 'systemtags';
}
function setName($name) {
throw new Forbidden('Permission denied to rename this collection');
}
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
function getLastModified() {
return null;
}
/**
* Create a sabre node for the given system tag
*
* @param ISystemTag $tag
*
* @return SystemTagNode
*/
private function makeNode(ISystemTag $tag) {
return new SystemTagNode($tag, $this->tagManager);
}
}

View File

@ -0,0 +1,160 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\SystemTag;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\ICollection;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\TagNotFoundException;
use OC\SystemTag\SystemTag;
/**
* Collection containing tags by object id
*/
class SystemTagsObjectMappingCollection implements ICollection {
/**
* @var string
*/
private $objectId;
/**
* @var string
*/
private $objectType;
/**
* @var ISystemTagManager
*/
private $tagManager;
/**
* @var ISystemTagObjectMapper
*/
private $tagMapper;
/**
* Constructor
*
* @param string $objectId object id
* @param string $objectType object type
* @param ISystemTagManager $tagManager
* @param ISystemTagObjectMapper $tagMapper
*/
public function __construct($objectId, $objectType, $tagManager, $tagMapper) {
$this->tagManager = $tagManager;
$this->tagMapper = $tagMapper;
$this->objectId = $objectId;
$this->objectType = $objectType;
}
function createFile($tagId, $data = null) {
try {
$this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId);
} catch (TagNotFoundException $e) {
throw new Forbidden('Tag with id ' . $tagId . ' does not exist, cannot assign');
}
}
function createDirectory($name) {
throw new Forbidden('Permission denied to create collections');
}
function getChild($tagId) {
try {
if ($this->tagMapper->haveTag($this->objectId, $this->objectType, $tagId, true)) {
$tag = $this->tagManager->getTagsById($tagId);
return $this->makeNode(current($tag));
}
throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId);
} catch (\InvalidArgumentException $e) {
throw new BadRequest('Invalid tag id', 0, $e);
} catch (TagNotFoundException $e) {
throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e);
}
}
function getChildren() {
$tagIds = current($this->tagMapper->getTagIdsForObjects($this->objectId, $this->objectType));
if (empty($tagIds)) {
return [];
}
$tags = $this->tagManager->getTagsById($tagIds);
return array_map(function($tag) {
return $this->makeNode($tag);
}, $tags);
}
function childExists($tagId) {
try {
return ($this->tagMapper->haveTag($this->objectId, $this->objectType, $tagId, true));
} catch (\InvalidArgumentException $e) {
throw new BadRequest('Invalid tag id', 0, $e);
} catch (TagNotFoundException $e) {
throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e);
}
}
function delete() {
throw new Forbidden('Permission denied to delete this collection');
}
function getName() {
return $this->objectId;
}
function setName($name) {
throw new Forbidden('Permission denied to rename this collection');
}
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
function getLastModified() {
return null;
}
/**
* Create a sabre node for the given system tag
*
* @param ISystemTag $tag
*
* @return SystemTagNode
*/
private function makeNode(ISystemTag $tag) {
return new SystemTagMappingNode(
$tag,
$this->objectId,
$this->objectType,
$this->tagManager,
$this->tagMapper
);
}
}

View File

@ -0,0 +1,114 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\SystemTag;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\ICollection;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\TagNotFoundException;
use OC\SystemTag\SystemTag;
/**
* Collection containing object ids by object type
*/
class SystemTagsObjectTypeCollection implements ICollection {
/**
* @var string
*/
private $objectType;
/**
* @var ISystemTagManager
*/
private $tagManager;
/**
* @var ISystemTagObjectMapper
*/
private $tagMapper;
/**
* Constructor
*
* @param string $objectType object type
* @param ISystemTagManager $tagManager
* @param ISystemTagObjectMapper $tagMapper
*/
public function __construct($objectType, $tagManager, $tagMapper) {
$this->tagManager = $tagManager;
$this->tagMapper = $tagMapper;
$this->objectType = $objectType;
}
function createFile($name, $data = null) {
throw new Forbidden('Permission denied to create collections');
}
function createDirectory($name) {
throw new Forbidden('Permission denied to create collections');
}
function getChild($objectId) {
return new SystemTagsObjectMappingCollection(
$objectId,
$this->objectType,
$this->tagManager,
$this->tagMapper
);
}
function getChildren() {
// do not list object ids
throw new MethodNotAllowed();
}
function childExists($name) {
return true;
}
function delete() {
throw new Forbidden('Permission denied to delete this collection');
}
function getName() {
return $this->objectType;
}
function setName($name) {
throw new Forbidden('Permission denied to rename this collection');
}
/**
* Returns the last modification time, as a unix timestamp
*
* @return int
*/
function getLastModified() {
return null;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\SystemTag;
use Sabre\DAV\SimpleCollection;
class SystemTagsRelationsCollection extends SimpleCollection {
/**
* SystemTagsRelationsCollection constructor.
*
* @param ISystemTagManager $tagManager
* @param ISystemTagObjectMapper $tagMapper
*/
public function __construct($tagManager, $tagMapper) {
$children = [
new SystemTagsObjectTypeCollection('files', $tagManager, $tagMapper),
];
parent::__construct('root', $children);
}
function getName() {
return 'systemtags-relations';
}
function setName($name) {
throw new Forbidden('Permission denied to rename this collection');
}
}

View File

@ -171,6 +171,10 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
public function haveTag($objIds, $objectType, $tagId, $all = true) { public function haveTag($objIds, $objectType, $tagId, $all = true) {
$this->assertTagsExist([$tagId]); $this->assertTagsExist([$tagId]);
if (!is_array($objIds)) {
$objIds = [$objIds];
}
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
if (!$all) { if (!$all) {