[Pkg-owncloud-commits] [php-sabredav] 39/275: Scheduling message is added to the inbox.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:55:49 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 d72286da7e4470a7d723c6a7921e7a4aa2905e7f
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Sun Jan 26 21:41:48 2014 -0500

    Scheduling message is added to the inbox.
---
 lib/Sabre/CalDAV/Backend/PDO.php                   | 17 ++++++-
 lib/Sabre/CalDAV/Backend/SchedulingSupport.php     | 10 ++++
 lib/Sabre/CalDAV/Schedule/ITipMessage.php          | 22 +++++++++
 lib/Sabre/CalDAV/Schedule/Inbox.php                | 30 ++++++++++++
 lib/Sabre/CalDAV/Schedule/Plugin.php               | 53 +++++++++++++++++++++-
 lib/Sabre/DAVACL/Plugin.php                        | 25 ++++++++++
 lib/Sabre/DAVACL/Principal.php                     | 12 ++---
 tests/Sabre/CalDAV/Backend/MockScheduling.php      | 23 ++++++++++
 .../Sabre/CalDAV/Schedule/DeliverNewEventTest.php  | 11 +++--
 9 files changed, 189 insertions(+), 14 deletions(-)

diff --git a/lib/Sabre/CalDAV/Backend/PDO.php b/lib/Sabre/CalDAV/Backend/PDO.php
index 3abc8fe..384f418 100755
--- a/lib/Sabre/CalDAV/Backend/PDO.php
+++ b/lib/Sabre/CalDAV/Backend/PDO.php
@@ -64,7 +64,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
      * @var string
      */
     protected $schedulingObjectTableName;
-    
+
     /**
      * The table name that will be used for calendar subscriptions.
      *
@@ -1249,4 +1249,19 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
 
     }
 
+    /**
+     * Creates a new scheduling object. This should land in a users' inbox.
+     *
+     * @param string $principalUri
+     * @param string $objectUri
+     * @param string $objectData
+     * @return void
+     */
+    public function createSchedulingObject($principalUri, $objectUri, $objectData) {
+
+        $stmt = $this->pdo->prepare('INSERT INTO '.$this->schedulingObjectTableName.' (principaluri, calendardata, uri, lastmodified, etag, size) VALUES (?, ?, ?, UNIX_TIMESTAMP(), ?, ?)');
+        $stmt->execute([$principalUri, $objectData, $objectUri, md5($objectData), strlen($objectData) ]);
+
+    }
+
 }
diff --git a/lib/Sabre/CalDAV/Backend/SchedulingSupport.php b/lib/Sabre/CalDAV/Backend/SchedulingSupport.php
index c618b03..838ba1b 100644
--- a/lib/Sabre/CalDAV/Backend/SchedulingSupport.php
+++ b/lib/Sabre/CalDAV/Backend/SchedulingSupport.php
@@ -52,4 +52,14 @@ interface SchedulingSupport extends BackendInterface {
      */
     public function deleteSchedulingObject($principalUri, $objectUri);
 
+    /**
+     * Creates a new scheduling object. This should land in a users' inbox.
+     *
+     * @param string $principalUri
+     * @param string $objectUri
+     * @param string $objectData
+     * @return void
+     */
+    public function createSchedulingObject($principalUri, $objectUri, $objectData);
+
 }
diff --git a/lib/Sabre/CalDAV/Schedule/ITipMessage.php b/lib/Sabre/CalDAV/Schedule/ITipMessage.php
index 51c0eff..575f280 100644
--- a/lib/Sabre/CalDAV/Schedule/ITipMessage.php
+++ b/lib/Sabre/CalDAV/Schedule/ITipMessage.php
@@ -75,4 +75,26 @@ class ITipMessage {
      */
     public $message;
 
+    /**
+     * This method is strictly for debugging. Allows us to pretty-print the
+     * contents of this message.
+     */
+    public function __toString() {
+
+        $sender = $this->senderName . ' <' . $this->sender . '>';
+        $recipient = $this->recipientName . ' <' . $this->recipient . '>';
+        $status = $this->scheduleStatus?:null;
+
+        return <<<HI
+Sender: $sender
+Recipient: $recipient
+Method: {$this->method}
+Status: $status
+
+
+HI
+        . $this->message->serialize();
+
+    }
+
 }
