summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-26 12:06:02 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-02-03 17:18:22 +0100
commit91065956080b02407625cd78796064e45a6d0236 (patch)
tree14d462ae2062ad6bc8e257167c36c0d04dd68c48 /apps
parentdfeb6ea49117654842157f66798ecea6367a7626 (diff)
downloadnextcloud-server-91065956080b02407625cd78796064e45a6d0236.tar.gz
nextcloud-server-91065956080b02407625cd78796064e45a6d0236.zip
Add calendar sharing
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/appinfo/register_command.php2
-rw-r--r--apps/dav/command/createcalendar.php15
-rw-r--r--apps/dav/lib/caldav/caldavbackend.php87
-rw-r--r--apps/dav/lib/caldav/calendar.php97
-rw-r--r--apps/dav/lib/caldav/calendarhome.php78
-rw-r--r--apps/dav/lib/caldav/calendarroot.php10
-rw-r--r--apps/dav/lib/carddav/carddavbackend.php18
-rw-r--r--apps/dav/lib/rootcollection.php4
-rw-r--r--apps/dav/tests/travis/caldav/install.sh1
-rw-r--r--apps/dav/tests/travis/caldav/script.sh4
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/1.xml8
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/4.xml8
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.ics29
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.xml6
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/6.ics29
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/7.ics29
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/8.ics29
-rw-r--r--apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/9.ics29
-rw-r--r--apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml114
-rw-r--r--apps/dav/tests/unit/caldav/caldavbackendtest.php16
20 files changed, 492 insertions, 121 deletions
diff --git a/apps/dav/appinfo/register_command.php b/apps/dav/appinfo/register_command.php
index e8fea5daf23..e8ca370f84f 100644
--- a/apps/dav/appinfo/register_command.php
+++ b/apps/dav/appinfo/register_command.php
@@ -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
diff --git a/apps/dav/command/createcalendar.php b/apps/dav/command/createcalendar.php
index 34bc061c45b..d7f82dd0e52 100644
--- a/apps/dav/command/createcalendar.php
+++ b/apps/dav/command/createcalendar.php
@@ -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, []);
}
}
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;
diff --git a/apps/dav/tests/travis/caldav/install.sh b/apps/dav/tests/travis/caldav/install.sh
index e836e37f86f..9688ec660de 100644
--- a/apps/dav/tests/travis/caldav/install.sh
+++ b/apps/dav/tests/travis/caldav/install.sh
@@ -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/../../../../../"
diff --git a/apps/dav/tests/travis/caldav/script.sh b/apps/dav/tests/travis/caldav/script.sh
index fe3391d5a06..7259372567c 100644
--- a/apps/dav/tests/travis/caldav/script.sh
+++ b/apps/dav/tests/travis/caldav/script.sh
@@ -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
index 00000000000..3bcf9dc47f9
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/1.xml
@@ -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
index 00000000000..fd0f248bb31
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/4.xml
@@ -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
index 00000000000..ae21adac8b2
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.ics
@@ -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
index 00000000000..e52a842ff66
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.xml
@@ -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
index 00000000000..145f5f14c7b
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/6.ics
@@ -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
index 00000000000..c4e816210df
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/7.ics
@@ -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
index 00000000000..2da72d2f601
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/8.ics
@@ -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
index 00000000000..dfc21bb9c5b
--- /dev/null
+++ b/apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/9.ics
@@ -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
diff --git a/apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml b/apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml
index fa20a6e4862..2204ca3af69 100644
--- a/apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml
+++ b/apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml
@@ -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'>
@@ -67,56 +69,11 @@
</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>
@@ -132,12 +89,12 @@
<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>
@@ -151,7 +108,7 @@
<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>
@@ -164,19 +121,19 @@
<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>
@@ -186,42 +143,6 @@
</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>
@@ -240,7 +161,7 @@
<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>
@@ -249,7 +170,7 @@
<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>
@@ -291,7 +212,7 @@
<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>
@@ -319,7 +240,7 @@
<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>
@@ -333,7 +254,7 @@
<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>
@@ -358,7 +279,8 @@
</request>
</test>
</test-suite>
-
+
+ <!--
<test-suite name='Default calendar cannot be shared calendar'>
<test name='1'>
<description>Set property on Inbox</description>
@@ -560,7 +482,10 @@
</test>
</test-suite>
+-->
+
<end>
+ <!--
<request user="$useradmin:" pswd="$pswdadmin:">
<method>DELETEALL</method>
<ruri>$notificationpath1:/</ruri>
@@ -568,6 +493,7 @@
<ruri>$notificationpath3:/</ruri>
<ruri>$notificationpath4:/</ruri>
</request>
+ -->
</end>
</caldavtest>
diff --git a/apps/dav/tests/unit/caldav/caldavbackendtest.php b/apps/dav/tests/unit/caldav/caldavbackendtest.php
index 939fd36fba8..a4869f18289 100644
--- a/apps/dav/tests/unit/caldav/caldavbackendtest.php
+++ b/apps/dav/tests/unit/caldav/caldavbackendtest.php
@@ -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();
}