[Pkg-owncloud-commits] [php-sabredav] 13/42: calendar-timezone support in free-busy-query REPORT

David Prévot taffit at moszumanska.debian.org
Fri Nov 28 22:47:48 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 0b3bcf7a6dd116b3b997736acd8d14d444bc0744
Author: Evert Pot <me at evertpot.com>
Date:   Thu Nov 13 20:14:34 2014 -0500

    calendar-timezone support in free-busy-query REPORT
---
 lib/CalDAV/Plugin.php                     | 23 ++++++++++++++++++-----
 tests/Sabre/CalDAV/FreeBusyReportTest.php | 29 +++++++++++++++++++++++------
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php
index 78f3a9b..fc01f31 100644
--- a/lib/CalDAV/Plugin.php
+++ b/lib/CalDAV/Plugin.php
@@ -684,22 +684,34 @@ class Plugin extends DAV\ServerPlugin {
             $end = VObject\DateTimeParser::parseDateTime($end);
         }
 
+        $uri = $this->server->getRequestUri();
         if (!$start && !$end) {
             throw new DAV\Exception\BadRequest('The freebusy report must have a time-range filter');
         }
-        $acl = $this->server->getPlugin('acl');
 
-        if (!$acl) {
-            throw new DAV\Exception('The ACL plugin must be loaded for free-busy queries to work');
+        $acl = $this->server->getPlugin('acl');
+        if ($acl) {
+            $acl->checkPrivileges($uri,'{' . self::NS_CALDAV . '}read-free-busy');
         }
-        $uri = $this->server->getRequestUri();
-        $acl->checkPrivileges($uri,'{' . self::NS_CALDAV . '}read-free-busy');
 
         $calendar = $this->server->tree->getNodeForPath($uri);
         if (!$calendar instanceof ICalendar) {
             throw new DAV\Exception\NotImplemented('The free-busy-query REPORT is only implemented on calendars');
         }
 
+        $tzProp = '{' . self::NS_CALDAV . '}calendar-timezone';
+
+        // Figuring out the default timezone for the calendar, for floating
+        // times.
+        $calendarProps = $this->server->getProperties($uri, [$tzProp]);
+
+        if (isset($calendarProps[$tzProp])) {
+            $vtimezoneObj = VObject\Reader::read($calendarProps[$tzProp]);
+            $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
+        } else {
+            $calendarTimeZone = new DateTimeZone('UTC');
+        }
+
         // Doing a calendar-query first, to make sure we get the most
         // performance.
         $urls = $calendar->calendarQuery([
@@ -729,6 +741,7 @@ class Plugin extends DAV\ServerPlugin {
         $generator = new VObject\FreeBusyGenerator();
         $generator->setObjects($objects);
         $generator->setTimeRange($start, $end);
+        $generator->setTimeZone($calendarTimeZone);
         $result = $generator->getResult();
         $result = $result->serialize();
 
diff --git a/tests/Sabre/CalDAV/FreeBusyReportTest.php b/tests/Sabre/CalDAV/FreeBusyReportTest.php
index 80b6027..04a5031 100644
--- a/tests/Sabre/CalDAV/FreeBusyReportTest.php
+++ b/tests/Sabre/CalDAV/FreeBusyReportTest.php
@@ -30,6 +30,7 @@ DURATION:PT1H
 END:VEVENT
 END:VCALENDAR
 ics;
+
         $obj2 = fopen('php://memory','r+');
         fwrite($obj2,<<<ics
 BEGIN:VCALENDAR
@@ -42,28 +43,43 @@ ics
         );
         rewind($obj2);
 
+        $obj3 = <<<ics
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+DTSTART:20111006T120000
+DURATION:PT1H
+END:VEVENT
+END:VCALENDAR
+ics;
+
         $calendarData = [
-            1 => [ 
+            1 => [
                 'obj1' => [
                     'calendarid' => 1,
                     'uri' => 'event1.ics',
                     'calendardata' => $obj1,
                 ],
-                'obj2' => [ 
+                'obj2' => [
                     'calendarid' => 1,
                     'uri' => 'event2.ics',
                     'calendardata' => $obj2
-                ] 
+                ],
+                'obj3' => [
+                    'calendarid' => 1,
+                    'uri' => 'event3.ics',
+                    'calendardata' => $obj3
+                ]
             ],
         ];
 
 
         $caldavBackend = new Backend\Mock([], $calendarData);
 
-        $calendar = new Calendar($caldavBackend, [ 
+        $calendar = new Calendar($caldavBackend, [
             'id' => 1,
             'uri' => 'calendar',
             'principaluri' => 'principals/user1',
+            '{' . Plugin::NS_CALDAV . '}calendar-timezone' => "BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nEND:VTIMEZONE\r\nEND:VCALENDAR",
         ]);
 
         $this->server = new DAV\Server([$calendar]);
@@ -76,7 +92,6 @@ ics
 
         $this->plugin = new Plugin();
         $this->server->addPlugin($this->plugin);
-        $this->server->addPlugin(new DAVACL\Plugin());
 
     }
 
@@ -94,7 +109,9 @@ XML;
 
         $this->assertEquals(200, $this->server->httpResponse->status);
         $this->assertEquals('text/calendar', $this->server->httpResponse->getHeader('Content-Type'));
-        $this->assertTrue(strpos($this->server->httpResponse->body,'BEGIN:VFREEBUSY')!==false);
+        $this->assertTrue(strpos($this->server->httpResponse->body, 'BEGIN:VFREEBUSY')!==false);
+        $this->assertTrue(strpos($this->server->httpResponse->body, '20111005T120000Z/20111005T130000Z')!==false);
+        $this->assertTrue(strpos($this->server->httpResponse->body, '20111006T100000Z/20111006T110000Z')!==false);
 
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list