Fix TODO and bring in abstraction (similar to comments)

This commit is contained in:
Joas Schilling 2016-05-24 15:23:50 +02:00
parent 5157c5a9c4
commit 8e13ff2c86
No known key found for this signature in database
GPG key ID: E166FD8976B3BAC8
4 changed files with 21 additions and 28 deletions

View file

@ -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(),

View file

@ -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() {

View file

@ -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);
}
),
];

View file

@ -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
);
}