summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Connector/Sabre
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2019-03-13 00:06:46 +0100
committerGitHub <noreply@github.com>2019-03-13 00:06:46 +0100
commitf0c85a0f5f84f6bacd4a58520669a71aff944660 (patch)
treedabe321d80514e6afa7019117d8a68fd25c76a77 /apps/dav/lib/Connector/Sabre
parent33c34ddafafe5f8f815dbde94dc477758d67db20 (diff)
parent5cc5107cba1bc35d51d28569bf46813cc89f26c6 (diff)
downloadnextcloud-server-f0c85a0f5f84f6bacd4a58520669a71aff944660.tar.gz
nextcloud-server-f0c85a0f5f84f6bacd4a58520669a71aff944660.zip
Merge pull request #6512 from coletivoEITA/add_circles_sharing_to_caldav
Change CALDAV to allow calendars be shared with circles.
Diffstat (limited to 'apps/dav/lib/Connector/Sabre')
-rw-r--r--apps/dav/lib/Connector/Sabre/Principal.php82
-rw-r--r--apps/dav/lib/Connector/Sabre/SharesPlugin.php3
2 files changed, 84 insertions, 1 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php
index 2574fbcd436..a441e1c8122 100644
--- a/apps/dav/lib/Connector/Sabre/Principal.php
+++ b/apps/dav/lib/Connector/Sabre/Principal.php
@@ -13,6 +13,8 @@
* @author Thomas Tanghus <thomas@tanghus.net>
* @author Vincent Petry <pvince81@owncloud.com>
* @author Georg Ehrke <oc.list@georgehrke.com>
+ * @author Vinicius Cubas Brand <vinicius@eita.org.br>
+ * @author Daniel Tygel <dtygel@eita.org.br>
*
* @license AGPL-3.0
*
@@ -32,6 +34,9 @@
namespace OCA\DAV\Connector\Sabre;
+use OCA\Circles\Exceptions\CircleDoesNotExistException;
+use OCP\App\IAppManager;
+use OCP\AppFramework\QueryException;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -60,12 +65,18 @@ class Principal implements BackendInterface {
/** @var IConfig */
private $config;
+ /** @var IAppManager */
+ private $appManager;
+
/** @var string */
private $principalPrefix;
/** @var bool */
private $hasGroups;
+ /** @var bool */
+ private $hasCircles;
+
/**
* @param IUserManager $userManager
* @param IGroupManager $groupManager
@@ -79,14 +90,16 @@ class Principal implements BackendInterface {
IShareManager $shareManager,
IUserSession $userSession,
IConfig $config,
+ IAppManager $appManager,
$principalPrefix = 'principals/users/') {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->shareManager = $shareManager;
$this->userSession = $userSession;
$this->config = $config;
+ $this->appManager = $appManager;
$this->principalPrefix = trim($principalPrefix, '/');
- $this->hasGroups = ($principalPrefix === 'principals/users/');
+ $this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/');
}
/**
@@ -131,6 +144,8 @@ class Principal implements BackendInterface {
if ($user !== null) {
return $this->userToPrincipal($user);
}
+ } else if ($prefix === 'principals/circles') {
+ return $this->circleToPrincipal($name);
}
return null;
}
@@ -388,4 +403,69 @@ class Principal implements BackendInterface {
return $this->principalPrefix;
}
+ /**
+ * @param string $circleUniqueId
+ * @return array|null
+ * @suppress PhanUndeclaredClassMethod
+ * @suppress PhanUndeclaredClassCatch
+ */
+ protected function circleToPrincipal($circleUniqueId) {
+ if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
+ return null;
+ }
+
+ try {
+ $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId, true);
+ } catch(QueryException $ex) {
+ return null;
+ } catch(CircleDoesNotExistException $ex) {
+ return null;
+ }
+
+ if (!$circle) {
+ return null;
+ }
+
+ $principal = [
+ 'uri' => 'principals/circles/' . $circleUniqueId,
+ '{DAV:}displayname' => $circle->getName(),
+ ];
+
+ return $principal;
+ }
+
+ /**
+ * Returns the list of circles a principal is a member of
+ *
+ * @param string $principal
+ * @param bool $needGroups
+ * @return array
+ * @throws Exception
+ * @suppress PhanUndeclaredClassMethod
+ */
+ public function getCircleMembership($principal):array {
+ if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) {
+ return [];
+ }
+
+ list($prefix, $name) = \Sabre\Uri\split($principal);
+ if ($this->hasCircles && $prefix === $this->principalPrefix) {
+ $user = $this->userManager->get($name);
+ if (!$user) {
+ throw new Exception('Principal not found');
+ }
+
+ $circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true);
+
+ $circles = array_map(function($circle) {
+ /** @var \OCA\Circles\Model\Circle $group */
+ return 'principals/circles/' . urlencode($circle->getUniqueId());
+ }, $circles);
+
+ return $circles;
+
+ }
+ return [];
+ }
+
}
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
index 990cc4a808f..46174c8118e 100644
--- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
@@ -7,6 +7,8 @@
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Vincent Petry <pvince81@owncloud.com>
+ * @author Vinicius Cubas Brand <vinicius@eita.org.br>
+ * @author Daniel Tygel <dtygel@eita.org.br>
*
* @license AGPL-3.0
*
@@ -125,6 +127,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
\OCP\Share::SHARE_TYPE_REMOTE,
\OCP\Share::SHARE_TYPE_EMAIL,
\OCP\Share::SHARE_TYPE_ROOM,
+ \OCP\Share::SHARE_TYPE_CIRCLE,
];
foreach ($requestedShareTypes as $requestedShareType) {
// one of each type is enough to find out about the types