[Pkg-owncloud-commits] [php-sabredav] 104/220: The old invite property now works correctly.
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:13 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 c871e1459d8cabf551b49635fa7787ce04bad4d5
Author: Evert Pot <me at evertpot.com>
Date: Wed Mar 23 02:31:07 2016 -0400
The old invite property now works correctly.
---
examples/sql/mysql.calendars.sql | 2 +-
examples/sql/sqlite.calendars.sql | 2 +-
lib/CalDAV/Backend/PDO.php | 34 +++-
lib/CalDAV/SharedCalendar.php | 2 +-
lib/CalDAV/Xml/Property/Invite.php | 208 +++++--------------------
lib/DAV/Sharing/Plugin.php | 2 +-
tests/Sabre/CalDAV/Xml/Property/InviteTest.php | 152 +++++-------------
7 files changed, 116 insertions(+), 286 deletions(-)
diff --git a/examples/sql/mysql.calendars.sql b/examples/sql/mysql.calendars.sql
index 7db3b6f..633290d 100644
--- a/examples/sql/mysql.calendars.sql
+++ b/examples/sql/mysql.calendars.sql
@@ -23,7 +23,7 @@ CREATE TABLE calendarinstances (
id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
calendarid INTEGER UNSIGNED NOT NULL,
principaluri VARBINARY(100),
- access TINYINT(1) NOT NULL DEFAULT '1' COMMENT '1 = owner, 2 = readwrite, 3 = read',
+ access TINYINT(1) NOT NULL DEFAULT '1' COMMENT '1 = owner, 2 = read, 3 = readwrite',
displayname VARCHAR(100),
uri VARBINARY(200),
description TEXT,
diff --git a/examples/sql/sqlite.calendars.sql b/examples/sql/sqlite.calendars.sql
index a33699d..c743a82 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 DEFAULT '1',
+ access integer COMMENT '1 = owner, 2 = read, 3 = readwrite' NOT NULL DEFAULT '1',
displayname text,
uri text NOT NULL,
description text,
diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index b66c6af..3dc808a 100644
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -6,6 +6,7 @@ use Sabre\CalDAV;
use Sabre\DAV;
use Sabre\DAV\Exception\Forbidden;
use Sabre\VObject;
+use Sabre\DAV\Xml\Element\Sharee;
/**
* PDO CalDAV backend
@@ -190,6 +191,7 @@ SQL
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0',
'{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet($components),
'{' . CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'),
+ 'share-resource-uri' => '/ns/share/' . $row['calendarid'],
];
// 1 = owner, 2 = readonly, 3 = readwrite
@@ -1331,7 +1333,7 @@ SQL;
}
/**
- * Returns the list of people whom this calendar is shared with.
+ * Returns the list of people whom a calendar is shared with.
*
* Every item in the returned list must be a Sharee object with at
* least the following properties set:
@@ -1347,7 +1349,35 @@ SQL;
*/
function getInvites($calendarId) {
- throw new \Exception('Not implemented');
+ if (!is_array($calendarId)) {
+ throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ }
+ list($calendarId, $instanceId) = $calendarId;
+
+ $query = <<<SQL
+SELECT
+ principaluri,
+ access
+FROM {$this->calendarInstancesTableName}
+WHERE
+ calendarid = ?
+SQL;
+
+ $stmt = $this->pdo->prepare($query);
+ $stmt->execute([$calendarId]);
+
+ $result = [];
+ while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+
+ $result[] = new Sharee([
+ 'href' => \Sabre\HTTP\encodePath($row['principaluri']),
+ 'access' => $row['access'],
+ /// Everyone is always immediately accepted, for now.
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ]);
+
+ }
+ return $result;
}
diff --git a/lib/CalDAV/SharedCalendar.php b/lib/CalDAV/SharedCalendar.php
index 1e3fc4c..96d630f 100644
--- a/lib/CalDAV/SharedCalendar.php
+++ b/lib/CalDAV/SharedCalendar.php
@@ -40,7 +40,7 @@ class SharedCalendar extends Calendar implements ISharedCalendar {
*/
function getShareResourceUri() {
- throw new \Exception('Not implemented');
+ return $this->calendarInfo['share-resource-uri'];
}
diff --git a/lib/CalDAV/Xml/Property/Invite.php b/lib/CalDAV/Xml/Property/Invite.php
index f9b0bac..40ff6b9 100644
--- a/lib/CalDAV/Xml/Property/Invite.php
+++ b/lib/CalDAV/Xml/Property/Invite.php
@@ -2,11 +2,9 @@
namespace Sabre\CalDAV\Xml\Property;
-use Sabre\Xml\Element;
-use Sabre\Xml\Reader;
+use Sabre\Xml\XmlSerializable;
use Sabre\Xml\Writer;
use Sabre\CalDAV\Plugin;
-use Sabre\CalDAV\SharingPlugin;
use Sabre\DAV;
/**
@@ -21,53 +19,23 @@ use Sabre\DAV;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Invite implements Element {
+class Invite implements XmlSerializable {
/**
* The list of users a calendar has been shared to.
*
- * @var array
+ * @var Sharee[]
*/
- protected $users;
-
- /**
- * The organizer contains information about the person who shared the
- * object.
- *
- * @var array
- */
- protected $organizer;
+ protected $sharees;
/**
* Creates the property.
*
- * Users is an array. Each element of the array has the following
- * properties:
- *
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first and lastname for a user.
- * * status - One of the SharingPlugin::STATUS_* constants.
- * * readOnly - true or false
- * * summary - Optional, description of the share
- *
- * The organizer key is optional to specify. It's only useful when a
- * 'sharee' requests the sharing information.
- *
- * The organizer may have the following properties:
- * * href - Often a mailto: address.
- * * commonName - Optional human-readable name.
- * * firstName - Optional first name.
- * * lastName - Optional last name.
- *
- * If you wonder why these two structures are so different, I guess a
- * valid answer is that the current spec is still a draft.
- *
- * @param array $users
+ * @param Sharee[] $sharees
*/
- function __construct(array $users, array $organizer = null) {
+ function __construct(array $sharees) {
- $this->users = $users;
- $this->organizer = $organizer;
+ $this->sharees = $sharees;
}
@@ -78,7 +46,7 @@ class Invite implements Element {
*/
function getValue() {
- return $this->users;
+ return $this->sharees;
}
@@ -105,149 +73,55 @@ class Invite implements Element {
$cs = '{' . Plugin::NS_CALENDARSERVER . '}';
- if (!is_null($this->organizer)) {
-
- $writer->startElement($cs . 'organizer');
- $writer->writeElement('{DAV:}href', $this->organizer['href']);
-
- if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
- $writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
- }
- if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
- $writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
- }
- if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
- $writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
- }
- $writer->endElement(); // organizer
+ foreach ($this->sharees as $sharee) {
- }
-
- foreach ($this->users as $user) {
-
- $writer->startElement($cs . 'user');
- $writer->writeElement('{DAV:}href', $user['href']);
- if (isset($user['commonName']) && $user['commonName']) {
- $writer->writeElement($cs . 'common-name', $user['commonName']);
- }
- switch ($user['status']) {
-
- case DAV\Sharing\Plugin::INVITE_ACCEPTED :
- $writer->writeElement($cs . 'invite-accepted');
- break;
- case DAV\Sharing\Plugin::INVITE_DECLINED :
- $writer->writeElement($cs . 'invite-declined');
- break;
- case DAV\Sharing\Plugin::INVITE_NORESPONSE :
- $writer->writeElement($cs . 'invite-noresponse');
- break;
- case DAV\Sharing\Plugin::INVITE_INVALID :
- $writer->writeElement($cs . 'invite-invalid');
- break;
- }
-
- $writer->startElement($cs . 'access');
- if ($user['readOnly']) {
- $writer->writeElement($cs . 'read');
+ if ($sharee->access === \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER) {
+ $writer->startElement($cs . 'organizer');
} else {
- $writer->writeElement($cs . 'read-write');
- }
- $writer->endElement(); // access
-
- if (isset($user['summary']) && $user['summary']) {
- $writer->writeElement($cs . 'summary', $user['summary']);
- }
-
- $writer->endElement(); //user
-
- }
-
- }
-
- /**
- * The deserialize method is called during xml parsing.
- *
- * This method is called statictly, this is because in theory this method
- * may be used as a type of constructor, or factory method.
- *
- * Often you want to return an instance of the current class, but you are
- * free to return other data as well.
- *
- * You are responsible for advancing the reader to the next element. Not
- * doing anything will result in a never-ending loop.
- *
- * If you just want to skip parsing for this element altogether, you can
- * just call $reader->next();
- *
- * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
- * the next element.
- *
- * @param Reader $reader
- * @return mixed
- */
- static function xmlDeserialize(Reader $reader) {
-
- $cs = '{' . Plugin::NS_CALENDARSERVER . '}';
-
- $users = [];
-
- foreach ($reader->parseInnerTree() as $elem) {
+ $writer->startElement($cs . 'user');
- if ($elem['name'] !== $cs . 'user')
- continue;
-
- $user = [
- 'href' => null,
- 'commonName' => null,
- 'readOnly' => null,
- 'summary' => null,
- 'status' => null,
- ];
-
- foreach ($elem['value'] as $userElem) {
-
- switch ($userElem['name']) {
- case $cs . 'invite-accepted' :
- $user['status'] = DAV\Sharing\Plugin::INVITE_ACCEPTED;
- break;
- case $cs . 'invite-declined' :
- $user['status'] = DAV\Sharing\Plugin::INVITE_DECLINED;
+ switch ($sharee->inviteStatus) {
+ case DAV\Sharing\Plugin::INVITE_ACCEPTED :
+ $writer->writeElement($cs . 'invite-accepted');
break;
- case $cs . 'invite-noresponse' :
- $user['status'] = DAV\Sharing\Plugin::INVITE_NORESPONSE;
+ case DAV\Sharing\Plugin::INVITE_DECLINED :
+ $writer->writeElement($cs . 'invite-declined');
break;
- case $cs . 'invite-invalid' :
- $user['status'] = DAV\Sharing\Plugin::INVITE_INVALID;
+ case DAV\Sharing\Plugin::INVITE_NORESPONSE :
+ $writer->writeElement($cs . 'invite-noresponse');
break;
- case '{DAV:}href' :
- $user['href'] = $userElem['value'];
+ case DAV\Sharing\Plugin::INVITE_INVALID :
+ $writer->writeElement($cs . 'invite-invalid');
break;
- case $cs . 'common-name' :
- $user['commonName'] = $userElem['value'];
- break;
- case $cs . 'access' :
- foreach ($userElem['value'] as $accessHref) {
- if ($accessHref['name'] === $cs . 'read') {
- $user['readOnly'] = true;
- }
- }
+ }
+
+ $writer->startElement($cs . 'access');
+ switch ($sharee->access) {
+ case DAV\Sharing\Plugin::ACCESS_READWRITE :
+ $writer->writeElement($cs . 'read-write');
break;
- case $cs . 'summary' :
- $user['summary'] = $userElem['value'];
+ case DAV\Sharing\Plugin::ACCESS_READ :
+ $writer->writeElement($cs . 'read');
break;
}
+ $writer->endElement(); // access
}
- if (!$user['status']) {
- throw new \InvalidArgumentException('Every user must have one of cs:invite-accepted, cs:invite-declined, cs:invite-noresponse or cs:invite-invalid');
- }
- $users[] = $user;
+ $href = new \Sabre\DAV\Xml\Property\Href($sharee->href);
+ $href->xmlSerialize($writer);
- }
+ if (isset($sharee->properties['{DAV:}displayname'])) {
+ $writer->writeElement($cs . 'common-name', $sharee->properties['{DAV:}displayname']);
+ }
+ if ($sharee->comment) {
+ $writer->writeElement($cs . 'summary', $sharee->comment);
+ }
+ $writer->endElement(); // organizer or user
- return new self($users);
+ }
}
+
}
diff --git a/lib/DAV/Sharing/Plugin.php b/lib/DAV/Sharing/Plugin.php
index 10bea95..8db4137 100644
--- a/lib/DAV/Sharing/Plugin.php
+++ b/lib/DAV/Sharing/Plugin.php
@@ -16,7 +16,7 @@ use Sabre\HTTP\ResponseInterface;
/**
* This plugin implements HTTP requests and properties related to:
*
- * draft-pot-webdav-resource-sharing-02
+ * draft-pot-webdav-resource-sharing
*
* This specification allows people to share webdav resources with others.
*
diff --git a/tests/Sabre/CalDAV/Xml/Property/InviteTest.php b/tests/Sabre/CalDAV/Xml/Property/InviteTest.php
index a954a9c..647139a 100644
--- a/tests/Sabre/CalDAV/Xml/Property/InviteTest.php
+++ b/tests/Sabre/CalDAV/Xml/Property/InviteTest.php
@@ -4,6 +4,8 @@ namespace Sabre\CalDAV\Xml\Property;
use Sabre\CalDAV;
use Sabre\DAV;
+use Sabre\DAV\Xml\Element\Sharee;
+use Sabre\DAV\Sharing\Plugin as SP;
class InviteTest extends DAV\Xml\XmlTest {
@@ -28,35 +30,36 @@ class InviteTest extends DAV\Xml\XmlTest {
function testSerialize() {
$property = new Invite([
- [
- 'href' => 'mailto:user1 at example.org',
- 'status' => DAV\Sharing\Plugin::INVITE_ACCEPTED,
- 'readOnly' => false,
- ],
- [
- 'href' => 'mailto:user2 at example.org',
- 'commonName' => 'John Doe',
- 'status' => DAV\Sharing\Plugin::INVITE_DECLINED,
- 'readOnly' => true,
- ],
- [
- 'href' => 'mailto:user3 at example.org',
- 'commonName' => 'Joe Shmoe',
- 'status' => DAV\Sharing\Plugin::INVITE_NORESPONSE,
- 'readOnly' => true,
- 'summary' => 'Something, something',
- ],
- [
- 'href' => 'mailto:user4 at example.org',
- 'commonName' => 'Hoe Boe',
- 'status' => DAV\Sharing\Plugin::INVITE_INVALID,
- 'readOnly' => true,
- ],
- ], [
- 'href' => 'mailto:thedoctor at example.org',
- 'commonName' => 'The Doctor',
- 'firstName' => 'The',
- 'lastName' => 'Doctor',
+ new Sharee([
+ 'href' => 'mailto:thedoctor at example.org',
+ 'properties' => ['{DAV:}displayname' => 'The Doctor'],
+ 'inviteStatus' => SP::INVITE_ACCEPTED,
+ 'access' => SP::ACCESS_SHAREDOWNER,
+ ]),
+ new Sharee([
+ 'href' => 'mailto:user1 at example.org',
+ 'inviteStatus' => SP::INVITE_ACCEPTED,
+ 'access' => SP::ACCESS_READWRITE,
+ ]),
+ new Sharee([
+ 'href' => 'mailto:user2 at example.org',
+ 'properties' => ['{DAV:}displayname' => 'John Doe'],
+ 'inviteStatus' => SP::INVITE_DECLINED,
+ 'access' => SP::ACCESS_READ,
+ ]),
+ new Sharee([
+ 'href' => 'mailto:user3 at example.org',
+ 'properties' => ['{DAV:}displayname' => 'Joe Shmoe'],
+ 'inviteStatus' => SP::INVITE_NORESPONSE,
+ 'access' => SP::ACCESS_READ,
+ 'comment' => 'Something, something',
+ ]),
+ new Sharee([
+ 'href' => 'mailto:user4 at example.org',
+ 'properties' => ['{DAV:}displayname' => 'Hoe Boe'],
+ 'inviteStatus' => SP::INVITE_INVALID,
+ 'access' => SP::ACCESS_READ,
+ ]),
]);
$xml = $this->write(['{DAV:}root' => $property]);
@@ -67,119 +70,42 @@ class InviteTest extends DAV\Xml\XmlTest {
<cs:organizer>
<d:href>mailto:thedoctor at example.org</d:href>
<cs:common-name>The Doctor</cs:common-name>
- <cs:first-name>The</cs:first-name>
- <cs:last-name>Doctor</cs:last-name>
</cs:organizer>
<cs:user>
- <d:href>mailto:user1 at example.org</d:href>
<cs:invite-accepted/>
<cs:access>
<cs:read-write/>
</cs:access>
+ <d:href>mailto:user1 at example.org</d:href>
</cs:user>
<cs:user>
- <d:href>mailto:user2 at example.org</d:href>
- <cs:common-name>John Doe</cs:common-name>
<cs:invite-declined/>
<cs:access>
<cs:read/>
</cs:access>
+ <d:href>mailto:user2 at example.org</d:href>
+ <cs:common-name>John Doe</cs:common-name>
</cs:user>
<cs:user>
- <d:href>mailto:user3 at example.org</d:href>
- <cs:common-name>Joe Shmoe</cs:common-name>
<cs:invite-noresponse/>
<cs:access>
<cs:read/>
</cs:access>
+ <d:href>mailto:user3 at example.org</d:href>
+ <cs:common-name>Joe Shmoe</cs:common-name>
<cs:summary>Something, something</cs:summary>
</cs:user>
<cs:user>
- <d:href>mailto:user4 at example.org</d:href>
- <cs:common-name>Hoe Boe</cs:common-name>
<cs:invite-invalid/>
<cs:access>
<cs:read/>
</cs:access>
+ <d:href>mailto:user4 at example.org</d:href>
+ <cs:common-name>Hoe Boe</cs:common-name>
</cs:user>
</d:root>
', $xml);
}
- /**
- * @depends testSerialize
- */
- function testUnserialize() {
-
- $input = [
- [
- 'href' => 'mailto:user1 at example.org',
- 'status' => DAV\Sharing\Plugin::INVITE_ACCEPTED,
- 'readOnly' => false,
- 'commonName' => '',
- 'summary' => '',
- ],
- [
- 'href' => 'mailto:user2 at example.org',
- 'commonName' => 'John Doe',
- 'status' => DAV\Sharing\Plugin::INVITE_DECLINED,
- 'readOnly' => true,
- 'summary' => '',
- ],
- [
- 'href' => 'mailto:user3 at example.org',
- 'commonName' => 'Joe Shmoe',
- 'status' => DAV\Sharing\Plugin::INVITE_NORESPONSE,
- 'readOnly' => true,
- 'summary' => 'Something, something',
- ],
- [
- 'href' => 'mailto:user4 at example.org',
- 'commonName' => 'Hoe Boe',
- 'status' => DAV\Sharing\Plugin::INVITE_INVALID,
- 'readOnly' => true,
- 'summary' => '',
- ],
- ];
-
- // Creating the xml
- $inputProperty = new Invite($input);
- $xml = $this->write(['{DAV:}root' => $inputProperty]);
- // Parsing it again
-
- $doc2 = $this->parse(
- $xml,
- ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\Invite']
- );
-
- $outputProperty = $doc2['value'];
-
- $this->assertEquals($input, $outputProperty->getValue());
-
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- function testUnserializeNoStatus() {
-
-$xml = '<?xml version="1.0"?>
-<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
- <cs:user>
- <d:href>mailto:user1 at example.org</d:href>
- <!-- <cs:invite-accepted/> -->
- <cs:access>
- <cs:read-write/>
- </cs:access>
- </cs:user>
-</d:root>';
-
- $this->parse(
- $xml,
- ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\Invite']
- );
-
- }
-
}
--
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