diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-07-19 10:47:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-19 10:47:12 +0200 |
commit | 0a6d95b1265be8755add34ff860764173197f57a (patch) | |
tree | 6fdea4f90cb3dd2444ec0ebdb59adb0498e430db /apps | |
parent | 4a963c21fff251a5ea105e6ec50e6d87dca1654e (diff) | |
parent | 9795a732ff755b87f2e314d0cb5d3ac193515d83 (diff) | |
download | nextcloud-server-0a6d95b1265be8755add34ff860764173197f57a.tar.gz nextcloud-server-0a6d95b1265be8755add34ff860764173197f57a.zip |
Merge pull request #394 from nextcloud/tags-for-everything
SystemTags for everything not just files
Diffstat (limited to 'apps')
8 files changed, 68 insertions, 51 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); } diff --git a/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php b/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php index 7e0e98eb78d..c54de152785 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php @@ -140,7 +140,7 @@ class SystemTagMappingNodeTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testDeleteTagNotFound() { // assuming the tag existed at the time the node was created, diff --git a/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php b/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php index 0a6c6b93560..252e592f73f 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php @@ -79,7 +79,7 @@ class SystemTagNodeTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed + * @expectedException \Sabre\DAV\Exception\MethodNotAllowed */ public function testSetName() { $this->getTagNode()->setName('2'); @@ -196,7 +196,7 @@ class SystemTagNodeTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\Conflict + * @expectedException \Sabre\DAV\Exception\Conflict */ public function testUpdateTagAlreadyExists() { $tag = new SystemTag(1, 'tag1', true, true); @@ -216,7 +216,7 @@ class SystemTagNodeTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testUpdateTagNotFound() { $tag = new SystemTag(1, 'tag1', true, true); @@ -294,7 +294,7 @@ class SystemTagNodeTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testDeleteTagNotFound() { $tag = new SystemTag(1, 'tag1', true, true); diff --git a/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php b/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php index 05a84731338..ee7a1f658a4 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php @@ -74,14 +74,14 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testForbiddenCreateFile() { $this->getNode()->createFile('555'); } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testForbiddenCreateDirectory() { $this->getNode()->createDirectory('789'); @@ -107,7 +107,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testGetChildInvalidName() { $this->tagManager->expects($this->once()) @@ -119,7 +119,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testGetChildNotFound() { $this->tagManager->expects($this->once()) @@ -131,7 +131,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testGetChildUserNotVisible() { $tag = new SystemTag(123, 'Test', false, false); @@ -225,7 +225,7 @@ class SystemTagsByIdCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testChildExistsBadRequest() { $this->tagManager->expects($this->once()) diff --git a/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php b/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php index cca781dc28e..e4f7e1bbd40 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagsObjectMappingCollectionTest.php @@ -128,7 +128,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\PreconditionFailed + * @expectedException \Sabre\DAV\Exception\PreconditionFailed */ public function testAssignTagNotFound() { $this->tagManager->expects($this->once()) @@ -140,7 +140,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testForbiddenCreateDirectory() { $this->getNode()->createDirectory('789'); @@ -193,7 +193,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testGetChildRelationNotFound() { $this->tagMapper->expects($this->once()) @@ -205,7 +205,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testGetChildInvalidId() { $this->tagMapper->expects($this->once()) @@ -217,7 +217,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testGetChildTagDoesNotExist() { $this->tagMapper->expects($this->once()) @@ -321,7 +321,7 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testChildExistsInvalidId() { $this->tagMapper->expects($this->once()) @@ -333,14 +333,14 @@ class SystemTagsObjectMappingCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testDelete() { $this->getNode()->delete(); } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testSetName() { $this->getNode()->setName('somethingelse'); diff --git a/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php b/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php index 628abe6689a..3c4d4dfc716 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php @@ -71,13 +71,12 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { $this->userFolder = $this->getMockBuilder('\OCP\Files\Folder') ->getMock(); + $userFolder = $this->userFolder; - $fileRoot = $this->getMockBuilder('\OCP\Files\IRootFolder') - ->getMock(); - $fileRoot->expects($this->any()) - ->method('getUserfolder') - ->with('testuser') - ->will($this->returnValue($this->userFolder)); + $closure = function($name) use ($userFolder) { + $nodes = $userFolder->getById(intval($name)); + return !empty($nodes); + }; $this->node = new \OCA\DAV\SystemTag\SystemTagsObjectTypeCollection( 'files', @@ -85,19 +84,19 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { $this->tagMapper, $userSession, $groupManager, - $fileRoot + $closure ); } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testForbiddenCreateFile() { $this->node->createFile('555'); } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testForbiddenCreateDirectory() { $this->node->createDirectory('789'); @@ -115,7 +114,7 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\NotFound + * @expectedException \Sabre\DAV\Exception\NotFound */ public function testGetChildWithoutAccess() { $this->userFolder->expects($this->once()) @@ -126,7 +125,7 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed + * @expectedException \Sabre\DAV\Exception\MethodNotAllowed */ public function testGetChildren() { $this->node->getChildren(); @@ -149,14 +148,14 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase { } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testDelete() { $this->node->delete(); } /** - * @expectedException Sabre\DAV\Exception\Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testSetName() { $this->node->setName('somethingelse'); |