summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-05-24 15:23:50 +0200
committerJoas Schilling <coding@schilljs.com>2016-07-18 10:26:36 +0200
commit8e13ff2c8621efc2640ff1fcd2c2b58391b09f6c (patch)
tree770f5a144c33b6267d404a7149a18b92b3ee09fa /apps/dav
parent5157c5a9c4b08518dc86e5755b991183f4323c43 (diff)
downloadnextcloud-server-8e13ff2c8621efc2640ff1fcd2c2b58391b09f6c.tar.gz
nextcloud-server-8e13ff2c8621efc2640ff1fcd2c2b58391b09f6c.zip
Fix TODO and bring in abstraction (similar to comments)
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/RootCollection.php3
-rw-r--r--apps/dav/lib/SystemTag/SystemTagsObjectTypeCollection.php23
-rw-r--r--apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php10
-rw-r--r--apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php13
4 files changed, 21 insertions, 28 deletions
diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php
index fd05ec2626f..356aad4e03a 100644
--- a/apps/dav/lib/RootCollection.php
+++ b/apps/dav/lib/RootCollection.php
@@ -71,8 +71,7 @@ class RootCollection extends SimpleCollection {
\OC::$server->getSystemTagManager(),
\OC::$server->getSystemTagObjectMapper(),
\OC::$server->getUserSession(),
- \OC::$server->getGroupManager(),
- \OC::$server->getRootFolder()
+ \OC::$server->getGroupManager()
);
$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..ba5b3e1185b 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,14 +83,14 @@ 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;
}
/**
@@ -133,17 +132,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() {
diff --git a/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php b/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php
index 19db39d3f3a..b09f95ccd65 100644
--- a/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php
+++ b/apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php
@@ -29,7 +29,6 @@ use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\SimpleCollection;
use OCP\IUserSession;
use OCP\IGroupManager;
-use OCP\Files\IRootFolder;
class SystemTagsRelationsCollection extends SimpleCollection {
@@ -40,14 +39,12 @@ class SystemTagsRelationsCollection extends SimpleCollection {
* @param ISystemTagObjectMapper $tagMapper
* @param IUserSession $userSession
* @param IGroupManager $groupManager
- * @param IRootFolder $fileRoot
*/
public function __construct(
ISystemTagManager $tagManager,
ISystemTagObjectMapper $tagMapper,
IUserSession $userSession,
- IGroupManager $groupManager,
- IRootFolder $fileRoot
+ IGroupManager $groupManager
) {
$children = [
new SystemTagsObjectTypeCollection(
@@ -56,7 +53,10 @@ class SystemTagsRelationsCollection extends SimpleCollection {
$tagMapper,
$userSession,
$groupManager,
- $fileRoot
+ function($name) {
+ $nodes = \OC::$server->getUserFolder()->getById(intval($name));
+ return !empty($nodes);
+ }
),
];
diff --git a/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php b/apps/dav/tests/unit/SystemTag/SystemTagsObjectTypeCollectionTest.php
index 628abe6689a..5b864802251 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,7 +84,7 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase {
$this->tagMapper,
$userSession,
$groupManager,
- $fileRoot
+ $closure
);
}