diff options
author | Mario Vavti <mario@mariovavti.com> | 2016-05-28 17:46:24 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2016-05-28 17:46:24 +0200 |
commit | 66effbfe0827fc61fff6d248797a894213ad20d6 (patch) | |
tree | 0fbb5ca644e1140e5b3b44b1adc874043790c388 /vendor/sabre/dav/lib/CalDAV/SharingPlugin.php | |
parent | ac4688eac087854bf8cb0c893d7a79052ad63a20 (diff) | |
download | volse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.tar.gz volse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.tar.bz2 volse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.zip |
upgrade to sabre32
Diffstat (limited to 'vendor/sabre/dav/lib/CalDAV/SharingPlugin.php')
-rw-r--r-- | vendor/sabre/dav/lib/CalDAV/SharingPlugin.php | 106 |
1 files changed, 41 insertions, 65 deletions
diff --git a/vendor/sabre/dav/lib/CalDAV/SharingPlugin.php b/vendor/sabre/dav/lib/CalDAV/SharingPlugin.php index 5154fb1de..6f7df02bc 100644 --- a/vendor/sabre/dav/lib/CalDAV/SharingPlugin.php +++ b/vendor/sabre/dav/lib/CalDAV/SharingPlugin.php @@ -4,6 +4,7 @@ namespace Sabre\CalDAV; use Sabre\DAV; use Sabre\DAV\Xml\Property\Href; +use Sabre\DAV\Xml\Property\LocalHref; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; @@ -26,15 +27,6 @@ use Sabre\HTTP\ResponseInterface; class SharingPlugin extends DAV\ServerPlugin { /** - * These are the various status constants used by sharing-messages. - */ - const STATUS_ACCEPTED = 1; - const STATUS_DECLINED = 2; - const STATUS_DELETED = 3; - const STATUS_NORESPONSE = 4; - const STATUS_INVALID = 5; - - /** * Reference to SabreDAV server object. * * @var Sabre\DAV\Server @@ -83,7 +75,10 @@ class SharingPlugin extends DAV\ServerPlugin { function initialize(DAV\Server $server) { $this->server = $server; - $server->resourceTypeMapping['Sabre\\CalDAV\\ISharedCalendar'] = '{' . Plugin::NS_CALENDARSERVER . '}shared'; + + if (is_null($this->server->getPlugin('sharing'))) { + throw new \LogicException('The generic "sharing" plugin must be loaded before the caldav sharing plugin. Call $server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); before this one.'); + } array_push( $this->server->protectedProperties, @@ -114,24 +109,8 @@ class SharingPlugin extends DAV\ServerPlugin { */ function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { - if ($node instanceof IShareableCalendar) { - - $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function() use ($node) { - return new Xml\Property\Invite( - $node->getShares() - ); - }); - - } - if ($node instanceof ISharedCalendar) { - $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}shared-url', function() use ($node) { - return new Href( - $node->getSharedUrl() - ); - }); - $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function() use ($node) { // Fetching owner information @@ -158,7 +137,7 @@ class SharingPlugin extends DAV\ServerPlugin { } return new Xml\Property\Invite( - $node->getShares(), + $node->getInvites(), $ownerInfo ); @@ -179,10 +158,18 @@ class SharingPlugin extends DAV\ServerPlugin { */ function propFindLate(DAV\PropFind $propFind, DAV\INode $node) { - if ($node instanceof IShareableCalendar) { + if ($node instanceof ISharedCalendar) { + $shareAccess = $node->getShareAccess(); if ($rt = $propFind->get('{DAV:}resourcetype')) { - if (count($node->getShares()) > 0) { - $rt->add('{' . Plugin::NS_CALENDARSERVER . '}shared-owner'); + switch ($shareAccess) { + case \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER : + $rt->add('{' . Plugin::NS_CALENDARSERVER . '}shared-owner'); + break; + case \Sabre\DAV\Sharing\Plugin::ACCESS_READ : + case \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE : + $rt->add('{' . Plugin::NS_CALENDARSERVER . '}shared'); + break; + } } $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', function() { @@ -211,21 +198,24 @@ class SharingPlugin extends DAV\ServerPlugin { function propPatch($path, DAV\PropPatch $propPatch) { $node = $this->server->tree->getNodeForPath($path); - if (!$node instanceof IShareableCalendar) + if (!$node instanceof ISharedCalendar) return; - $propPatch->handle('{DAV:}resourcetype', function($value) use ($node) { - if ($value->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) return false; - $shares = $node->getShares(); - $remove = []; - foreach ($shares as $share) { - $remove[] = $share['href']; - } - $node->updateShares([], $remove); + if ($node->getShareAccess() === \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER || $node->getShareAccess() === \Sabre\DAV\Sharing\Plugin::ACCESS_NOTSHARED) { - return true; + $propPatch->handle('{DAV:}resourcetype', function($value) use ($node) { + if ($value->is('{' . Plugin::NS_CALENDARSERVER . '}shared-owner')) return false; + $shares = $node->getInvites(); + foreach ($shares as $share) { + $share->access = DAV\Sharing\Plugin::ACCESS_NOACCESS; + } + $node->updateInvites($shares); - }); + return true; + + }); + + } } @@ -267,26 +257,12 @@ class SharingPlugin extends DAV\ServerPlugin { switch ($documentType) { - // Dealing with the 'share' document, which modified invitees on a - // calendar. + // Both the DAV:share-resource and CALENDARSERVER:share requests + // behave identically. case '{' . Plugin::NS_CALENDARSERVER . '}share' : - // We can only deal with IShareableCalendar objects - if (!$node instanceof IShareableCalendar) { - return; - } - - $this->server->transactionType = 'post-calendar-share'; - - // Getting ACL info - $acl = $this->server->getPlugin('acl'); - - // If there's no ACL support, we allow everything - if ($acl) { - $acl->checkPrivileges($path, '{DAV:}write'); - } - - $node->updateShares($message->set, $message->remove); + $sharingPlugin = $this->server->getPlugin('sharing'); + $sharingPlugin->shareResource($path, $message->sharees); $response->setStatus(200); // Adding this because sending a response body may cause issues, @@ -328,11 +304,11 @@ class SharingPlugin extends DAV\ServerPlugin { $response->setHeader('X-Sabre-Status', 'everything-went-well'); if ($url) { - $writer = $this->server->xml->getWriter($this->server->getBaseUri()); + $writer = $this->server->xml->getWriter(); $writer->openMemory(); $writer->startDocument(); $writer->startElement('{' . Plugin::NS_CALENDARSERVER . '}shared-as'); - $writer->write(new Href($url)); + $writer->write(new LocalHref($url)); $writer->endElement(); $response->setHeader('Content-Type', 'application/xml'); $response->setBody($writer->outputMemory()); @@ -345,7 +321,7 @@ class SharingPlugin extends DAV\ServerPlugin { case '{' . Plugin::NS_CALENDARSERVER . '}publish-calendar' : // We can only deal with IShareableCalendar objects - if (!$node instanceof IShareableCalendar) { + if (!$node instanceof ISharedCalendar) { return; } $this->server->transactionType = 'post-publish-calendar'; @@ -355,7 +331,7 @@ class SharingPlugin extends DAV\ServerPlugin { // If there's no ACL support, we allow everything if ($acl) { - $acl->checkPrivileges($path, '{DAV:}write'); + $acl->checkPrivileges($path, '{DAV:}share'); } $node->setPublishStatus(true); @@ -373,7 +349,7 @@ class SharingPlugin extends DAV\ServerPlugin { case '{' . Plugin::NS_CALENDARSERVER . '}unpublish-calendar' : // We can only deal with IShareableCalendar objects - if (!$node instanceof IShareableCalendar) { + if (!$node instanceof ISharedCalendar) { return; } $this->server->transactionType = 'post-unpublish-calendar'; @@ -383,7 +359,7 @@ class SharingPlugin extends DAV\ServerPlugin { // If there's no ACL support, we allow everything if ($acl) { - $acl->checkPrivileges($path, '{DAV:}write'); + $acl->checkPrivileges($path, '{DAV:}share'); } $node->setPublishStatus(false); |