[Pkg-owncloud-commits] [php-sabredav] 03/275: Moved scheduling properties to the scheduling plugin.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:55:44 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 0841435ea3da9dc2661931e201341180976b41d6
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Fri Aug 16 18:58:16 2013 +0100
Moved scheduling properties to the scheduling plugin.
---
lib/Sabre/CalDAV/Plugin.php | 29 --------
lib/Sabre/CalDAV/Schedule/Plugin.php | 81 ++++++++++++++++++++++
tests/Sabre/CalDAV/PluginTest.php | 13 ----
.../Sabre/CalDAV/Schedule/PluginPropertiesTest.php | 43 ++++++++++++
.../CalDAV/UserCalendarsSharedCalendarsTest.php | 2 +-
.../CalDAV/UserCalendarsSubscriptionsTest.php | 4 +-
6 files changed, 127 insertions(+), 45 deletions(-)
diff --git a/lib/Sabre/CalDAV/Plugin.php b/lib/Sabre/CalDAV/Plugin.php
index 58f2182..dd0e720 100644
--- a/lib/Sabre/CalDAV/Plugin.php
+++ b/lib/Sabre/CalDAV/Plugin.php
@@ -193,12 +193,6 @@ class Plugin extends DAV\ServerPlugin {
'{' . self::NS_CALDAV . '}supported-collation-set',
'{' . self::NS_CALDAV . '}calendar-data',
- // scheduling extension
- '{' . self::NS_CALDAV . '}schedule-inbox-URL',
- '{' . self::NS_CALDAV . '}schedule-outbox-URL',
- '{' . self::NS_CALDAV . '}calendar-user-address-set',
- '{' . self::NS_CALDAV . '}calendar-user-type',
-
// CalendarServer extensions
'{' . self::NS_CALENDARSERVER . '}getctag',
'{' . self::NS_CALENDARSERVER . '}calendar-proxy-read-for',
@@ -314,29 +308,6 @@ class Plugin extends DAV\ServerPlugin {
}
- // schedule-outbox-URL property
- $scheduleProp = '{' . self::NS_CALDAV . '}schedule-outbox-URL';
- if (in_array($scheduleProp,$requestedProperties)) {
-
- $calendarHomePath = $this->getCalendarHomeForPrincipal($principalUrl);
- $outboxPath = $calendarHomePath . '/outbox';
-
- unset($requestedProperties[array_search($scheduleProp, $requestedProperties)]);
- $returnedProperties[200][$scheduleProp] = new DAV\Property\Href($outboxPath);
-
- }
-
- // calendar-user-address-set property
- $calProp = '{' . self::NS_CALDAV . '}calendar-user-address-set';
- if (in_array($calProp,$requestedProperties)) {
-
- $addresses = $node->getAlternateUriSet();
- $addresses[] = $this->server->getBaseUri() . $node->getPrincipalUrl() . '/';
- unset($requestedProperties[array_search($calProp, $requestedProperties)]);
- $returnedProperties[200][$calProp] = new DAV\Property\HrefList($addresses, false);
-
- }
-
// These two properties are shortcuts for ical to easily find
// other principals this principal has access to.
$propRead = '{' . self::NS_CALENDARSERVER . '}calendar-proxy-read-for';
diff --git a/lib/Sabre/CalDAV/Schedule/Plugin.php b/lib/Sabre/CalDAV/Schedule/Plugin.php
index 611e5cf..59b564d 100644
--- a/lib/Sabre/CalDAV/Schedule/Plugin.php
+++ b/lib/Sabre/CalDAV/Schedule/Plugin.php
@@ -5,9 +5,12 @@ namespace Sabre\CalDAV\Schedule;
use
Sabre\DAV\Server,
Sabre\DAV\ServerPlugin,
+ Sabre\DAV\Property\Href,
+ Sabre\DAV\Property\HrefList,
Sabre\HTTP\RequestInterface,
Sabre\HTTP\ResponseInterface,
Sabre\VObject,
+ Sabre\DAVACL,
Sabre\CalDAV\ICalendar,
Sabre\DAV\Exception\NotFound,
Sabre\DAV\Exception\Forbidden,
@@ -100,10 +103,25 @@ class Plugin extends ServerPlugin {
$this->server = $server;
$server->on('method:POST', [$this,'httpPost']);
+ $server->on('beforeGetProperties', [$this,'beforeGetProperties']);
+ /**
+ * This information ensures that the {DAV:}resourcetype property has
+ * the correct values.
+ */
$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IOutbox'] = '{urn:ietf:params:xml:ns:caldav}schedule-outbox';
$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IInbox'] = '{urn:ietf:params:xml:ns:caldav}schedule-inbox';
+ /**
+ * Properties we protect are made read-only by the server.
+ */
+ array_push($server->protectedProperties,
+ '{' . self::NS_CALDAV . '}schedule-inbox-URL',
+ '{' . self::NS_CALDAV . '}schedule-outbox-URL',
+ '{' . self::NS_CALDAV . '}calendar-user-address-set',
+ '{' . self::NS_CALDAV . '}calendar-user-type'
+ );
+
}
/**
@@ -167,6 +185,69 @@ class Plugin extends ServerPlugin {
}
+
+ /**
+ * beforeGetProperties
+ *
+ * This method handler is invoked before any after properties for a
+ * resource are fetched. This allows us to add in any CalDAV specific
+ * properties.
+ *
+ * @param string $path
+ * @param \Sabre\DAV\INode $node
+ * @param array $requestedProperties
+ * @param array $returnedProperties
+ * @return void
+ */
+ public function beforeGetProperties($path, \Sabre\DAV\INode $node, &$requestedProperties, &$returnedProperties) {
+
+ $caldavPlugin = $this->server->getPlugin('caldav');
+
+ if ($node instanceof DAVACL\IPrincipal) {
+
+ $principalUrl = $node->getPrincipalUrl();
+
+ // schedule-outbox-URL property
+ $scheduleProp = '{' . self::NS_CALDAV . '}schedule-outbox-URL';
+ if (in_array($scheduleProp,$requestedProperties)) {
+
+ $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+ $outboxPath = $calendarHomePath . '/outbox';
+
+ unset($requestedProperties[array_search($scheduleProp, $requestedProperties)]);
+ $returnedProperties[200][$scheduleProp] = new Href($outboxPath);
+
+ }
+
+ // schedule-inbox-URL property
+ $scheduleProp = '{' . self::NS_CALDAV . '}schedule-inbox-URL';
+ if (in_array($scheduleProp,$requestedProperties)) {
+
+ $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
+ $inboxPath = $calendarHomePath . '/inbox';
+
+ unset($requestedProperties[array_search($scheduleProp, $requestedProperties)]);
+ $returnedProperties[200][$scheduleProp] = new Href($inboxPath);
+
+ }
+
+
+ // calendar-user-address-set property
+ $calProp = '{' . self::NS_CALDAV . '}calendar-user-address-set';
+ if (in_array($calProp,$requestedProperties)) {
+
+ $addresses = $node->getAlternateUriSet();
+ $addresses[] = $this->server->getBaseUri() . $node->getPrincipalUrl() . '/';
+ unset($requestedProperties[array_search($calProp, $requestedProperties)]);
+ $returnedProperties[200][$calProp] = new HrefList($addresses, false);
+
+ }
+
+ } // instanceof IPrincipal
+
+ }
+
+
/**
* This method handles POST requests to the schedule-outbox.
*
diff --git a/tests/Sabre/CalDAV/PluginTest.php b/tests/Sabre/CalDAV/PluginTest.php
index 454bb66..6ff2719 100644
--- a/tests/Sabre/CalDAV/PluginTest.php
+++ b/tests/Sabre/CalDAV/PluginTest.php
@@ -435,8 +435,6 @@ END:VCALENDAR';
$props = $this->server->getPropertiesForPath('/principals/user1',array(
'{urn:ietf:params:xml:ns:caldav}calendar-home-set',
- '{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
- '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
'{' . Plugin::NS_CALENDARSERVER . '}calendar-proxy-read-for',
'{' . Plugin::NS_CALENDARSERVER . '}calendar-proxy-write-for',
'{' . Plugin::NS_CALENDARSERVER . '}notification-URL',
@@ -451,21 +449,10 @@ END:VCALENDAR';
$this->assertTrue($prop instanceof DAV\Property\Href);
$this->assertEquals('calendars/user1/',$prop->getHref());
- $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',$props[0][200]);
- $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL'];
- $this->assertTrue($prop instanceof DAV\Property\Href);
- $this->assertEquals('calendars/user1/outbox',$prop->getHref());
-
$this->assertArrayHasKey('{'.Plugin::NS_CALENDARSERVER .'}notification-URL',$props[0][200]);
$prop = $props[0][200]['{'.Plugin::NS_CALENDARSERVER .'}notification-URL'];
$this->assertTrue($prop instanceof DAV\Property\Href);
- $this->assertEquals('calendars/user1/notifications/',$prop->getHref());
-
- $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',$props[0][200]);
- $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
- $this->assertTrue($prop instanceof DAV\Property\HrefList);
- $this->assertEquals(array('mailto:user1.sabredav at sabredav.org','/principals/user1/'),$prop->getHrefs());
$this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-read-for', $props[0][200]);
$prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-read-for'];
diff --git a/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
new file mode 100644
index 0000000..eb8aa45
--- /dev/null
+++ b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Sabre\CalDAV\Schedule;
+
+use Sabre\DAVACL;
+use Sabre\DAV;
+use Sabre\HTTP;
+
+class PluginPropertiesTest extends \Sabre\DAVServerTest {
+
+ protected $setupCalDAV = true;
+ protected $setupCalDAVScheduling = true;
+
+ function testPrincipalProperties() {
+
+ $props = $this->server->getPropertiesForPath('/principals/user1',array(
+ '{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',
+ '{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
+ '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
+ ));
+
+ $this->assertArrayHasKey(0,$props);
+ $this->assertArrayHasKey(200,$props[0]);
+
+ $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',$props[0][200]);
+ $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL'];
+ $this->assertTrue($prop instanceof DAV\Property\Href);
+ $this->assertEquals('calendars/user1/outbox',$prop->getHref());
+
+ $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',$props[0][200]);
+ $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL'];
+ $this->assertTrue($prop instanceof DAV\Property\Href);
+ $this->assertEquals('calendars/user1/inbox',$prop->getHref());
+
+
+ $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',$props[0][200]);
+ $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
+ $this->assertTrue($prop instanceof DAV\Property\HrefList);
+ $this->assertEquals(array('mailto:user1.sabredav at sabredav.org','/principals/user1/'),$prop->getHrefs());
+
+ }
+
+}
diff --git a/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php b/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php
index 1f20be4..7e76ad2 100644
--- a/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php
+++ b/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php
@@ -52,7 +52,7 @@ class UserCalendarsSharedCalendarsTest extends \PHPUnit_Framework_TestCase {
$instance = $this->getInstance();
$children = $instance->getChildren();
- $this->assertEquals(4, count($children));
+ $this->assertEquals(5, count($children));
// Testing if we got all the objects back.
$hasShareable = false;
diff --git a/tests/Sabre/CalDAV/UserCalendarsSubscriptionsTest.php b/tests/Sabre/CalDAV/UserCalendarsSubscriptionsTest.php
index 77e63b8..6ccd5de 100644
--- a/tests/Sabre/CalDAV/UserCalendarsSubscriptionsTest.php
+++ b/tests/Sabre/CalDAV/UserCalendarsSubscriptionsTest.php
@@ -35,7 +35,7 @@ class UserCalendarsSubscriptionsTest extends \PHPUnit_Framework_TestCase {
$instance = $this->getInstance();
$children = $instance->getChildren();
- $this->assertEquals(3, count($children));
+ $this->assertEquals(4, count($children));
foreach($children as $child) {
if ($child instanceof Subscriptions\Subscription) {
return;
@@ -57,7 +57,7 @@ class UserCalendarsSubscriptionsTest extends \PHPUnit_Framework_TestCase {
$instance->createExtendedCollection('sub2', $rt, $props);
$children = $instance->getChildren();
- $this->assertEquals(4, count($children));
+ $this->assertEquals(5, count($children));
}
--
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