[Pkg-owncloud-commits] [php-sabredav] 257/275: Scheduling Plugin uses new API to find principals to deliver to.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:56:16 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 fd750e9b46f5aa5e23dec22978b815ddd9198abe
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Tue Sep 23 19:04:40 2014 +0100
Scheduling Plugin uses new API to find principals to deliver to.
---
lib/CalDAV/Schedule/Plugin.php | 36 ++++++++++++++++++----------
lib/DAVACL/Plugin.php | 27 ++++++++++++++++-----
tests/Sabre/DAVACL/PrincipalBackend/Mock.php | 5 ++--
3 files changed, 48 insertions(+), 20 deletions(-)
diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php
index e6cf494..60f2682 100644
--- a/lib/CalDAV/Schedule/Plugin.php
+++ b/lib/CalDAV/Schedule/Plugin.php
@@ -429,8 +429,22 @@ class Plugin extends ServerPlugin {
$caldavNS = '{' . Plugin::NS_CALDAV . '}';
- $result = $aclPlugin->principalSearch(
- ['{http://sabredav.org/ns}email-address' => substr($iTipMessage->recipient, 7)],
+ $principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
+ if (!$principalUri) {
+ $iTipMessage->scheduleStatus = '3.7;Could not find principal.';
+ return;
+ }
+
+ // We found a principal URL, now we need to find its inbox.
+ // Unfortunately we may not have sufficient privileges to find this, so
+ // we are temporarily turning off ACL to let this come through.
+ //
+ // Once we support PHP 5.5, this should be wrapped in a try..finally
+ // block so we can ensure that this privilege gets added again after.
+ $this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
+
+ $result = $this->server->getProperties(
+ $principalUri,
[
'{DAV:}principal-URL',
$caldavNS . 'calendar-home-set',
@@ -440,27 +454,25 @@ class Plugin extends ServerPlugin {
]
);
- if (!count($result)) {
- $iTipMessage->scheduleStatus = '3.7;Could not find principal.';
- return;
- }
+ // Re-registering the ACL event
+ $this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
- if (!isset($result[0][200][$caldavNS . 'schedule-inbox-URL'])) {
+ if (!isset($result[$caldavNS . 'schedule-inbox-URL'])) {
$iTipMessage->scheduleStatus = '5.2;Could not find local inbox';
return;
}
- if (!isset($result[0][200][$caldavNS . 'calendar-home-set'])) {
+ if (!isset($result[$caldavNS . 'calendar-home-set'])) {
$iTipMessage->scheduleStatus = '5.2;Could not locate a calendar-home-set';
return;
}
- if (!isset($result[0][200][$caldavNS . 'schedule-default-calendar-URL'])) {
+ if (!isset($result[$caldavNS . 'schedule-default-calendar-URL'])) {
$iTipMessage->scheduleStatus = '5.2;Could not find a schedule-default-calendar-URL property';
return;
}
- $calendarPath = $result[0][200][$caldavNS . 'schedule-default-calendar-URL']->getHref();
- $homePath = $result[0][200][$caldavNS . 'calendar-home-set']->getHref();
- $inboxPath = $result[0][200][$caldavNS . 'schedule-inbox-URL']->getHref();
+ $calendarPath = $result[$caldavNS . 'schedule-default-calendar-URL']->getHref();
+ $homePath = $result[$caldavNS . 'calendar-home-set']->getHref();
+ $inboxPath = $result[$caldavNS . 'schedule-inbox-URL']->getHref();
if ($iTipMessage->method === 'REPLY') {
$privilege = 'schedule-deliver-reply';
diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index a72ac4d..32324bf 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -596,22 +596,38 @@ class Plugin extends DAV\ServerPlugin {
*
* This method returns false if the principal could not be found.
*
- * @return string|null
+ * @deprecated use getPrincipalByUri instead.
+ * @return string|bool
*/
function getPrincipalByEmail($email) {
+ $result = $this->getPrincipalByUri('mailto:' . $email);
+ return $result?:false;
+
+ }
+
+ /**
+ * Returns a principal based on its uri.
+ *
+ * Returns null if the principal could not be found.
+ *
+ * @param string $uri
+ * @return null|string
+ */
+ function getPrincipalByUri($uri) {
+
$result = null;
- $uris = $this->principalCollectionSet;
- foreach($uris as $uri) {
+ $collections = $this->principalCollectionSet;
+ foreach($collections as $collection) {
- $principalCollection = $this->server->tree->getNodeForPath($uri);
+ $principalCollection = $this->server->tree->getNodeForPath($collection);
if (!$principalCollection instanceof IPrincipalCollection) {
// Not a principal collection, we're simply going to ignore
// this.
continue;
}
- $result = $principalCollection->findByUri('mailto:' . $email);
+ $result = $principalCollection->findByUri($uri);
if ($result) {
return $result;
}
@@ -726,7 +742,6 @@ class Plugin extends DAV\ServerPlugin {
}
-
/* {{{ Event handlers */
/**
diff --git a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
index d58fe12..eeb61f9 100644
--- a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
+++ b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
@@ -32,12 +32,13 @@ class Mock extends AbstractBackend {
function getPrincipalsByPrefix($prefix) {
- $prefix = trim($prefix,'/') . '/';
+ $prefix = trim($prefix,'/');
+ if ($prefix) $prefix.='/';
$return = array();
foreach($this->principals as $principal) {
- if (strpos($principal['uri'], $prefix)!==0) continue;
+ if ($prefix && strpos($principal['uri'], $prefix)!==0) continue;
$return[] = $principal;
--
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