[Pkg-owncloud-commits] [php-sabredav] 48/220: Slowly kicking CalDAV in line with the new API
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:06 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 cc0b1ce8037b5c5f525df4646078021da068e3f1
Author: Evert Pot <me at evertpot.com>
Date: Tue Jan 12 01:19:00 2016 -0500
Slowly kicking CalDAV in line with the new API
---
examples/sql/mysql.calendars.sql | 2 +-
examples/sql/sqlite.calendars.sql | 2 +-
lib/CalDAV/Backend/PDO.php | 47 +++++++-------------
lib/CalDAV/Backend/SharingSupport.php | 41 +++++-------------
lib/CalDAV/SharedCalendar.php | 4 +-
lib/CalDAV/SharingPlugin.php | 8 ++--
lib/DAV/Sharing/Plugin.php | 2 +-
lib/DAV/Xml/Element/Sharee.php | 25 ++++++++++-
tests/Sabre/CalDAV/Backend/MockSharing.php | 69 ++++++++++++++----------------
tests/Sabre/CalDAV/SharedCalendarTest.php | 69 ++++++++++++++++--------------
tests/Sabre/CalDAV/SharingPluginTest.php | 12 +++---
11 files changed, 135 insertions(+), 146 deletions(-)
diff --git a/examples/sql/mysql.calendars.sql b/examples/sql/mysql.calendars.sql
index 45cc09e..7db3b6f 100644
--- a/examples/sql/mysql.calendars.sql
+++ b/examples/sql/mysql.calendars.sql
@@ -19,7 +19,7 @@ CREATE TABLE calendars (
components VARBINARY(20)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-CREATE TABLE calendar_instances (
+CREATE TABLE calendarinstances (
id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
calendarid INTEGER UNSIGNED NOT NULL,
principaluri VARBINARY(100),
diff --git a/examples/sql/sqlite.calendars.sql b/examples/sql/sqlite.calendars.sql
index 87e5270..32b0627 100644
--- a/examples/sql/sqlite.calendars.sql
+++ b/examples/sql/sqlite.calendars.sql
@@ -18,7 +18,7 @@ CREATE TABLE calendars (
components text
);
-CREATE TABLE calendar_instances (
+CREATE TABLE calendarinstances (
id integer primary key asc,
calendarid integer,
principaluri text,
diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index de74e8a..b66c6af 100644
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -56,7 +56,7 @@ class PDO extends AbstractBackend
*
* @var string
*/
- public $calendarInstancesTableName = 'calendar_instances';
+ public $calendarInstancesTableName = 'calendarinstances';
/**
* The table name that will be used for calendar objects
@@ -199,7 +199,9 @@ SQL
$stmt2->execute([$row['id']]);
$calendar['share-access'] = $row['access'];
- $calendar['owner_principal'] = $stmt2->fetchColumn();
+
+ // read-only is for backwards compatbility. Might go away in
+ // the future.
$calendar['read-only'] = $row['access'] === \Sabre\DAV\Sharing\Plugin::ACCESS_READONLY;
}
@@ -1318,27 +1320,11 @@ SQL;
/**
* Updates the list of shares.
*
- * The first array is a list of people that are to be added to the
- * calendar.
- *
- * Every element in the add array has the following properties:
- * * href - A url. Usually a mailto: address
- * * commonName - Usually a first and last name, or false
- * * summary - A description of the share, can also be false
- * * readOnly - A boolean value
- *
- * Every element in the remove array is just the address string.
- *
- * Note that if the calendar is currently marked as 'not shared' by and
- * this method is called, the calendar should be 'upgraded' to a shared
- * calendar.
- *
* @param mixed $calendarId
- * @param array $add
- * @param array $remove
+ * @param \Sabre\DAV\Xml\Element\Sharee[] $sharees
* @return void
*/
- function updateShares($calendarId, array $add, array $remove) {
+ function updateInvites($calendarId, array $sharees) {
throw new \Exception('Not implemented');
@@ -1347,22 +1333,19 @@ SQL;
/**
* Returns the list of people whom this calendar is shared with.
*
- * Every element in this array should have the following properties:
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first + last name
- * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
- * * readOnly - boolean
- * * summary - Optional, a description for the share
+ * Every item in the returned list must be a Sharee object with at
+ * least the following properties set:
+ * $href
+ * $shareAccess
+ * $inviteStatus
*
- * This method may be called by either the original instance of the
- * calendar, as well as the shared instances. In the case of the shared
- * instances, it is perfectly acceptable to return an empty array in case
- * there are privacy concerns.
+ * and optionally:
+ * $properties
*
* @param mixed $calendarId
- * @return array
+ * @return \Sabre\DAV\Xml\Element\Sharee[]
*/
- function getShares($calendarId) {
+ function getInvites($calendarId) {
throw new \Exception('Not implemented');
diff --git a/lib/CalDAV/Backend/SharingSupport.php b/lib/CalDAV/Backend/SharingSupport.php
index 84f1070..f3aa6ad 100644
--- a/lib/CalDAV/Backend/SharingSupport.php
+++ b/lib/CalDAV/Backend/SharingSupport.php
@@ -118,47 +118,28 @@ interface SharingSupport extends BackendInterface {
/**
* Updates the list of shares.
*
- * The first array is a list of people that are to be added to the
- * calendar.
- *
- * Every element in the add array has the following properties:
- * * href - A url. Usually a mailto: address
- * * commonName - Usually a first and last name, or false
- * * summary - A description of the share, can also be false
- * * readOnly - A boolean value
- *
- * Every element in the remove array is just the address string.
- *
- * Note that if the calendar is currently marked as 'not shared' by and
- * this method is called, the calendar should be 'upgraded' to a shared
- * calendar.
- *
* @param mixed $calendarId
- * @param array $add
- * @param array $remove
+ * @param \Sabre\DAV\Xml\Element\Sharee[] $sharees
* @return void
*/
- function updateShares($calendarId, array $add, array $remove);
+ function updateInvites($calendarId, array $sharees);
/**
* Returns the list of people whom this calendar is shared with.
*
- * Every element in this array should have the following properties:
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first + last name
- * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
- * * readOnly - boolean
- * * summary - Optional, a description for the share
+ * Every item in the returned list must be a Sharee object with at
+ * least the following properties set:
+ * $href
+ * $shareAccess
+ * $inviteStatus
*
- * This method may be called by either the original instance of the
- * calendar, as well as the shared instances. In the case of the shared
- * instances, it is perfectly acceptable to return an empty array in case
- * there are privacy concerns.
+ * and optionally:
+ * $properties
*
* @param mixed $calendarId
- * @return array
+ * @return \Sabre\DAV\Xml\Element\Sharee[]
*/
- function getShares($calendarId);
+ function getInvites($calendarId);
/**
* Publishes a calendar
diff --git a/lib/CalDAV/SharedCalendar.php b/lib/CalDAV/SharedCalendar.php
index cf29668..1e3fc4c 100644
--- a/lib/CalDAV/SharedCalendar.php
+++ b/lib/CalDAV/SharedCalendar.php
@@ -54,7 +54,7 @@ class SharedCalendar extends Calendar implements ISharedCalendar {
*/
function updateInvites(array $sharees) {
- $this->caldavBackend->updateShares($this->calendarInfo['id'], $sharees);
+ $this->caldavBackend->updateInvites($this->calendarInfo['id'], $sharees);
}
@@ -76,7 +76,7 @@ class SharedCalendar extends Calendar implements ISharedCalendar {
*/
function getInvites() {
- return $this->caldavBackend->getShares($this->calendarInfo['id']);
+ return $this->caldavBackend->getInvites($this->calendarInfo['id']);
}
diff --git a/lib/CalDAV/SharingPlugin.php b/lib/CalDAV/SharingPlugin.php
index bb669de..0c13b7f 100644
--- a/lib/CalDAV/SharingPlugin.php
+++ b/lib/CalDAV/SharingPlugin.php
@@ -136,7 +136,7 @@ class SharingPlugin extends DAV\ServerPlugin {
}
return new Xml\Property\Invite(
- $node->getShares(),
+ $node->getInvites(),
$ownerInfo
);
@@ -204,12 +204,12 @@ class SharingPlugin extends DAV\ServerPlugin {
$propPatch->handle('{DAV:}resourcetype', function($value) use ($node) {
if ($value->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) return false;
- $shares = $node->getShares();
+ $shares = $node->getInvites();
$remove = [];
foreach ($shares as $share) {
- $remove[] = $share['href'];
+ $share->access = DAV\Sharing\Plugin::ACCESS_NOACCESS;
}
- $node->updateShares([], $remove);
+ $node->updateInvites($shares);
return true;
diff --git a/lib/DAV/Sharing/Plugin.php b/lib/DAV/Sharing/Plugin.php
index 57850bf..df56c85 100644
--- a/lib/DAV/Sharing/Plugin.php
+++ b/lib/DAV/Sharing/Plugin.php
@@ -131,7 +131,7 @@ class Plugin extends ServerPlugin {
$acl->checkPrivileges($path, '{DAV:}share');
}
- $node->updateShares($sharees);
+ $node->updateInvites($sharees);
}
diff --git a/lib/DAV/Xml/Element/Sharee.php b/lib/DAV/Xml/Element/Sharee.php
index d4d523c..c9d4a88 100644
--- a/lib/DAV/Xml/Element/Sharee.php
+++ b/lib/DAV/Xml/Element/Sharee.php
@@ -45,12 +45,12 @@ class Sharee implements Element {
* ACCESS_READWRITE
* ACCESS_SHAREDOWNER
* ACCESS_NOACCESS
- *
+ *
* depending on context.
*
* @var int
*/
- public $shareAccess;
+ public $access;
/**
* When a sharee is originally invited to a share, the sharer may add
@@ -69,6 +69,27 @@ class Sharee implements Element {
public $inviteStatus;
/**
+ * Creates the object
+ *
+ * $properties will be used to populate all internal properties.
+ *
+ * @param array $properties
+ */
+ function __construct(array $properties = []) {
+
+ foreach($properties as $k=>$v) {
+
+ if (property_exists($this, $k)) {
+ $this->$k = $v;
+ } else {
+ throw new \InvalidArgumentException('Unknown property: ' . $k);
+ }
+
+ }
+
+ }
+
+ /**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
diff --git a/tests/Sabre/CalDAV/Backend/MockSharing.php b/tests/Sabre/CalDAV/Backend/MockSharing.php
index 2b6cc9f..7a5216a 100644
--- a/tests/Sabre/CalDAV/Backend/MockSharing.php
+++ b/tests/Sabre/CalDAV/Backend/MockSharing.php
@@ -43,7 +43,7 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
continue;
}
if (!empty($this->shares[$calendar['id']])) {
- $calendar['share-access'] = DAV\Sharing\Plugin::ACCESS_OWNER;
+ $calendar['share-access'] = DAV\Sharing\Plugin::ACCESS_SHAREDOWNER;
} else {
$calendar['share-access'] = DAV\Sharing\Plugin::ACCESS_NOTSHARED;
}
@@ -94,43 +94,38 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
/**
* Updates the list of shares.
*
- * The first array is a list of people that are to be added to the
- * calendar.
- *
- * Every element in the add array has the following properties:
- * * href - A url. Usually a mailto: address
- * * commonName - Usually a first and last name, or false
- * * summary - A description of the share, can also be false
- * * readOnly - A boolean value
- *
- * Every element in the remove array is just the address string.
- *
- * Note that if the calendar is currently marked as 'not shared' by and
- * this method is called, the calendar should be 'upgraded' to a shared
- * calendar.
- *
* @param mixed $calendarId
- * @param array $add
- * @param array $remove
+ * @param \Sabre\DAV\Xml\Element\Sharee[] $sharees
* @return void
*/
- function updateShares($calendarId, array $add, array $remove) {
+ function updateInvites($calendarId, array $sharees) {
if (!isset($this->shares[$calendarId])) {
$this->shares[$calendarId] = [];
}
- foreach ($add as $val) {
- $val['status'] = DAV\Sharing\Plugin::INVITE_NORESPONSE;
- $this->shares[$calendarId][] = $val;
- }
-
- foreach ($this->shares[$calendarId] as $k => $share) {
+ foreach ($sharees as $sharee) {
- if (in_array($share['href'], $remove)) {
- unset($this->shares[$calendarId][$k]);
+ $existingKey = null;
+ foreach($this->shares[$calendarId] as $k=>$existingSharee) {
+ if ($sharee->href === $existingSharee->href) {
+ $existingKey = $k;
+ }
+ }
+ // Just making sure we're not affecting an existing copy.
+ $sharee = clone $sharee;
+ $sharee->inviteStatus = DAV\Sharing\Plugin::INVITE_NORESPONSE;
+
+ if ($sharee->access === DAV\Sharing\Plugin::ACCESS_NOACCESS) {
+ // It's a removal
+ unset($this->shares[$calendarId][$existingKey]);
+ } elseif ($existingKey) {
+ // It's an update
+ $this->shares[$calendarId][$existingKey] = $sharee;
+ } else {
+ // It's an addition
+ $this->shares[$calendarId][] = $sharee;
}
-
}
// Re-numbering keys
@@ -141,17 +136,19 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
/**
* Returns the list of people whom this calendar is shared with.
*
- * Every element in this array should have the following properties:
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first + last name
- * * status - See the Sabre\DAV\Sharing\Plugin::INVITE_ constants.
- * * readOnly - boolean
- * * summary - Optional, a description for the share
+ * Every item in the returned list must be a Sharee object with at
+ * least the following properties set:
+ * $href
+ * $shareAccess
+ * $inviteStatus
+ *
+ * and optionally:
+ * $properties
*
* @param mixed $calendarId
- * @return array
+ * @return \Sabre\DAV\Xml\Element\Sharee[]
*/
- function getShares($calendarId) {
+ function getInvites($calendarId) {
if (!isset($this->shares[$calendarId])) {
return [];
diff --git a/tests/Sabre/CalDAV/SharedCalendarTest.php b/tests/Sabre/CalDAV/SharedCalendarTest.php
index 0b4e1ba..f71c195 100644
--- a/tests/Sabre/CalDAV/SharedCalendarTest.php
+++ b/tests/Sabre/CalDAV/SharedCalendarTest.php
@@ -3,6 +3,7 @@
namespace Sabre\CalDAV;
use Sabre\DAV\Sharing;
+use Sabre\DAV\Xml\Element\Sharee;
class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
@@ -26,26 +27,29 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
[],
[]
);
- $this->backend->updateShares(1, [
- [
- 'href' => 'mailto:removeme at example.org',
- 'commonName' => 'To be removed',
- 'readOnly' => true,
- ],
- ], []);
+
+ $sharee = new Sharee();
+ $sharee->href = 'mailto:removeme at example.org';
+ $sharee->properties['{DAV:}displayname'] = 'To be removed';
+ $sharee->access = Sharing\Plugin::ACCESS_READ;
+ $this->backend->updateInvites(1, [$sharee]);
return new SharedCalendar($this->backend, $props);
}
- function testGetShares() {
+ function testGetInvites() {
- $this->assertEquals([[
- 'href' => 'mailto:removeme at example.org',
- 'commonName' => 'To be removed',
- 'readOnly' => true,
- 'status' => Sharing\Plugin::INVITE_NORESPONSE,
- ]], $this->getInstance()->getInvites());
+ $sharee = new Sharee();
+ $sharee->href = 'mailto:removeme at example.org';
+ $sharee->properties['{DAV:}displayname'] = 'To be removed';
+ $sharee->access = Sharing\Plugin::ACCESS_READ;
+ $sharee->inviteStatus = Sharing\Plugin::INVITE_NORESPONSE;
+
+ $this->assertEquals(
+ [$sharee],
+ $this->getInstance()->getInvites()
+ );
}
@@ -137,25 +141,28 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
}
- function testUpdateShares() {
+ function testUpdateInvites() {
$instance = $this->getInstance();
- $instance->updateShares([
- [
- 'href' => 'mailto:test at example.org',
- 'commonName' => 'Foo Bar',
- 'summary' => 'Booh',
- 'readOnly' => false,
- ],
- ], ['mailto:removeme at example.org']);
-
- $this->assertEquals([[
- 'href' => 'mailto:test at example.org',
- 'commonName' => 'Foo Bar',
- 'summary' => 'Booh',
- 'readOnly' => false,
- 'status' => SharingPlugin::STATUS_NORESPONSE,
- ]], $instance->getShares());
+ $newSharees = [
+ new Sharee(),
+ new Sharee()
+ ];
+ $newSharees[0]->href = 'mailto:test at example.org';
+ $newSharees[0]->properties['{DAV:}displayname'] = 'Foo Bar';
+ $newSharees[0]->comment = 'Booh';
+ $newSharees[0]->access = Sharing\Plugin::ACCESS_READWRITE;
+
+ $newSharees[1]->href = 'mailto:removeme at example.org';
+ $newSharees[1]->access = Sharing\Plugin::ACCESS_NOACCESS;
+
+ $instance->updateInvites($newSharees);
+
+ $expected = [
+ clone $newSharees[0]
+ ];
+ $expected[0]->inviteStatus = Sharing\Plugin::INVITE_NORESPONSE;
+ $this->assertEquals($expected, $instance->getInvites());
}
diff --git a/tests/Sabre/CalDAV/SharingPluginTest.php b/tests/Sabre/CalDAV/SharingPluginTest.php
index 34dd05a..31da65e 100644
--- a/tests/Sabre/CalDAV/SharingPluginTest.php
+++ b/tests/Sabre/CalDAV/SharingPluginTest.php
@@ -3,6 +3,7 @@
namespace Sabre\CalDAV;
use Sabre\DAV;
+use Sabre\DAV\Xml\Element\Sharee;
use Sabre\HTTP;
class SharingPluginTest extends \Sabre\DAVServerTest {
@@ -84,13 +85,12 @@ class SharingPluginTest extends \Sabre\DAVServerTest {
function testUpdateResourceType() {
- $this->caldavBackend->updateShares(1,
+ $this->caldavBackend->updateInvites(1,
[
- [
+ new Sharee([
'href' => 'mailto:joe at example.org',
- ],
- ],
- []
+ ])
+ ]
);
$result = $this->server->updateProperties('calendars/user1/cal1', [
'{DAV:}resourcetype' => new DAV\Xml\Property\ResourceType(['{DAV:}collection'])
@@ -100,7 +100,7 @@ class SharingPluginTest extends \Sabre\DAVServerTest {
'{DAV:}resourcetype' => 200
], $result);
- $this->assertEquals(0, count($this->caldavBackend->getShares(1)));
+ $this->assertEquals(0, count($this->caldavBackend->getInvites(1)));
}
--
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