diff --git a/lib/Sabre/CalDAV/Schedule/Inbox.php b/lib/Sabre/CalDAV/Schedule/Inbox.php
index b216360..9c50cf4 100644
--- a/lib/Sabre/CalDAV/Schedule/Inbox.php
+++ b/lib/Sabre/CalDAV/Schedule/Inbox.php
@@ -75,6 +75,36 @@ class Inbox extends DAV\Collection implements IInbox {
     }
 
     /**
+     * Creates a new file in the directory
+     *
+     * Data will either be supplied as a stream resource, or in certain cases
+     * as a string. Keep in mind that you may have to support either.
+     *
+     * After succesful creation of the file, you may choose to return the ETag
+     * of the new file here.
+     *
+     * The returned ETag must be surrounded by double-quotes (The quotes should
+     * be part of the actual string).
+     *
+     * If you cannot accurately determine the ETag, you should not return it.
+     * If you don't store the file exactly as-is (you're transforming it
+     * somehow) you should also not return an ETag.
+     *
+     * This means that if a subsequent GET to this new file does not exactly
+     * return the same contents of what was submitted here, you are strongly
+     * recommended to omit the ETag.
+     *
+     * @param string $name Name of the file
+     * @param resource|string $data Initial payload
+     * @return null|string
+     */
+    public function createFile($name, $data = null) {
+
+        $this->caldavBackend->createSchedulingObject($this->principalUri, $name, $data);
+
+    }
+
+    /**
      * Returns the owner principal
      *
      * This must be a url to a principal, or null if there's no owner
diff --git a/lib/Sabre/CalDAV/Schedule/Plugin.php b/lib/Sabre/CalDAV/Schedule/Plugin.php
index a07ba76..6d91d0c 100644
--- a/lib/Sabre/CalDAV/Schedule/Plugin.php
+++ b/lib/Sabre/CalDAV/Schedule/Plugin.php
@@ -187,8 +187,9 @@ class Plugin extends ServerPlugin {
 
         $this->server = $server;
         $server->on('method:POST', [$this,'httpPost']);
-        $server->on('beforeGetProperties', [$this,'beforeGetProperties']);
-        $server->on('beforeCreateFile',    [$this,'beforeCreateFile']);
+        $server->on('beforeGetProperties', [$this, 'beforeGetProperties']);
+        $server->on('beforeCreateFile',    [$this, 'beforeCreateFile']);
+        $server->on('schedule',            [$this, 'scheduleLocalDelivery']);
 
         /**
          * This information ensures that the {DAV:}resourcetype property has
@@ -480,6 +481,54 @@ class Plugin extends ServerPlugin {
     }
 
     /**
+     * Event handler for the 'schedule' event.
+     *
+     * This handler attempts to look at local accounts to deliver the
+     * scheduling object.
+     *
+     * @param ITipImessage $iTipMessage
+     * @return void
+     */
+    public function scheduleLocalDelivery($iTipMessage) {
+
+        $aclPlugin = $this->server->getPlugin('acl');
+
+        // Local delivery is not available if the ACL plugin is not loaded.
+        if (!$aclPlugin) {
+            return;
+        }
+
+        $caldavNS = '{' . Plugin::NS_CALDAV . '}';
+
+        $result = $aclPlugin->principalSearch(
+            ['{http://sabredav.org/ns}email-address' => $iTipMessage->recipient],
+            [
+                '{DAV:}principal-URL',
+                 $caldavNS . 'calendar-home-set',
+                 $caldavNS . 'schedule-inbox-URL',
+                '{http://sabredav.org/ns}email-address',
+            ]
+        );
+
+        if (!count($result)) {
+            $iTipMessage->scheduleStatus = '3.7; Could not find principal with email: ' . $iTipMessage->recipient;
+            return;
+        }
+
+        $inboxPath = $result[0][200][$caldavNS . 'schedule-inbox-URL']->getHref();
+
+        // Note that we are bypassing ACL on purpose by calling this directly.
+        // We may need to look a bit deeper into this later. Supporting ACL
+        // here would be nice
+        $inbox = $this->server->tree->getNodeForPath($inboxPath);
+        $inbox->createFile('sabredav-' . \Sabre\DAV\UUIDUtil::getUUID() . '.ics', $iTipMessage->message->serialize());
+
+        $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
+
+
+    }
+
+    /**
      * Returns a list of addresses that are associated with a principal.
      *
      * @param string $principal
diff --git a/lib/Sabre/DAVACL/Plugin.php b/lib/Sabre/DAVACL/Plugin.php
index 7841bc3..0dcc3d5 100644
--- a/lib/Sabre/DAVACL/Plugin.php
+++ b/lib/Sabre/DAVACL/Plugin.php
@@ -587,6 +587,31 @@ class Plugin extends DAV\ServerPlugin {
     }
 
     /**
+     * Returns a principal url based on an email address.
+     *
+     * Note that wether or not this works may depend on wether a search
+     * facility is built into the server.
+     *
+     * This method returns false if the principal could not be found.
+     *
+     * @return string|bool
+     */
+    public function getPrincipalByEmail($email) {
+
+        $result = $this->principalSearch(
+            ['{http://sabredav.org/ns}email-address' => $email],
+            ['{DAV:}principal-URL']
+        );
+
+        if (!count($result)) {
+            return false;
+        }
+
+        return $result[0][200]['{DAV:}principal-URL'];
+
+    }
+
+    /**
      * Principal property search
      *
      * This method can search for principals matching certain values in
diff --git a/lib/Sabre/DAVACL/Principal.php b/lib/Sabre/DAVACL/Principal.php
index e90c035..29c493c 100644
--- a/lib/Sabre/DAVACL/Principal.php
+++ b/lib/Sabre/DAVACL/Principal.php
@@ -186,7 +186,7 @@ class Principal extends DAV\Node implements IPrincipal, DAV\IProperties, IACL {
 
     /**
      * Updates this principals properties.
-     * 
+     *
      * @param array $mutations
      * @see Sabre\DAV\IProperties::updateProperties
      * @return bool|array
@@ -238,13 +238,13 @@ class Principal extends DAV\Node implements IPrincipal, DAV\IProperties, IACL {
      */
     public function getACL() {
 
-        return array(
-            array(
+        return [
+            [
                 'privilege' => '{DAV:}read',
-                'principal' => $this->getPrincipalUrl(),
+                'principal' => '{DAV:}authenticated',
                 'protected' => true,
-            ),
-        );
+            ],
+        ];
 
     }
 
