]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add calendar sharing
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 26 Jan 2016 11:06:02 +0000 (12:06 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Wed, 3 Feb 2016 16:18:22 +0000 (17:18 +0100)
20 files changed:
apps/dav/appinfo/register_command.php
apps/dav/command/createcalendar.php
apps/dav/lib/caldav/caldavbackend.php
apps/dav/lib/caldav/calendar.php [new file with mode: 0644]
apps/dav/lib/caldav/calendarhome.php [new file with mode: 0644]
apps/dav/lib/caldav/calendarroot.php [new file with mode: 0644]
apps/dav/lib/carddav/carddavbackend.php
apps/dav/lib/rootcollection.php
apps/dav/tests/travis/caldav/install.sh
apps/dav/tests/travis/caldav/script.sh
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/1.xml [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/4.xml [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.ics [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.xml [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/6.ics [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/7.ics [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/8.ics [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/9.ics [new file with mode: 0644]
apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml
apps/dav/tests/unit/caldav/caldavbackendtest.php

index e8fea5daf23740dd2388861077e976f3b61067c9..e8ca370f84f4bb958ed1ce8a66ec82b696c64b67 100644 (file)
@@ -36,7 +36,7 @@ $app = new Application();
 
 /** @var Symfony\Component\Console\Application $application */
 $application->add(new CreateAddressBook($userManager, $groupManager, $dbConnection, $logger));
-$application->add(new CreateCalendar($userManager, $dbConnection));
+$application->add(new CreateCalendar($userManager, $groupManager, $dbConnection));
 $application->add(new SyncSystemAddressBook($app->getSyncService()));
 
 // the occ tool is *for now* only available in debug mode for developers to test
index 34bc061c45b464f69d248bbe01078b8267a9ea76..d7f82dd0e524fa573d498905a3ef7c241a94987c 100644 (file)
@@ -21,7 +21,9 @@
 namespace OCA\DAV\Command;
 
 use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\Connector\Sabre\Principal;
 use OCP\IDBConnection;
+use OCP\IGroupManager;
 use OCP\IUserManager;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputArgument;
@@ -33,6 +35,9 @@ class CreateCalendar extends Command {
        /** @var IUserManager */
        protected $userManager;
 
+       /** @var IGroupManager $groupManager */
+       private $groupManager;
+
        /** @var \OCP\IDBConnection */
        protected $dbConnection;
 
@@ -40,9 +45,10 @@ class CreateCalendar extends Command {
         * @param IUserManager $userManager
         * @param IDBConnection $dbConnection
         */
-       function __construct(IUserManager $userManager, IDBConnection $dbConnection) {
+       function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
                parent::__construct();
                $this->userManager = $userManager;
+               $this->groupManager = $groupManager;
                $this->dbConnection = $dbConnection;
        }
 
@@ -63,8 +69,13 @@ class CreateCalendar extends Command {
                if (!$this->userManager->userExists($user)) {
                        throw new \InvalidArgumentException("User <$user> in unknown.");
                }
+               $principalBackend = new Principal(
+                       $this->userManager,
+                       $this->groupManager
+               );
+
                $name = $input->getArgument('name');
-               $caldav = new CalDavBackend($this->dbConnection);
+               $caldav = new CalDavBackend($this->dbConnection, $principalBackend);
                $caldav->createCalendar("principals/users/$user", $name, []);
        }
 }
index 0b70b37967f2402eaf6159929ba71ca5a54e3bfa..48fc1fe3b080166626a41d2abaf4f94573c10cae 100644 (file)
@@ -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 (file)
index 0000000..b4a4741
--- /dev/null
@@ -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 (file)
index 0000000..7f98dfb
--- /dev/null
@@ -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 (file)
index 0000000..ae5fc54
--- /dev/null
@@ -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
index 3dc5c00e10b9652be9171be55356805266899737..025d46ecdeeb4dac0311cba275c6e3c322e2035d 100644 (file)
@@ -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);
        }
 }
index 5be469e7b0c6aaa399b4005d57c004c436b7c8ed..2a8f63a22703ea9e8a9807344cf2521814ee0624 100644 (file)
 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;
 
index e836e37f86f77ebf68db30cf71f09d7bbdcd5a14..9688ec660de1ec939c211cc4ac62512a1c3837ea 100644 (file)
@@ -15,6 +15,7 @@ fi
 cd "$SCRIPTPATH/../../../../../"
 OC_PASS=user01 php occ user:add --password-from-env user01
 php occ dav:create-calendar user01 calendar
+php occ dav:create-calendar user01 shared
 OC_PASS=user02 php occ user:add --password-from-env user02
 php occ dav:create-calendar user02 calendar
 cd "$SCRIPTPATH/../../../../../"
index fe3391d5a06a60240dc4a1a0dc5c3247e4c58109..7259372567cd0c5e8df875ed57405c461fa7204b 100644 (file)
@@ -11,8 +11,8 @@ sleep 30
 cd "$SCRIPTPATH/CalDAVTester"
 PYTHONPATH="$SCRIPTPATH/pycalendar/src" python testcaldav.py --print-details-onfail --basedir "$SCRIPTPATH/../caldavtest/" -o cdt.txt \
        "CalDAV/current-user-principal.xml" \
-       "CalDAV/sync-report.xml"
-
+       "CalDAV/sync-report.xml" \
+       "CalDAV/sharing-calendars.xml"
 
 RESULT=$?
 
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/1.xml b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/1.xml
new file mode 100644 (file)
index 0000000..3bcf9dc
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<CS:share xmlns:D="DAV:" xmlns:CS="http://owncloud.org/ns">
+       <CS:set>
+               <D:href>principal:principals/users/user02</D:href>
+               <CS:summary>My Shared Calendar</CS:summary>
+               <CS:read-write/>
+       </CS:set>
+</CS:share>
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/4.xml b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/4.xml
new file mode 100644 (file)
index 0000000..fd0f248
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<D:propfind xmlns:D="DAV:">
+<D:prop>
+<D:resourcetype/>
+<D:owner/>
+<D:current-user-privilege-set/>
+</D:prop>
+</D:propfind>
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.ics b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.ics
new file mode 100644 (file)
index 0000000..ae21ada
--- /dev/null
@@ -0,0 +1,29 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:US/Eastern
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:$uid1:
+DTSTART;TZID=US/Eastern:$now.year.1:0101T100000
+DURATION:PT1H
+DTSTAMP:20051222T205953Z
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.xml b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.xml
new file mode 100644 (file)
index 0000000..e52a842
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<D:propfind xmlns:D="DAV:" xmlns:CS="http://calendarserver.org/ns/">
+<D:prop>
+<CS:invite/>
+</D:prop>
+</D:propfind>
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/6.ics b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/6.ics
new file mode 100644 (file)
index 0000000..145f5f1
--- /dev/null
@@ -0,0 +1,29 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:US/Eastern
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:$uid1:
+DTSTART;TZID=US/Eastern:$now.year.1:0101T100000
+DURATION:PT4H
+DTSTAMP:20051222T205953Z
+SUMMARY:event 4
+END:VEVENT
+END:VCALENDAR
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/7.ics b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/7.ics
new file mode 100644 (file)
index 0000000..c4e8162
--- /dev/null
@@ -0,0 +1,29 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:US/Eastern
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:$uid2:
+DTSTART;TZID=US/Eastern:$now.year.1:0201T100000
+DURATION:PT1H
+DTSTAMP:20051222T205953Z
+SUMMARY:event 7
+END:VEVENT
+END:VCALENDAR
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/8.ics b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/8.ics
new file mode 100644 (file)
index 0000000..2da72d2
--- /dev/null
@@ -0,0 +1,29 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:US/Eastern
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:$uid2:
+DTSTART;TZID=US/Eastern:$now.year.1:0201T100000
+DURATION:PT7H
+DTSTAMP:20051222T205953Z
+SUMMARY:event 7-1
+END:VEVENT
+END:VCALENDAR
diff --git a/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/9.ics b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/9.ics
new file mode 100644 (file)
index 0000000..dfc21bb
--- /dev/null
@@ -0,0 +1,29 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PYVOBJECT//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:US/Eastern
+LAST-MODIFIED:20040110T032845Z
+BEGIN:STANDARD
+DTSTART:20001026T020000
+RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
+TZNAME:EST
+TZOFFSETFROM:-0400
+TZOFFSETTO:-0500
+END:STANDARD
+BEGIN:DAYLIGHT
+DTSTART:20000404T020000
+RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
+TZNAME:EDT
+TZOFFSETFROM:-0500
+TZOFFSETTO:-0400
+END:DAYLIGHT
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:$uid3:
+DTSTART;TZID=US/Eastern:$now.year.1:0201T100000
+DURATION:PT7H
+DTSTAMP:20051222T205953Z
+SUMMARY:event 9.ics
+END:VEVENT
+END:VCALENDAR
index fa20a6e486252d67e37d5e9176dc1ea4998f61ba..2204ca3af6986ae22b9f2ad47c2328af9636e2ac 100644 (file)
@@ -27,6 +27,7 @@
        </require-feature>
 
        <start>
+               <!--
                <request user="$userid1:" pswd="$pswd1:">
                        <method>DELETEALL</method>
                        <ruri>$notificationpath1:/</ruri>
@@ -50,6 +51,7 @@
                                <filepath>Resource/Common/PROPPATCH/calendar-transp-opaque.xml</filepath>
                        </data>
                </request>
+               -->
        </start>
        
        <test-suite name='Read-write calendar'>
                                </verify>
                        </request>
                </test>
-               <test name='2'>
-                       <description>Check Sharee notification collection</description>
-                       <request user="$userid2:" pswd="$pswd2:">
-                               <method>WAITCOUNT 1</method>
-                               <ruri>$notificationpath2:/</ruri>
-                       </request>
-                       <request user="$userid2:" pswd="$pswd2:">
-                               <method>GETNEW</method>
-                               <ruri>$notificationpath2:/</ruri>
-                               <verify>
-                                       <callback>xmlDataMatch</callback>
-                                       <arg>
-                                               <name>filepath</name>
-                                               <value>Resource/CalDAV/sharing/calendars/read-write/2.xml</value>
-                                       </arg>
-                                       <arg>
-                                               <name>filter</name>
-                                               <value>{http://calendarserver.org/ns/}dtstamp</value>
-                                               <value>{http://calendarserver.org/ns/}uid</value>
-                                       </arg>
-                               </verify>
-                               <grabelement>
-                                       <name>{http://calendarserver.org/ns/}invite-notification/{http://calendarserver.org/ns/}uid</name>
-                                       <variable>$inviteuid:</variable>
-                               </grabelement>
-                       </request>
-               </test>
-               <test name='3'>
-                       <description>Sharee replies ACCEPTED</description>
-                       <request user="$userid2:" pswd="$pswd2:">
-                               <method>POST</method>
-                               <ruri>$calendarhome2:/</ruri>
-                               <data>
-                                       <content-type>application/xml; charset=utf-8</content-type>
-                                       <filepath>Resource/CalDAV/sharing/calendars/read-write/3.xml</filepath>
-                               </data>
-                               <verify>
-                                       <callback>statusCode</callback>
-                               </verify>
-                               <grabelement>
-                                       <name>{DAV:}href</name>
-                                       <variable>$sharedcalendar:</variable>
-                               </grabelement>
-                       </request>
-               </test>
                <test name='4'>
                        <description>Shared calendar exists</description>
                        <request user="$userid2:" pswd="$pswd2:">
                                <method>PROPFIND</method>
-                               <ruri>$sharedcalendar:/</ruri>
+                               <ruri>$calendarhome1:/shared/</ruri>
                                <header>
                                        <name>Depth</name>
                                        <value>0</value>
                                                <value>$verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>
                                                <value>$verify-property-prefix:/{DAV:}resourcetype/{DAV:}collection</value>
                                                <value>$verify-property-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:caldav}calendar</value>
-                                               <value>$verify-property-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared</value>
+                                               <!-- value>$verify-property-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared</value -->
                                                <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read</value>
                                                <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write</value>
                                                <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind</value>
                                                <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind</value>
-                                               <value>$verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent</value>
+                                               <!-- value>$verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent</value -->
                                        </arg>
                                        <arg>
                                                <name>notexists</name>
                        <description>Shared calendar exists Depth:1</description>
                        <request user="$userid2:" pswd="$pswd2:">
                                <method>PROPFIND</method>
-                               <ruri>$calendarhome2:/</ruri>
+                               <ruri>$calendarhome2:</ruri>
                                <header>
                                        <name>Depth</name>
                                        <value>1</value>
                                        <callback>xmlElementMatch</callback>
                                        <arg>
                                                <name>parent</name>
-                                               <value>$multistatus-response-prefix:[^{DAV:}href=$sharedcalendar:/]</value>
+                                               <value>$multistatus-response-prefix:[^{DAV:}href=$calendarhome2:/shared_shared_by_user01/]</value>
                                        </arg>
                                        <arg>
                                                <name>exists</name>
                                                <value>$verify-response-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>
                                                <value>$verify-response-prefix:/{DAV:}resourcetype/{DAV:}collection</value>
                                                <value>$verify-response-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:caldav}calendar</value>
-                                               <value>$verify-response-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared</value>
+                                               <!-- value>$verify-response-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared</value -->
                                                <value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read</value>
                                                <value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write</value>
                                                <value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind</value>
                                                <value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind</value>
-                                               <value>$verify-response-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent</value>
+                                               <!-- value>$verify-response-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent</value -->
                                        </arg>
                                        <arg>
                                                <name>notexists</name>
                                </verify>
                        </request>
                </test>
-               <test name='4b'>
-                       <description>Shared calendar has invite property</description>
-                       <request user="$userid2:" pswd="$pswd2:">
-                               <method>PROPFIND</method>
-                               <ruri>$sharedcalendar:/</ruri>
-                               <header>
-                                       <name>Depth</name>
-                                       <value>0</value>
-                               </header>
-                               <data>
-                                       <content-type>text/xml; charset=utf-8</content-type>
-                                       <filepath>Resource/CalDAV/sharing/calendars/read-write/5.xml</filepath>
-                               </data>
-                               <verify>
-                                       <callback>propfindItems</callback>
-                                       <arg>
-                                               <name>okprops</name>
-                                               <value>{http://calendarserver.org/ns/}invite</value>
-                                       </arg>
-                               </verify>
-                               <verify>
-                                       <callback>xmlElementMatch</callback>
-                                       <arg>
-                                               <name>exists</name>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite</value>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer</value>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer/{DAV:}href[=$principaluri1:]</value>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer/{http://calendarserver.org/ns/}common-name[=$username1:]</value>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user</value>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{DAV:}href[=$cuaddrurn2:]</value>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{http://calendarserver.org/ns/}access/{http://calendarserver.org/ns/}read-write</value>
-                                               <value>$verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{http://calendarserver.org/ns/}invite-accepted</value>
-                                       </arg>
-                               </verify>
-                       </request>
-               </test>
                <test name='5'>
                        <description>Original calendar unchanged</description>
                        <request>
                                        <arg>
                                                <name>exists</name>
                                                <value>$verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>
-                                               <value>$verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}opaque</value>
+                                               <!-- value>$verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}opaque</value -->
                                        </arg>
                                </verify>
                        </request>
                        <description>Sharee creates event</description>
                        <request user="$userid2:" pswd="$pswd2:">
                                <method>PUT</method>
-                               <ruri>$sharedcalendar:/1.ics</ruri>
+                               <ruri>$calendarhome1:/shared/1.ics</ruri>
                                <data>
                                        <content-type>text/calendar; charset=utf-8</content-type>
                                        <filepath>Resource/CalDAV/sharing/calendars/read-write/5.ics</filepath>
                        <description>Sharee sees changed event</description>
                        <request user="$userid2:" pswd="$pswd2:">
                                <method>GET</method>
-                               <ruri>$sharedcalendar:/1.ics</ruri>
+                               <ruri>$calendarhome1:/shared/1.ics</ruri>
                                <verify>
                                        <callback>calendarDataMatch</callback>
                                        <arg>
                        <description>Sharee sees new event</description>
                        <request user="$userid2:" pswd="$pswd2:">
                                <method>GET</method>
-                               <ruri>$sharedcalendar:/2.ics</ruri>
+                               <ruri>$calendarhome1:/shared/2.ics</ruri>
                                <verify>
                                        <callback>calendarDataMatch</callback>
                                        <arg>
                        <description>Sharee changes event</description>
                        <request user="$userid2:" pswd="$pswd2:">
                                <method>PUT</method>
-                               <ruri>$sharedcalendar:/2.ics</ruri>
+                               <ruri>$calendarhome1:/shared/2.ics</ruri>
                                <data>
                                        <content-type>text/calendar; charset=utf-8</content-type>
                                        <filepath>Resource/CalDAV/sharing/calendars/read-write/8.ics</filepath>
                        </request>
                </test>
        </test-suite>
-       
+
+       <!--
        <test-suite name='Default calendar cannot be shared calendar'>
                <test name='1'>
                        <description>Set property on Inbox</description>
                </test>
        </test-suite>
 
+-->
+
        <end>
+               <!--
                <request user="$useradmin:" pswd="$pswdadmin:">
                        <method>DELETEALL</method>
                        <ruri>$notificationpath1:/</ruri>
                        <ruri>$notificationpath3:/</ruri>
                        <ruri>$notificationpath4:/</ruri>
                </request>
+               -->
        </end>
        
 </caldavtest>
index 939fd36fba84d4f14543d33394ae12b6965a72d9..a4869f182894e2e5b70fb450a502d30aeda862bd 100644 (file)
@@ -23,6 +23,7 @@ namespace Tests\Connector\Sabre;
 use DateTime;
 use DateTimeZone;
 use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\Connector\Sabre\Principal;
 use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
 use Sabre\DAV\PropPatch;
 use Sabre\DAV\Xml\Property\Href;
@@ -40,14 +41,25 @@ class CalDavBackendTest extends TestCase {
        /** @var CalDavBackend */
        private $backend;
 
-       const UNIT_TEST_USER = 'caldav-unit-test';
+       /** @var Principal | \PHPUnit_Framework_MockObject_MockObject */
+       private $principal;
 
+       const UNIT_TEST_USER = 'caldav-unit-test';
 
        public function setUp() {
                parent::setUp();
 
+               $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
+                       ->disableOriginalConstructor()
+                       ->setMethods(['getPrincipalByPath'])
+                       ->getMock();
+               $this->principal->method('getPrincipalByPath')
+                       ->willReturn([
+                               'uri' => 'principals/best-friend'
+                       ]);
+
                $db = \OC::$server->getDatabaseConnection();
-               $this->backend = new CalDavBackend($db);
+               $this->backend = new CalDavBackend($db, $this->principal);
 
                $this->tearDown();
        }