Skip to content
Closed
Prev Previous commit
Next Next commit
Created infrastructure to show circles' shared files
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 <[email protected]>
  • Loading branch information
viniciuscb committed Oct 20, 2017
commit 253b263109700cf28b36c96e21e59f638f5b5def
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 @@ -45,6 +45,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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be {http:/nextcloud.com/ns}circle

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, adding hooks in dav app would be more elegant. But since system tags are already core factored in dav, we thought a first approach would be to have both system tags and circles working similarly.

We would be happy to collaborate to implement hooks in dav in the future, and then migrate both circles and system tags to the hooks approach.

Maybe, for NC13, we could start the way we've implemented now... What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another difference ;)
systemtags are shipped (therefor the code is not missing etc) while circles are totally optional


/**
* Reference to main server object
Expand Down Expand Up @@ -255,14 +256,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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's CIRCLE_PROPERTYNAME now

$circlesIds[] = $filterRule['value'];
}
if ($filterRule['name'] === $ns . 'favorite') {
$favoriteFilter = true;
}

}

if ($favoriteFilter !== null) {
Expand All @@ -281,6 +287,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 @@ -327,6 +342,29 @@ private function getSystemTagFileIds($systemTagIds) {
return $resultFileIds;
}

private function getCirclesFileIds($circlesIds) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPDocs on the function parameters and the return value would be awesome.

Also is $circlesIds an array? If so you can typehint it with array $circleIds.


// 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');
}
}
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe cleaning those commented line


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 @@ -454,7 +454,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 @@ -476,7 +476,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 @@ -502,6 +503,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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nc?

});
if (filter.favorite) {
body += ' <oc:favorite>' + (filter.favorite ? '1': '0') + '</oc:favorite>\n';
}
Expand Down