diff --git a/tests/Sabre/CalDAV/Backend/MockScheduling.php b/tests/Sabre/CalDAV/Backend/MockScheduling.php
index 8b6c588..8aa1f79 100644
--- a/tests/Sabre/CalDAV/Backend/MockScheduling.php
+++ b/tests/Sabre/CalDAV/Backend/MockScheduling.php
@@ -66,4 +66,27 @@ class MockScheduling extends Mock implements SchedulingSupport {
 
     }
 
+    /**
+     * Creates a new scheduling object. This should land in a users' inbox.
+     *
+     * @param string $principalUri
+     * @param string $objectUri
+     * @param string $objectData;
+     * @return void
+     */
+    public function createSchedulingObject($principalUri, $objectUri, $objectData) {
+
+        if (!isset($this->schedulingObjects[$principalUri])) {
+            $this->schedulingObjects[$principalUri] = [];
+        }
+        $this->schedulingObjects[$principalUri][$objectUri] = [
+            'uri' => $objectUri,
+            'calendardata' => $objectData,
+            'lastmodified' => null,
+            'etag' => '"' . md5($objectData) . '"',
+            'size' => strlen($objectData)
+        ];
+
+    }
+
 }
diff --git a/tests/Sabre/CalDAV/Schedule/DeliverNewEventTest.php b/tests/Sabre/CalDAV/Schedule/DeliverNewEventTest.php
index e249e69..937fc9b 100644
--- a/tests/Sabre/CalDAV/Schedule/DeliverNewEventTest.php
+++ b/tests/Sabre/CalDAV/Schedule/DeliverNewEventTest.php
@@ -10,6 +10,8 @@ class DeliverNewEventTest extends \Sabre\DAVServerTest {
 
     public $setupCalDAV = true;
     public $setupCalDAVScheduling = true;
+    public $setupACL = true;
+    public $autoLogin = 'user1';
 
     function setUp() {
 
@@ -38,9 +40,8 @@ UID:AADC6438-18CF-4B52-8DD2-EF9AD75ADE83
 DTEND;TZID=America/Toronto:20140107T110000
 TRANSP:OPAQUE
 ATTENDEE;CN="Adminstrator";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:mailto:user1.sabredav at sabredav.org
-ATTENDEE;CN="Roxy Kesh";CUTYPE=INDIVIDUAL;EMAIL="roxannakesh at gmail.com";
- PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:roxannakesh@
- gmail.com
+ATTENDEE;CN="Roxy Kesh";CUTYPE=INDIVIDUAL;EMAIL="user2.sabredav at sabrdav.org";
+ PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:user2.sabredav at sabredav.org
 SUMMARY:Just testing!
 DTSTART;TZID=America/Toronto:20140107T100000
 DTSTAMP:20140109T204422Z
@@ -64,7 +65,7 @@ ICS
         $resultVObj = VObject\Reader::read($result);
 
         $this->assertEquals(
-            '5.2;There was no system capable of delivering the scheduling message',
+            '1.2;Message delivered locally',
             $resultVObj->VEVENT->ATTENDEE[1]['SCHEDULE-STATUS']->getValue()
         );
 
@@ -72,7 +73,7 @@ ICS
         $message = $messages[0];
 
         $this->assertInstanceOf('\Sabre\CalDAV\Schedule\ITipMessage', $message);
-        $this->assertEquals('roxannakesh at gmail.com', $message->recipient);
+        $this->assertEquals('user2.sabredav at sabredav.org', $message->recipient);
         $this->assertEquals('Roxy Kesh', $message->recipientName);
         $this->assertEquals('user1.sabredav at sabredav.org', $message->sender);
         $this->assertEquals('Administrator', $message->senderName);

-- 
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