summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-08-06 13:40:52 +0200
committerGeorg Ehrke <developer@georgehrke.com>2019-08-15 15:41:27 +0200
commit01a4644cad99c8502f15a7f62f72f4e040670024 (patch)
treed6e8d5a5d8fe7ed9560df880ee5ef84afddde9a3 /apps/dav/lib/CalDAV
parent22f29d8e54be32fe44e5d715aa8ae0dbaf558229 (diff)
downloadnextcloud-server-01a4644cad99c8502f15a7f62f72f4e040670024.tar.gz
nextcloud-server-01a4644cad99c8502f15a7f62f72f4e040670024.zip
Use the proxymapper to obtain valid proxy data
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/lib/CalDAV')
-rw-r--r--apps/dav/lib/CalDAV/Calendar.php39
-rw-r--r--apps/dav/lib/CalDAV/Proxy/Proxy.php13
-rw-r--r--apps/dav/lib/CalDAV/Proxy/ProxyMapper.php7
3 files changed, 52 insertions, 7 deletions
diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php
index f26913d7ce1..ae5cb226b0e 100644
--- a/apps/dav/lib/CalDAV/Calendar.php
+++ b/apps/dav/lib/CalDAV/Calendar.php
@@ -26,6 +26,7 @@
*/
namespace OCA\DAV\CalDAV;
+use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\DAV\Sharing\IShareable;
use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
use OCP\IConfig;
@@ -46,6 +47,9 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
/** @var IConfig */
private $config;
+ /** @var ProxyMapper */
+ private $proxyMapper;
+
public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
parent::__construct($caldavBackend, $calendarInfo);
@@ -58,6 +62,9 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
}
$this->config = $config;
+
+ // TODO: proper DI
+ $this->proxyMapper = \OC::$server->query(ProxyMapper::class);
}
/**
@@ -141,7 +148,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
}
if (!$this->isShared()) {
- return $acl;
+ return $this->addProxies($acl);
}
if ($this->getOwner() !== parent::getOwner()) {
@@ -174,9 +181,37 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
- return array_filter($acl, function($rule) use ($allowedPrincipals) {
+ $acl = array_filter($acl, function($rule) use ($allowedPrincipals) {
return \in_array($rule['principal'], $allowedPrincipals, true);
});
+
+ $acl = $this->addProxies($acl);
+
+ return $acl;
+ }
+
+ public function addProxies(array $acl): array {
+ list($prefix, $name) = \Sabre\Uri\split($this->getOwner());
+ $proxies = $this->proxyMapper->getProxiesOf($name);
+
+ foreach ($proxies as $proxy) {
+ if ($proxy->getPermissions() & ProxyMapper::PERMISSION_READ) {
+ $acl[] = [
+ 'privilege' => '{DAV:}read',
+ 'principal' => 'principals/users/' . $proxy->getProxyId(),
+ 'protected' => true,
+ ];
+ }
+ if ($proxy->getPermissions() & ProxyMapper::PERMISSION_WRITE) {
+ $acl[] = [
+ 'privilege' => '{DAV:}write',
+ 'principal' => 'principals/users/' . $proxy->getProxyId(),
+ 'protected' => true,
+ ];
+ }
+ }
+
+ return $acl;
}
public function getChildACL() {
diff --git a/apps/dav/lib/CalDAV/Proxy/Proxy.php b/apps/dav/lib/CalDAV/Proxy/Proxy.php
index 1df97dee19e..cb01470ae82 100644
--- a/apps/dav/lib/CalDAV/Proxy/Proxy.php
+++ b/apps/dav/lib/CalDAV/Proxy/Proxy.php
@@ -22,11 +22,18 @@ declare(strict_types=1);
*
*/
-namespace OCA\DAV\CalDAV\Delegation;
+namespace OCA\DAV\CalDAV\Proxy;
-use OCA\DAV\CalDAV\ProxyMapper;
use OCP\AppFramework\Db\Entity;
+/**
+ * @method string getOwnerId()
+ * @method void setOwnerId(string $ownerId)
+ * @method string getProxyId()
+ * @method void setProxyId(string $proxyId)
+ * @method int getPermissions()
+ * @method void setPermissions(int $permissions)
+ */
class Proxy extends Entity {
/** @var string */
@@ -34,7 +41,7 @@ class Proxy extends Entity {
/** @var string */
protected $proxyId;
/** @var int */
- private $permissions;
+ protected $permissions;
public function __construct() {
$this->addType('ownerId', 'string');
diff --git a/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php b/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php
index d3657b306a9..6a569394c4b 100644
--- a/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php
+++ b/apps/dav/lib/CalDAV/Proxy/ProxyMapper.php
@@ -22,9 +22,8 @@ declare(strict_types=1);
*
*/
-namespace OCA\DAV\CalDAV;
+namespace OCA\DAV\CalDAV\Proxy;
-use OCA\DAV\CalDAV\Delegation\Proxy;
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;
@@ -39,6 +38,8 @@ class ProxyMapper extends QBMapper {
/**
* @param string $proxyId The userId that can act as a proxy for the resulting calendars
+ *
+ * @return Proxy[]
*/
public function getProxiesFor(string $proxyId): array {
$qb = $this->db->getQueryBuilder();
@@ -52,6 +53,8 @@ class ProxyMapper extends QBMapper {
/**
* @param string $ownerId The userId that has the resulting proxies for their calendars
+ *
+ * @return Proxy[]
*/
public function getProxiesOf(string $ownerId): array {
$qb = $this->db->getQueryBuilder();