Skip to content

Commit

Permalink
Created infrastructure to show circles' shared files
Browse files Browse the repository at this point in the history
There is a proposal to allow users to filter files shared to circles. This commit is needed to provide the infrastucture for it.

Issue: nextcloud/circles#137

Signed-off-by: Vinicius Cubas Brand <viniciuscb@gmail.com>
  • Loading branch information
viniciuscb authored and MorrisJobke committed Mar 12, 2019
1 parent f0c85a0 commit 5396326
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
38 changes: 38 additions & 0 deletions apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FilesReportPlugin extends ServerPlugin {
const NS_OWNCLOUD = 'http://owncloud.org/ns';
const REPORT_NAME = '{http://owncloud.org/ns}filter-files';
const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag';
const CIRCLE_PROPERTYNAME = '{http://owncloud.org/ns}circle';

/**
* Reference to main server object
Expand Down Expand Up @@ -256,14 +257,19 @@ protected function processFilterRules($filterRules) {
$ns = '{' . $this::NS_OWNCLOUD . '}';
$resultFileIds = null;
$systemTagIds = [];
$circlesIds = [];
$favoriteFilter = null;
foreach ($filterRules as $filterRule) {
if ($filterRule['name'] === $ns . 'systemtag') {
$systemTagIds[] = $filterRule['value'];
}
if ($filterRule['name'] === $ns . 'circle') {
$circlesIds[] = $filterRule['value'];
}
if ($filterRule['name'] === $ns . 'favorite') {
$favoriteFilter = true;
}

}

if ($favoriteFilter !== null) {
Expand All @@ -282,6 +288,15 @@ protected function processFilterRules($filterRules) {
}
}

if (!empty($circlesIds)) {
$fileIds = $this->getCirclesFileIds($circlesIds);
if (empty($resultFileIds)) {
$resultFileIds = $fileIds;
} else {
$resultFileIds = array_intersect($fileIds, $resultFileIds);
}
}

return $resultFileIds;
}

Expand Down Expand Up @@ -328,6 +343,29 @@ private function getSystemTagFileIds($systemTagIds) {
return $resultFileIds;
}

private function getCirclesFileIds($circlesIds) {

// check user permissions, if applicable
/*
if (!$this->isAdmin()) {
// check visibility/permission
$tags = $this->tagManager->getTagsByIds($circlesIds);
$unknownTagIds = [];
foreach ($tags as $tag) {
if (!$tag->isUserVisible()) {
$unknownTagIds[] = $tag->getId();
}
}
if (!empty($unknownTagIds)) {
throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found');
}
}
*/

return \OCA\Circles\Api\v1\Circles::getObjectIdsForCircles($circlesIds);
}

/**
* Prepare propfind response for the given nodes
*
Expand Down
8 changes: 6 additions & 2 deletions core/js/files/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@

/**
* Fetches a flat list of files filtered by a given filter criteria.
* (currently only system tags is supported)
* (currently system tags and circles are supported)
*
* @param {Object} filter filter criteria
* @param {Object} [filter.systemTagIds] list of system tag ids to filter by
Expand All @@ -525,7 +525,8 @@
properties = options.properties;
}

if (!filter || (!filter.systemTagIds && _.isUndefined(filter.favorite))) {
if (!filter ||
(!filter.systemTagIds && _.isUndefined(filter.favorite) && !filter.circlesIds) ) {
throw 'Missing filter argument';
}

Expand All @@ -551,6 +552,9 @@
_.each(filter.systemTagIds, function(systemTagIds) {
body += ' <oc:systemtag>' + escapeHTML(systemTagIds) + '</oc:systemtag>\n';
});
_.each(filter.circlesIds, function(circlesIds) {
body += ' <oc:circle>' + escapeHTML(circlesIds) + '</oc:circle>\n';
});
if (filter.favorite) {
body += ' <oc:favorite>' + (filter.favorite ? '1': '0') + '</oc:favorite>\n';
}
Expand Down

0 comments on commit 5396326

Please sign in to comment.