[Pkg-owncloud-commits] [php-sabredav] 93/220: Work on getting old-school sharing to map to the new system

David Prévot taffit at moszumanska.debian.org
Thu May 12 01:21:12 UTC 2016


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

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

commit 1877395f9ddae4e73d74ff0d82d0b0d1f4888cd2
Author: Evert Pot <me at evertpot.com>
Date:   Wed Mar 23 00:44:31 2016 -0400

    Work on getting old-school sharing to map to the new system
---
 examples/sql/sqlite.calendars.sql           |  2 +-
 lib/CalDAV/SharingPlugin.php                |  2 +-
 lib/CalDAV/Xml/Request/Share.php            | 61 +++++++++++++----------------
 tests/Sabre/CalDAV/Backend/PDOMySQLTest.php |  2 +-
 tests/Sabre/CalDAV/CalendarTest.php         |  9 -----
 tests/Sabre/CalDAV/SharingPluginTest.php    |  8 ++--
 tests/Sabre/DAVServerTest.php               |  3 +-
 7 files changed, 37 insertions(+), 50 deletions(-)

diff --git a/examples/sql/sqlite.calendars.sql b/examples/sql/sqlite.calendars.sql
index 71f3eb7..a33699d 100644
--- a/examples/sql/sqlite.calendars.sql
+++ b/examples/sql/sqlite.calendars.sql
@@ -22,7 +22,7 @@ CREATE TABLE calendarinstances (
     id integer primary key asc NOT NULL,
     calendarid integer NOT NULL,
     principaluri text NOT NULL,
-    access integer COMMENT '1 = owner, 2 = readwrite, 3 = read' NOT NULL,
+    access integer COMMENT '1 = owner, 2 = readwrite, 3 = read' NOT NULL DEFAULT '1',
     displayname text,
     uri text NOT NULL,
     description text,
diff --git a/lib/CalDAV/SharingPlugin.php b/lib/CalDAV/SharingPlugin.php
index 5918cc3..ee9ff42 100644
--- a/lib/CalDAV/SharingPlugin.php
+++ b/lib/CalDAV/SharingPlugin.php
@@ -263,7 +263,7 @@ class SharingPlugin extends DAV\ServerPlugin {
             case '{' . Plugin::NS_CALENDARSERVER . '}share' :
 
                 $sharingPlugin = $this->server->getPlugin('sharing');
-                $sharingPlugin->shareResource($path, $message->set, $message->remove);
+                $sharingPlugin->shareResource($path, $message->sharees);
 
                 $response->setStatus(200);
                 // Adding this because sending a response body may cause issues,
diff --git a/lib/CalDAV/Xml/Request/Share.php b/lib/CalDAV/Xml/Request/Share.php
index dacc5dc..1339fc3 100644
--- a/lib/CalDAV/Xml/Request/Share.php
+++ b/lib/CalDAV/Xml/Request/Share.php
@@ -2,9 +2,10 @@
 
 namespace Sabre\CalDAV\Xml\Request;
 
+use Sabre\CalDAV\Plugin;
+use Sabre\DAV\Xml\Element\Sharee;
 use Sabre\Xml\Reader;
 use Sabre\Xml\XmlDeserializable;
-use Sabre\CalDAV\Plugin;
 
 /**
  * Share POST request parser
@@ -20,37 +21,20 @@ use Sabre\CalDAV\Plugin;
 class Share implements XmlDeserializable {
 
     /**
-     * The list of new people added or updated.
-     *
-     * Every element has the following keys:
-     * 1. href - An email address
-     * 2. commonName - Some name
-     * 3. summary - An optional description of the share
-     * 4. readOnly - true or false
-     *
-     * @var array
-     */
-    public $set = [];
-
-    /**
-     * List of people removed from the share list.
-     *
-     * The list is a flat list of email addresses (including mailto:).
+     * The list of new people added or updated or removed from the share.
      *
-     * @var array
+     * @var Sharee[]
      */
-    public $remove = [];
+    public $sharees = [];
 
     /**
      * Constructor
      *
-     * @param array $set
-     * @param array $remove
+     * @param Sharee[] $sharees
      */
-    function __construct(array $set, array $remove) {
+    function __construct(array $sharees) {
 
-        $this->set = $set;
-        $this->remove = $remove;
+        $this->sharees = $sharees;
 
     }
 
@@ -82,8 +66,7 @@ class Share implements XmlDeserializable {
             '{' . Plugin::NS_CALENDARSERVER . '}remove' => 'Sabre\\Xml\\Element\\KeyValue',
         ]);
 
-        $set = [];
-        $remove = [];
+        $sharees = [];
 
         foreach ($elems as $elem) {
             switch ($elem['name']) {
@@ -94,22 +77,34 @@ class Share implements XmlDeserializable {
                     $sumElem = '{' . Plugin::NS_CALENDARSERVER . '}summary';
                     $commonName = '{' . Plugin::NS_CALENDARSERVER . '}common-name';
 
-                    $set[] = [
+                    $properties = [];
+                    if (isset($sharee[$commonName])) {
+                        $properties['{DAV:}displayname'] = $sharee[$commonName];
+                    }
+
+                    $access = array_key_exists('{' . Plugin::NS_CALENDARSERVER . '}read-write', $sharee)
+                        ? \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE
+                        : \Sabre\DAV\Sharing\Plugin::ACCESS_READ;
+
+                    $sharees[] = new Sharee([
                         'href'       => $sharee['{DAV:}href'],
-                        'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null,
-                        'summary'    => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
-                        'readOnly'   => !array_key_exists('{' . Plugin::NS_CALENDARSERVER . '}read-write', $sharee),
-                    ];
+                        'properties' => $properties,
+                        'access'     => $access,
+                        'comment'    => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null
+                    ]);
                     break;
 
                 case '{' . Plugin::NS_CALENDARSERVER . '}remove' :
-                    $remove[] = $elem['value']['{DAV:}href'];
+                    $sharees[] = new Sharee([
+                        'href' => $elem['value']['{DAV:}href'],
+                        'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS
+                    ]);
                     break;
 
             }
         }
 
-        return new self($set, $remove);
+        return new self($sharees);
 
     }
 
diff --git a/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php b/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php
index ea46cfb..8e0e072 100644
--- a/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php
+++ b/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php
@@ -14,7 +14,7 @@ class PDOMySQLTest extends AbstractPDOTest {
         $pdo = \Sabre\TestUtil::getMySQLDB();
         if (!$pdo) $this->markTestSkipped('Could not connect to mysql database');
 
-        $pdo->query('DROP TABLE IF EXISTS calendarobjects, calendars, calendar_instances, calendarchanges, calendarsubscriptions, schedulingobjects');
+        $pdo->query('DROP TABLE IF EXISTS calendarobjects, calendars, calendarinstances, calendarchanges, calendarsubscriptions, schedulingobjects');
 
         $queries = explode(
             ';',
diff --git a/tests/Sabre/CalDAV/CalendarTest.php b/tests/Sabre/CalDAV/CalendarTest.php
index 2cd344a..6be1e0d 100644
--- a/tests/Sabre/CalDAV/CalendarTest.php
+++ b/tests/Sabre/CalDAV/CalendarTest.php
@@ -251,15 +251,6 @@ class CalendarTest extends \PHPUnit_Framework_TestCase {
 
     }
 
-    function testGetSyncToken2() {
-
-        $calendar = new Calendar(new Backend\Mock([], []), [
-            '{DAV:}sync-token' => 2
-        ]);
-        $this->assertEquals(2, $this->calendar->getSyncToken());
-
-    }
-
     function testGetSyncTokenNoSyncSupport() {
 
         $calendar = new Calendar(new Backend\Mock([], []), []);
diff --git a/tests/Sabre/CalDAV/SharingPluginTest.php b/tests/Sabre/CalDAV/SharingPluginTest.php
index 31da65e..1eb2365 100644
--- a/tests/Sabre/CalDAV/SharingPluginTest.php
+++ b/tests/Sabre/CalDAV/SharingPluginTest.php
@@ -22,10 +22,10 @@ class SharingPluginTest extends \Sabre\DAVServerTest {
                 'uri'          => 'cal1',
             ],
             [
-                'principaluri'                                  => 'principals/user1',
-                'id'                                            => 2,
-                'uri'                                           => 'cal2',
-                'share-access'                                  => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
+                'principaluri' => 'principals/user1',
+                'id'           => 2,
+                'uri'          => 'cal2',
+                'share-access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
             ],
             [
                 'principaluri' => 'principals/user1',
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index cb01771..b175be8 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -198,7 +198,8 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
         $this->server->exec();
 
         if ($expectedStatus) {
-            $this->assertEquals($expectedStatus, $response->getStatus(), 'Incorrect HTTP status received for request');
+            $responseBody = $expectedStatus !== $response->getStatus() ? $response->getBodyAsString() : '';
+            $this->assertEquals($expectedStatus, $response->getStatus(), 'Incorrect HTTP status received for request. Response body: ' . $responseBody);
         }
         return $this->server->httpResponse;
 

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



More information about the Pkg-owncloud-commits mailing list