summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-09-12 17:09:46 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-10-19 11:06:29 +0200
commit361f008c705009eee8d7435f46095760ac706456 (patch)
tree95e7033befa4ff0fc20e60f5df2a4b249575d636 /apps/dav/lib
parent5e48ce98c70fa511ea2c1caeb332594912c9d96a (diff)
downloadnextcloud-server-361f008c705009eee8d7435f46095760ac706456.tar.gz
nextcloud-server-361f008c705009eee8d7435f46095760ac706456.zip
Make it possible to filter by tags with REPORT method
Enhanced the REPORT method on the Webdav endpoint and added a "oc:favorite" filter rule. When set, it will return a flat list of results filtered with only favorite files. The web UI was also adjusted to use this REPORT method instead of the private API endpoint. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/Connector/Sabre/FilesReportPlugin.php42
-rw-r--r--apps/dav/lib/Connector/Sabre/ServerFactory.php1
-rw-r--r--apps/dav/lib/Connector/Sabre/ShareTypeList.php6
-rw-r--r--apps/dav/lib/Connector/Sabre/TagList.php6
4 files changed, 53 insertions, 2 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
index 5b96f4f0f64..4df5f8b80e5 100644
--- a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
@@ -39,6 +39,7 @@ use OCP\Files\Folder;
use OCP\IGroupManager;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\TagNotFoundException;
+use OCP\ITagManager;
class FilesReportPlugin extends ServerPlugin {
@@ -75,6 +76,13 @@ class FilesReportPlugin extends ServerPlugin {
private $tagMapper;
/**
+ * Manager for private tags
+ *
+ * @var ITagManager
+ */
+ private $fileTagger;
+
+ /**
* @var IUserSession
*/
private $userSession;
@@ -92,11 +100,18 @@ class FilesReportPlugin extends ServerPlugin {
/**
* @param Tree $tree
* @param View $view
+ * @param ISystemTagManager $tagManager
+ * @param ISystemTagObjectMapper $tagMapper
+ * @param ITagManager $fileTagger manager for private tags
+ * @param IUserSession $userSession
+ * @param IGroupManager $groupManager
+ * @param Folder $userfolder
*/
public function __construct(Tree $tree,
View $view,
ISystemTagManager $tagManager,
ISystemTagObjectMapper $tagMapper,
+ ITagManager $fileTagger,
IUserSession $userSession,
IGroupManager $groupManager,
Folder $userFolder
@@ -105,6 +120,7 @@ class FilesReportPlugin extends ServerPlugin {
$this->fileView = $view;
$this->tagManager = $tagManager;
$this->tagMapper = $tagMapper;
+ $this->fileTagger = $fileTagger;
$this->userSession = $userSession;
$this->groupManager = $groupManager;
$this->userFolder = $userFolder;
@@ -215,12 +231,38 @@ class FilesReportPlugin extends ServerPlugin {
$ns = '{' . $this::NS_OWNCLOUD . '}';
$resultFileIds = null;
$systemTagIds = [];
+ $favoriteFilter = null;
foreach ($filterRules as $filterRule) {
if ($filterRule['name'] === $ns . 'systemtag') {
$systemTagIds[] = $filterRule['value'];
}
+ if ($filterRule['name'] === $ns . 'favorite') {
+ $favoriteFilter = true;
+ }
}
+ if ($favoriteFilter !== null) {
+ $resultFileIds = $this->fileTagger->load('files')->getFavorites();
+ if (empty($resultFileIds)) {
+ return [];
+ }
+ }
+
+ if (!empty($systemTagIds)) {
+ $fileIds = $this->getSystemTagFileIds($systemTagIds);
+ if (empty($resultFileIds)) {
+ $resultFileIds = $fileIds;
+ } else {
+ $resultFileIds = array_intersect($fileIds, $resultFileIds);
+ }
+ }
+
+ return $resultFileIds;
+ }
+
+ private function getSystemTagFileIds($systemTagIds) {
+ $resultFileIds = null;
+
// check user permissions, if applicable
if (!$this->isAdmin()) {
// check visibility/permission
diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php
index 644f0f28f57..6d9f9b1bc8b 100644
--- a/apps/dav/lib/Connector/Sabre/ServerFactory.php
+++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php
@@ -177,6 +177,7 @@ class ServerFactory {
$view,
\OC::$server->getSystemTagManager(),
\OC::$server->getSystemTagObjectMapper(),
+ \OC::$server->getTagManager(),
$this->userSession,
\OC::$server->getGroupManager(),
$userFolder
diff --git a/apps/dav/lib/Connector/Sabre/ShareTypeList.php b/apps/dav/lib/Connector/Sabre/ShareTypeList.php
index fd9ba3f7267..4d9179b6651 100644
--- a/apps/dav/lib/Connector/Sabre/ShareTypeList.php
+++ b/apps/dav/lib/Connector/Sabre/ShareTypeList.php
@@ -66,7 +66,11 @@ class ShareTypeList implements Element {
static function xmlDeserialize(Reader $reader) {
$shareTypes = [];
- foreach ($reader->parseInnerTree() as $elem) {
+ $tree = $reader->parseInnerTree();
+ if ($tree === null) {
+ return null;
+ }
+ foreach ($tree as $elem) {
if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') {
$shareTypes[] = (int)$elem['value'];
}
diff --git a/apps/dav/lib/Connector/Sabre/TagList.php b/apps/dav/lib/Connector/Sabre/TagList.php
index 23576171262..2f514112a43 100644
--- a/apps/dav/lib/Connector/Sabre/TagList.php
+++ b/apps/dav/lib/Connector/Sabre/TagList.php
@@ -85,7 +85,11 @@ class TagList implements Element {
static function xmlDeserialize(Reader $reader) {
$tags = [];
- foreach ($reader->parseInnerTree() as $elem) {
+ $tree = $reader->parseInnerTree();
+ if ($tree === null) {
+ return null;
+ }
+ foreach ($tree as $elem) {
if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
$tags[] = $elem['value'];
}