summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Connector/Sabre
diff options
context:
space:
mode:
authorVinicius Cubas Brand <viniciuscb@gmail.com>2017-09-29 18:43:04 -0300
committerMorris Jobke <hey@morrisjobke.de>2019-03-13 00:31:38 +0100
commit9bb13fb05fffe9af94f1e57866a025382b71f5a4 (patch)
treedb9f20a2bc3c90be8958398e8e50efe02a81ef6c /apps/dav/lib/Connector/Sabre
parentf0c85a0f5f84f6bacd4a58520669a71aff944660 (diff)
downloadnextcloud-server-9bb13fb05fffe9af94f1e57866a025382b71f5a4.tar.gz
nextcloud-server-9bb13fb05fffe9af94f1e57866a025382b71f5a4.zip
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: https://github.com/nextcloud/circles/issues/137 Changes to comply to https://github.com/coletivoEITA/circles/pull/2 Polishing: get files shared to circles in caldav Signed-off-by: Vinicius Cubas Brand <viniciuscb@gmail.com> Signed-off-by: Maxence Lange <maxence@artificial-owl.com> Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps/dav/lib/Connector/Sabre')
-rw-r--r--apps/dav/lib/Connector/Sabre/FilesReportPlugin.php28
-rw-r--r--apps/dav/lib/Connector/Sabre/Principal.php15
2 files changed, 38 insertions, 5 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
index 3e85615638b..f4e5de0ea43 100644
--- a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
@@ -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
@@ -256,14 +257,19 @@ class FilesReportPlugin extends ServerPlugin {
$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'] === self::CIRCLE_PROPERTYNAME) {
+ $circlesIds[] = $filterRule['value'];
+ }
if ($filterRule['name'] === $ns . 'favorite') {
$favoriteFilter = true;
}
+
}
if ($favoriteFilter !== null) {
@@ -282,6 +288,15 @@ class FilesReportPlugin extends ServerPlugin {
}
}
+ if (!empty($circlesIds)) {
+ $fileIds = $this->getCirclesFileIds($circlesIds);
+ if (empty($resultFileIds)) {
+ $resultFileIds = $fileIds;
+ } else {
+ $resultFileIds = array_intersect($fileIds, $resultFileIds);
+ }
+ }
+
return $resultFileIds;
}
@@ -329,6 +344,19 @@ class FilesReportPlugin extends ServerPlugin {
}
/**
+ * @suppress PhanUndeclaredClassMethod
+ * @param array $circlesIds
+ * @return array
+ */
+ private function getCirclesFileIds(array $circlesIds) {
+ if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
+ return array();
+ }
+ return \OCA\Circles\Api\v1\Circles::getFilesForCircles($circlesIds);
+ }
+
+
+ /**
* Prepare propfind response for the given nodes
*
* @param string $filesUri $filesUri URI leading to root of the files URI,
diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php
index a441e1c8122..e7816185394 100644
--- a/apps/dav/lib/Connector/Sabre/Principal.php
+++ b/apps/dav/lib/Connector/Sabre/Principal.php
@@ -45,7 +45,7 @@ use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IManager as IShareManager;
use Sabre\DAV\Exception;
-use \Sabre\DAV\PropPatch;
+use Sabre\DAV\PropPatch;
use Sabre\DAVACL\PrincipalBackend\BackendInterface;
class Principal implements BackendInterface {
@@ -145,7 +145,11 @@ class Principal implements BackendInterface {
return $this->userToPrincipal($user);
}
} else if ($prefix === 'principals/circles') {
- return $this->circleToPrincipal($name);
+ try {
+ return $this->circleToPrincipal($name);
+ } catch (QueryException $e) {
+ return null;
+ }
}
return null;
}
@@ -406,6 +410,7 @@ class Principal implements BackendInterface {
/**
* @param string $circleUniqueId
* @return array|null
+ * @throws \OCP\AppFramework\QueryException
* @suppress PhanUndeclaredClassMethod
* @suppress PhanUndeclaredClassCatch
*/
@@ -438,9 +443,9 @@ class Principal implements BackendInterface {
* Returns the list of circles a principal is a member of
*
* @param string $principal
- * @param bool $needGroups
* @return array
* @throws Exception
+ * @throws \OCP\AppFramework\QueryException
* @suppress PhanUndeclaredClassMethod
*/
public function getCircleMembership($principal):array {
@@ -458,13 +463,13 @@ class Principal implements BackendInterface {
$circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true);
$circles = array_map(function($circle) {
- /** @var \OCA\Circles\Model\Circle $group */
+ /** @var \OCA\Circles\Model\Circle $circle */
return 'principals/circles/' . urlencode($circle->getUniqueId());
}, $circles);
return $circles;
-
}
+
return [];
}