diff options
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/caldav/caldavbackend.php | 87 | ||||
-rw-r--r-- | apps/dav/lib/caldav/calendar.php | 97 | ||||
-rw-r--r-- | apps/dav/lib/caldav/calendarhome.php | 78 | ||||
-rw-r--r-- | apps/dav/lib/caldav/calendarroot.php | 10 | ||||
-rw-r--r-- | apps/dav/lib/carddav/carddavbackend.php | 18 | ||||
-rw-r--r-- | apps/dav/lib/rootcollection.php | 4 |
6 files changed, 274 insertions, 20 deletions
diff --git a/apps/dav/lib/caldav/caldavbackend.php b/apps/dav/lib/caldav/caldavbackend.php index 0b70b37967f..48fc1fe3b08 100644 --- a/apps/dav/lib/caldav/caldavbackend.php +++ b/apps/dav/lib/caldav/caldavbackend.php @@ -23,6 +23,8 @@ namespace OCA\DAV\CalDAV; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCA\DAV\Connector\Sabre\Principal; +use OCA\DAV\DAV\Sharing\Backend; use Sabre\CalDAV\Backend\AbstractBackend; use Sabre\CalDAV\Backend\SchedulingSupport; use Sabre\CalDAV\Backend\SubscriptionSupport; @@ -32,6 +34,7 @@ use Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; use Sabre\DAV; use Sabre\DAV\Exception\Forbidden; +use Sabre\HTTP\URLUtil; use Sabre\VObject\DateTimeParser; use Sabre\VObject\Reader; use Sabre\VObject\RecurrenceIterator; @@ -86,8 +89,24 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', ]; - public function __construct(\OCP\IDBConnection $db) { + /** @var \OCP\IDBConnection */ + private $db; + + /** @var Backend */ + private $sharingBackend; + + /** @var Principal */ + private $principalBackend; + + /** + * CalDavBackend constructor. + * + * @param \OCP\IDBConnection $db + */ + public function __construct(\OCP\IDBConnection $db, Principal $principalBackend) { $this->db = $db; + $this->principalBackend = $principalBackend; + $this->sharingBackend = new Backend($this->db, 'calendar'); } /** @@ -156,6 +175,59 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $calendars[] = $calendar; } + $stmt->closeCursor(); + + // query for shared calendars + $principals = $this->principalBackend->getGroupMembership($principalUri); + $principals[]= $principalUri; + + $fields = array_values($this->propertyMap); + $fields[] = 'a.id'; + $fields[] = 'a.uri'; + $fields[] = 'a.synctoken'; + $fields[] = 'a.components'; + $fields[] = 'a.principaluri'; + $fields[] = 'a.transparent'; + $fields[] = 's.access'; + $query = $this->db->getQueryBuilder(); + $result = $query->select($fields) + ->from('dav_shares', 's') + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) + ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) + ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) + ->setParameter('type', 'calendar') + ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) + ->execute(); + + while($row = $result->fetch()) { + list(, $name) = URLUtil::splitPath($row['principaluri']); + $uri = $row['uri'] . '_shared_by_' . $name; + $row['displayname'] = $row['displayname'] . "($name)"; + $components = []; + if ($row['components']) { + $components = explode(',',$row['components']); + } + $calendar = [ + 'id' => $row['id'], + 'uri' => $uri, + 'principaluri' => $principalUri, + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'], + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $row['access'] === Backend::ACCESS_READ, + ]; + + foreach($this->propertyMap as $xmlName=>$dbName) { + $calendar[$xmlName] = $row[$dbName]; + } + + $calendars[]= $calendar; + } + $result->closeCursor(); + + return $calendars; } @@ -1173,4 +1245,17 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return $cardData; } + + public function updateShares($shareable, $add, $remove) { + $this->sharingBackend->updateShares($shareable, $add, $remove); + } + + public function getShares($resourceId) { + return $this->sharingBackend->getShares($resourceId); + } + + public function applyShareAcl($addressBookId, $acl) { + return $this->sharingBackend->applyShareAcl($addressBookId, $acl); + } + } diff --git a/apps/dav/lib/caldav/calendar.php b/apps/dav/lib/caldav/calendar.php new file mode 100644 index 00000000000..b4a47418350 --- /dev/null +++ b/apps/dav/lib/caldav/calendar.php @@ -0,0 +1,97 @@ +<?php + +namespace OCA\DAV\CalDAV; + +use OCA\DAV\DAV\Sharing\IShareable; + +class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { + + /** + * Updates the list of shares. + * + * The first array is a list of people that are to be added to the + * resource. + * + * Every element in the add array has the following properties: + * * href - A url. Usually a mailto: address + * * commonName - Usually a first and last name, or false + * * summary - A description of the share, can also be false + * * readOnly - A boolean value + * + * Every element in the remove array is just the address string. + * + * @param array $add + * @param array $remove + * @return void + */ + function updateShares(array $add, array $remove) { + /** @var CalDavBackend $calDavBackend */ + $calDavBackend = $this->caldavBackend; + $calDavBackend->updateShares($this, $add, $remove); + } + + /** + * Returns the list of people whom this resource is shared with. + * + * Every element in this array should have the following properties: + * * href - Often a mailto: address + * * commonName - Optional, for example a first + last name + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. + * * readOnly - boolean + * * summary - Optional, a description for the share + * + * @return array + */ + function getShares() { + /** @var CalDavBackend $caldavBackend */ + $caldavBackend = $this->caldavBackend; + return $caldavBackend->getShares($this->getResourceId()); + } + + /** + * @return int + */ + public function getResourceId() { + return $this->calendarInfo['id']; + } + + function getACL() { + $acl = parent::getACL(); + + // add the current user + if (isset($this->calendarInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'])) { + $owner = $this->calendarInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal']; + $acl[] = [ + 'privilege' => '{DAV:}read', + 'principal' => $owner, + 'protected' => true, + ]; + if ($this->calendarInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only']) { + $acl[] = [ + 'privilege' => '{DAV:}write', + 'principal' => $owner, + 'protected' => true, + ]; + } + } + + /** @var CalDavBackend $caldavBackend */ + $caldavBackend = $this->caldavBackend; + return $caldavBackend->applyShareAcl($this->getResourceId(), $acl); + } + + function getChildACL() { + $acl = parent::getChildACL(); + + /** @var CalDavBackend $caldavBackend */ + $caldavBackend = $this->caldavBackend; + return $caldavBackend->applyShareAcl($this->getResourceId(), $acl); + } + + function getOwner() { + if (isset($this->calendarInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'])) { + return $this->calendarInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal']; + } + return parent::getOwner(); + } +} diff --git a/apps/dav/lib/caldav/calendarhome.php b/apps/dav/lib/caldav/calendarhome.php new file mode 100644 index 00000000000..7f98dfb94e0 --- /dev/null +++ b/apps/dav/lib/caldav/calendarhome.php @@ -0,0 +1,78 @@ +<?php + +namespace OCA\DAV\CalDAV; + +use Sabre\CalDAV\Backend\NotificationSupport; +use Sabre\CalDAV\Backend\SchedulingSupport; +use Sabre\CalDAV\Backend\SubscriptionSupport; +use Sabre\CalDAV\Schedule\Inbox; +use Sabre\CalDAV\Schedule\Outbox; +use Sabre\CalDAV\Subscriptions\Subscription; +use Sabre\DAV\Exception\NotFound; + +class CalendarHome extends \Sabre\CalDAV\CalendarHome { + + /** + * @inheritdoc + */ + function getChildren() { + $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); + $objs = []; + foreach ($calendars as $calendar) { + $objs[] = new Calendar($this->caldavBackend, $calendar); + } + + if ($this->caldavBackend instanceof SchedulingSupport) { + $objs[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); + $objs[] = new Outbox($this->principalInfo['uri']); + } + + // We're adding a notifications node, if it's supported by the backend. + if ($this->caldavBackend instanceof NotificationSupport) { + $objs[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); + } + + // If the backend supports subscriptions, we'll add those as well, + if ($this->caldavBackend instanceof SubscriptionSupport) { + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { + $objs[] = new Subscription($this->caldavBackend, $subscription); + } + } + + return $objs; + } + + /** + * @inheritdoc + */ + function getChild($name) { + // Special nodes + if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { + return new Inbox($this->caldavBackend, $this->principalInfo['uri']); + } + if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { + return new Outbox($this->principalInfo['uri']); + } + if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { + return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); + } + + // Calendars + foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { + if ($calendar['uri'] === $name) { + return new Calendar($this->caldavBackend, $calendar); + } + } + + if ($this->caldavBackend instanceof SubscriptionSupport) { + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { + if ($subscription['uri'] === $name) { + return new Subscription($this->caldavBackend, $subscription); + } + } + + } + + throw new NotFound('Node with name \'' . $name . '\' could not be found'); + } +}
\ No newline at end of file diff --git a/apps/dav/lib/caldav/calendarroot.php b/apps/dav/lib/caldav/calendarroot.php new file mode 100644 index 00000000000..ae5fc54cdf3 --- /dev/null +++ b/apps/dav/lib/caldav/calendarroot.php @@ -0,0 +1,10 @@ +<?php + +namespace OCA\DAV\CalDAV; + +class CalendarRoot extends \Sabre\CalDAV\CalendarRoot { + + function getChildForPrincipal(array $principal) { + return new CalendarHome($this->caldavBackend, $principal); + } +}
\ No newline at end of file diff --git a/apps/dav/lib/carddav/carddavbackend.php b/apps/dav/lib/carddav/carddavbackend.php index 3dc5c00e10b..025d46ecdee 100644 --- a/apps/dav/lib/carddav/carddavbackend.php +++ b/apps/dav/lib/carddav/carddavbackend.php @@ -920,22 +920,6 @@ class CardDavBackend implements BackendInterface, SyncSupport { * @return array */ public function applyShareAcl($addressBookId, $acl) { - - $shares = $this->getShares($addressBookId); - foreach ($shares as $share) { - $acl[] = [ - 'privilege' => '{DAV:}read', - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], - 'protected' => true, - ]; - if (!$share['readOnly']) { - $acl[] = [ - 'privilege' => '{DAV:}write', - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], - 'protected' => true, - ]; - } - } - return $acl; + return $this->sharingBackend->applyShareAcl($addressBookId, $acl); } } diff --git a/apps/dav/lib/rootcollection.php b/apps/dav/lib/rootcollection.php index 5be469e7b0c..2a8f63a2270 100644 --- a/apps/dav/lib/rootcollection.php +++ b/apps/dav/lib/rootcollection.php @@ -22,12 +22,12 @@ namespace OCA\DAV; use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\CalDAV\CalendarRoot; use OCA\DAV\CardDAV\AddressBookRoot; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\GroupPrincipalBackend; use OCA\DAV\DAV\SystemPrincipalBackend; -use Sabre\CalDAV\CalendarRoot; use Sabre\CalDAV\Principal\Collection; use Sabre\DAV\SimpleCollection; @@ -55,7 +55,7 @@ class RootCollection extends SimpleCollection { $systemPrincipals->disableListing = $disableListing; $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $filesCollection->disableListing = $disableListing; - $caldavBackend = new CalDavBackend($db); + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend); $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); $calendarRoot->disableListing = $disableListing; |