From 91065956080b02407625cd78796064e45a6d0236 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Tue, 26 Jan 2016 12:06:02 +0100 Subject: [PATCH] Add calendar sharing --- apps/dav/appinfo/register_command.php | 2 +- apps/dav/command/createcalendar.php | 15 ++- apps/dav/lib/caldav/caldavbackend.php | 87 ++++++++++++- apps/dav/lib/caldav/calendar.php | 97 +++++++++++++++ apps/dav/lib/caldav/calendarhome.php | 78 ++++++++++++ apps/dav/lib/caldav/calendarroot.php | 10 ++ apps/dav/lib/carddav/carddavbackend.php | 18 +-- apps/dav/lib/rootcollection.php | 4 +- apps/dav/tests/travis/caldav/install.sh | 1 + apps/dav/tests/travis/caldav/script.sh | 4 +- .../CalDAV/sharing/calendars/read-write/1.xml | 8 ++ .../CalDAV/sharing/calendars/read-write/4.xml | 8 ++ .../CalDAV/sharing/calendars/read-write/5.ics | 29 +++++ .../CalDAV/sharing/calendars/read-write/5.xml | 6 + .../CalDAV/sharing/calendars/read-write/6.ics | 29 +++++ .../CalDAV/sharing/calendars/read-write/7.ics | 29 +++++ .../CalDAV/sharing/calendars/read-write/8.ics | 29 +++++ .../CalDAV/sharing/calendars/read-write/9.ics | 29 +++++ .../tests/CalDAV/sharing-calendars.xml | 114 +++--------------- .../tests/unit/caldav/caldavbackendtest.php | 16 ++- 20 files changed, 492 insertions(+), 121 deletions(-) create mode 100644 apps/dav/lib/caldav/calendar.php create mode 100644 apps/dav/lib/caldav/calendarhome.php create mode 100644 apps/dav/lib/caldav/calendarroot.php create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/1.xml create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/4.xml create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.ics create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/5.xml create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/6.ics create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/7.ics create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/8.ics create mode 100644 apps/dav/tests/travis/caldavtest/data/Resource/CalDAV/sharing/calendars/read-write/9.ics 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 @@ +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 @@ +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 @@ +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 @@ + + + + principal:principals/users/user02 + My Shared Calendar + + + 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 @@ + + + + + + + + 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 @@ + + + + + + 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 @@ + @@ -67,56 +69,11 @@ - - Check Sharee notification collection - - WAITCOUNT 1 - $notificationpath2:/ - - - GETNEW - $notificationpath2:/ - - xmlDataMatch - - filepath - Resource/CalDAV/sharing/calendars/read-write/2.xml - - - filter - {http://calendarserver.org/ns/}dtstamp - {http://calendarserver.org/ns/}uid - - - - {http://calendarserver.org/ns/}invite-notification/{http://calendarserver.org/ns/}uid - $inviteuid: - - - - - Sharee replies ACCEPTED - - POST - $calendarhome2:/ - - application/xml; charset=utf-8 - Resource/CalDAV/sharing/calendars/read-write/3.xml - - - statusCode - - - {DAV:}href - $sharedcalendar: - - - Shared calendar exists PROPFIND - $sharedcalendar:/ + $calendarhome1:/shared/
Depth 0 @@ -132,12 +89,12 @@ $verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:] $verify-property-prefix:/{DAV:}resourcetype/{DAV:}collection $verify-property-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:caldav}calendar - $verify-property-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared + $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind $verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind - $verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent + notexists @@ -151,7 +108,7 @@ Shared calendar exists Depth:1 PROPFIND - $calendarhome2:/ + $calendarhome2:
Depth 1 @@ -164,19 +121,19 @@ xmlElementMatch parent - $multistatus-response-prefix:[^{DAV:}href=$sharedcalendar:/] + $multistatus-response-prefix:[^{DAV:}href=$calendarhome2:/shared_shared_by_user01/] exists $verify-response-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:] $verify-response-prefix:/{DAV:}resourcetype/{DAV:}collection $verify-response-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:caldav}calendar - $verify-response-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared + $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind $verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind - $verify-response-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent + notexists @@ -186,42 +143,6 @@ - - Shared calendar has invite property - - PROPFIND - $sharedcalendar:/ -
- Depth - 0 -
- - text/xml; charset=utf-8 - Resource/CalDAV/sharing/calendars/read-write/5.xml - - - propfindItems - - okprops - {http://calendarserver.org/ns/}invite - - - - xmlElementMatch - - exists - $verify-property-prefix:/{http://calendarserver.org/ns/}invite - $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer - $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer/{DAV:}href[=$principaluri1:] - $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}organizer/{http://calendarserver.org/ns/}common-name[=$username1:] - $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user - $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{DAV:}href[=$cuaddrurn2:] - $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{http://calendarserver.org/ns/}access/{http://calendarserver.org/ns/}read-write - $verify-property-prefix:/{http://calendarserver.org/ns/}invite/{http://calendarserver.org/ns/}user/{http://calendarserver.org/ns/}invite-accepted - - -
-
Original calendar unchanged @@ -240,7 +161,7 @@ exists $verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:] - $verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}opaque + @@ -249,7 +170,7 @@ Sharee creates event PUT - $sharedcalendar:/1.ics + $calendarhome1:/shared/1.ics text/calendar; charset=utf-8 Resource/CalDAV/sharing/calendars/read-write/5.ics @@ -291,7 +212,7 @@ Sharee sees changed event GET - $sharedcalendar:/1.ics + $calendarhome1:/shared/1.ics calendarDataMatch @@ -319,7 +240,7 @@ Sharee sees new event GET - $sharedcalendar:/2.ics + $calendarhome1:/shared/2.ics calendarDataMatch @@ -333,7 +254,7 @@ Sharee changes event PUT - $sharedcalendar:/2.ics + $calendarhome1:/shared/2.ics text/calendar; charset=utf-8 Resource/CalDAV/sharing/calendars/read-write/8.ics @@ -358,7 +279,8 @@ - + + + + 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(); } -- 2.39.5