2015-11-27 14:54:31 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-11-27 14:54:31 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
2016-01-12 17:02:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-11-27 14:54:31 +03:00
|
|
|
* @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\MethodNotAllowed;
|
2016-02-01 20:18:17 +03:00
|
|
|
use Sabre\DAV\Exception\NotFound;
|
2015-11-27 14:54:31 +03:00
|
|
|
use Sabre\DAV\ICollection;
|
|
|
|
|
|
|
|
use OCP\SystemTag\ISystemTagManager;
|
|
|
|
use OCP\SystemTag\ISystemTagObjectMapper;
|
2016-01-21 16:09:15 +03:00
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\IGroupManager;
|
2016-02-01 20:18:17 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
2015-11-27 14:54:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Collection containing object ids by object type
|
|
|
|
*/
|
|
|
|
class SystemTagsObjectTypeCollection implements ICollection {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $objectType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ISystemTagManager
|
|
|
|
*/
|
|
|
|
private $tagManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ISystemTagObjectMapper
|
|
|
|
*/
|
|
|
|
private $tagMapper;
|
|
|
|
|
2016-01-20 13:47:23 +03:00
|
|
|
/**
|
2016-01-21 16:09:15 +03:00
|
|
|
* @var IGroupManager
|
|
|
|
*/
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IUserSession
|
2016-01-20 13:47:23 +03:00
|
|
|
*/
|
2016-01-21 16:09:15 +03:00
|
|
|
private $userSession;
|
2016-01-20 13:47:23 +03:00
|
|
|
|
2016-02-01 20:18:17 +03:00
|
|
|
/**
|
|
|
|
* @var IRootFolder
|
|
|
|
**/
|
|
|
|
protected $fileRoot;
|
|
|
|
|
2015-11-27 14:54:31 +03:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $objectType object type
|
|
|
|
* @param ISystemTagManager $tagManager
|
|
|
|
* @param ISystemTagObjectMapper $tagMapper
|
2016-01-21 16:09:15 +03:00
|
|
|
* @param IUserSession $userSession
|
|
|
|
* @param IGroupManager $groupManager
|
2016-02-01 20:18:17 +03:00
|
|
|
* @param IRootFolder $fileRoot
|
2015-11-27 14:54:31 +03:00
|
|
|
*/
|
2016-01-21 16:09:15 +03:00
|
|
|
public function __construct(
|
|
|
|
$objectType,
|
|
|
|
ISystemTagManager $tagManager,
|
|
|
|
ISystemTagObjectMapper $tagMapper,
|
|
|
|
IUserSession $userSession,
|
2016-02-01 20:18:17 +03:00
|
|
|
IGroupManager $groupManager,
|
|
|
|
IRootFolder $fileRoot
|
2016-01-21 16:09:15 +03:00
|
|
|
) {
|
2015-11-27 14:54:31 +03:00
|
|
|
$this->tagManager = $tagManager;
|
|
|
|
$this->tagMapper = $tagMapper;
|
|
|
|
$this->objectType = $objectType;
|
2016-01-21 16:09:15 +03:00
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->groupManager = $groupManager;
|
2016-02-01 20:18:17 +03:00
|
|
|
$this->fileRoot = $fileRoot;
|
2016-01-21 16:09:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the currently logged in user is an administrator
|
|
|
|
*/
|
|
|
|
private function isAdmin() {
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
if ($user !== null) {
|
|
|
|
return $this->groupManager->isAdmin($user->getUID());
|
|
|
|
}
|
|
|
|
return false;
|
2015-11-27 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
2015-12-08 18:01:20 +03:00
|
|
|
/**
|
|
|
|
* @param string $name
|
2015-12-10 18:43:10 +03:00
|
|
|
* @param resource|string $data Initial payload
|
|
|
|
* @throws Forbidden
|
2015-12-08 18:01:20 +03:00
|
|
|
*/
|
2015-11-27 14:54:31 +03:00
|
|
|
function createFile($name, $data = null) {
|
2015-12-04 19:30:22 +03:00
|
|
|
throw new Forbidden('Permission denied to create nodes');
|
2015-11-27 14:54:31 +03:00
|
|
|
}
|
|
|
|
|
2015-12-08 18:01:20 +03:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2015-11-27 14:54:31 +03:00
|
|
|
function createDirectory($name) {
|
|
|
|
throw new Forbidden('Permission denied to create collections');
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:01:20 +03:00
|
|
|
/**
|
|
|
|
* @param string $objectId
|
|
|
|
*/
|
2015-11-27 14:54:31 +03:00
|
|
|
function getChild($objectId) {
|
2016-02-01 20:18:17 +03:00
|
|
|
// make sure the object exists and is reachable
|
|
|
|
if(!$this->childExists($objectId)) {
|
|
|
|
throw new NotFound('Entity does not exist or is not available');
|
|
|
|
}
|
2015-11-27 14:54:31 +03:00
|
|
|
return new SystemTagsObjectMappingCollection(
|
|
|
|
$objectId,
|
|
|
|
$this->objectType,
|
2016-01-21 16:09:15 +03:00
|
|
|
$this->isAdmin(),
|
2015-11-27 14:54:31 +03:00
|
|
|
$this->tagManager,
|
|
|
|
$this->tagMapper
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChildren() {
|
|
|
|
// do not list object ids
|
|
|
|
throw new MethodNotAllowed();
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:01:20 +03:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2015-11-27 14:54:31 +03:00
|
|
|
function childExists($name) {
|
2016-02-01 20:18:17 +03:00
|
|
|
// 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);
|
|
|
|
}
|
2015-11-27 14:54:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete() {
|
|
|
|
throw new Forbidden('Permission denied to delete this collection');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getName() {
|
|
|
|
return $this->objectType;
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:01:20 +03:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2015-11-27 14:54:31 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|