Fix TODO and bring in abstraction (similar to comments)
This commit is contained in:
parent
5157c5a9c4
commit
8e13ff2c86
|
@ -71,8 +71,7 @@ class RootCollection extends SimpleCollection {
|
||||||
\OC::$server->getSystemTagManager(),
|
\OC::$server->getSystemTagManager(),
|
||||||
\OC::$server->getSystemTagObjectMapper(),
|
\OC::$server->getSystemTagObjectMapper(),
|
||||||
\OC::$server->getUserSession(),
|
\OC::$server->getUserSession(),
|
||||||
\OC::$server->getGroupManager(),
|
\OC::$server->getGroupManager()
|
||||||
\OC::$server->getRootFolder()
|
|
||||||
);
|
);
|
||||||
$commentsCollection = new Comments\RootCollection(
|
$commentsCollection = new Comments\RootCollection(
|
||||||
\OC::$server->getCommentsManager(),
|
\OC::$server->getCommentsManager(),
|
||||||
|
|
|
@ -31,7 +31,6 @@ use OCP\SystemTag\ISystemTagManager;
|
||||||
use OCP\SystemTag\ISystemTagObjectMapper;
|
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use OCP\Files\IRootFolder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection containing object ids by object type
|
* Collection containing object ids by object type
|
||||||
|
@ -64,9 +63,9 @@ class SystemTagsObjectTypeCollection implements ICollection {
|
||||||
private $userSession;
|
private $userSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var IRootFolder
|
* @var \Closure
|
||||||
**/
|
**/
|
||||||
protected $fileRoot;
|
protected $childExistsFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -76,7 +75,7 @@ class SystemTagsObjectTypeCollection implements ICollection {
|
||||||
* @param ISystemTagObjectMapper $tagMapper
|
* @param ISystemTagObjectMapper $tagMapper
|
||||||
* @param IUserSession $userSession
|
* @param IUserSession $userSession
|
||||||
* @param IGroupManager $groupManager
|
* @param IGroupManager $groupManager
|
||||||
* @param IRootFolder $fileRoot
|
* @param \Closure $childExistsFunction
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$objectType,
|
$objectType,
|
||||||
|
@ -84,14 +83,14 @@ class SystemTagsObjectTypeCollection implements ICollection {
|
||||||
ISystemTagObjectMapper $tagMapper,
|
ISystemTagObjectMapper $tagMapper,
|
||||||
IUserSession $userSession,
|
IUserSession $userSession,
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager,
|
||||||
IRootFolder $fileRoot
|
\Closure $childExistsFunction
|
||||||
) {
|
) {
|
||||||
$this->tagManager = $tagManager;
|
$this->tagManager = $tagManager;
|
||||||
$this->tagMapper = $tagMapper;
|
$this->tagMapper = $tagMapper;
|
||||||
$this->objectType = $objectType;
|
$this->objectType = $objectType;
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->groupManager = $groupManager;
|
$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
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function childExists($name) {
|
function childExists($name) {
|
||||||
// TODO: make this more abstract
|
return call_user_func($this->childExistsFunction, $name);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete() {
|
function delete() {
|
||||||
|
|
|
@ -29,7 +29,6 @@ use Sabre\DAV\Exception\Forbidden;
|
||||||
use Sabre\DAV\SimpleCollection;
|
use Sabre\DAV\SimpleCollection;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use OCP\Files\IRootFolder;
|
|
||||||
|
|
||||||
class SystemTagsRelationsCollection extends SimpleCollection {
|
class SystemTagsRelationsCollection extends SimpleCollection {
|
||||||
|
|
||||||
|
@ -40,14 +39,12 @@ class SystemTagsRelationsCollection extends SimpleCollection {
|
||||||
* @param ISystemTagObjectMapper $tagMapper
|
* @param ISystemTagObjectMapper $tagMapper
|
||||||
* @param IUserSession $userSession
|
* @param IUserSession $userSession
|
||||||
* @param IGroupManager $groupManager
|
* @param IGroupManager $groupManager
|
||||||
* @param IRootFolder $fileRoot
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ISystemTagManager $tagManager,
|
ISystemTagManager $tagManager,
|
||||||
ISystemTagObjectMapper $tagMapper,
|
ISystemTagObjectMapper $tagMapper,
|
||||||
IUserSession $userSession,
|
IUserSession $userSession,
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager
|
||||||
IRootFolder $fileRoot
|
|
||||||
) {
|
) {
|
||||||
$children = [
|
$children = [
|
||||||
new SystemTagsObjectTypeCollection(
|
new SystemTagsObjectTypeCollection(
|
||||||
|
@ -56,7 +53,10 @@ class SystemTagsRelationsCollection extends SimpleCollection {
|
||||||
$tagMapper,
|
$tagMapper,
|
||||||
$userSession,
|
$userSession,
|
||||||
$groupManager,
|
$groupManager,
|
||||||
$fileRoot
|
function($name) {
|
||||||
|
$nodes = \OC::$server->getUserFolder()->getById(intval($name));
|
||||||
|
return !empty($nodes);
|
||||||
|
}
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -71,13 +71,12 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->userFolder = $this->getMockBuilder('\OCP\Files\Folder')
|
$this->userFolder = $this->getMockBuilder('\OCP\Files\Folder')
|
||||||
->getMock();
|
->getMock();
|
||||||
|
$userFolder = $this->userFolder;
|
||||||
|
|
||||||
$fileRoot = $this->getMockBuilder('\OCP\Files\IRootFolder')
|
$closure = function($name) use ($userFolder) {
|
||||||
->getMock();
|
$nodes = $userFolder->getById(intval($name));
|
||||||
$fileRoot->expects($this->any())
|
return !empty($nodes);
|
||||||
->method('getUserfolder')
|
};
|
||||||
->with('testuser')
|
|
||||||
->will($this->returnValue($this->userFolder));
|
|
||||||
|
|
||||||
$this->node = new \OCA\DAV\SystemTag\SystemTagsObjectTypeCollection(
|
$this->node = new \OCA\DAV\SystemTag\SystemTagsObjectTypeCollection(
|
||||||
'files',
|
'files',
|
||||||
|
@ -85,7 +84,7 @@ class SystemTagsObjectTypeCollectionTest extends \Test\TestCase {
|
||||||
$this->tagMapper,
|
$this->tagMapper,
|
||||||
$userSession,
|
$userSession,
|
||||||
$groupManager,
|
$groupManager,
|
||||||
$fileRoot
|
$closure
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue