Make little corrections

Function getPublishedStatus) is not working atm.
pull/1197/head
Thomas Citharel 9 years ago committed by Lukas Reschke
parent 69d3601dcb
commit 5824c2493b
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
  1. 1
      apps/dav/appinfo/v1/caldav.php
  2. 5
      apps/dav/lib/CalDAV/CalDavBackend.php
  3. 45
      apps/dav/lib/CalDAV/Publishing/PublishPlugin.php
  4. 15
      apps/dav/lib/CalDAV/Publishing/Xml/Publisher.php

@ -71,7 +71,6 @@ $server->setBaseUri($baseuri);
$server->addPlugin(new MaintenancePlugin());
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
$server->addPlugin(new \Sabre\CalDAV\Plugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin());
$server->addPlugin(new LegacyDAVACL());
if ($debugging) {

@ -66,6 +66,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
*/
const MAX_DATE = '2038-01-01';
const ACCESS_PUBLIC = 4;
const CLASSIFICATION_PUBLIC = 0;
const CLASSIFICATION_PRIVATE = 1;
const CLASSIFICATION_CONFIDENTIAL = 2;
@ -1483,13 +1484,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->values([
'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()),
'type' => $query->createNamedParameter('calendar'),
'access' => $query->createNamedParameter(self::CLASSIFICATION_PUBLIC),
'access' => $query->createNamedParameter(self::ACCESS_PUBLIC),
'resourceid' => $query->createNamedParameter($calendar->getResourceId())
]);
} else {
$query->delete('dav_shares')
->Where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId())))
->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)));
->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC)));
}
$query->execute();
}

@ -6,13 +6,12 @@ namespace OCA\DAV\CalDAV\Publishing;
use Sabre\DAV\PropFind;
use Sabre\DAV\INode;
use OCP\IRequest;
use Sabre\CalDAV\IShareableCalendar;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use OCA\DAV\CalDAV\Publishing\Xml\Publisher;
use OCA\DAV\CalDAV\Calendar;
class PublishPlugin extends ServerPlugin
{
@ -70,36 +69,42 @@ class PublishPlugin extends ServerPlugin
$this->server->on('propFind', [$this, 'propFind']);
}
function propFind(PropFind $propFind, INode $node) {
if ($node instanceof IShareableCalendar) {
$token = md5(\OC::$server->getConfig()->getSystemValue('secret','') . $node->getName());
// $propFind->handle('{' . self::NS_CALENDARSERVER . '}publish-url', function() use ($node, $token) {
// return new Publisher($token);
// });
public function propFind(PropFind $propFind, INode $node)
{
if ($node instanceof Calendar) {
$token = md5(\OC::$server->getConfig()->getSystemValue('secret', '').$node->getName());
$propFind->handle('{' . self::NS_CALENDARSERVER . '}pre-publish-url', function() use ($node, $token) {
$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $token) {
if ($node->getPublishStatus()) {
return new Publisher($token);
return new Publisher($token, $node->getPublishStatus());
}
});
$propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $token) {
if ($node->getPublishStatus()) {
return new Publisher($token, false);
}
});
}
}
}
/**
* We intercept this to handle POST requests on calendars.
*
* @param RequestInterface $request
* @param ResponseInterface $response
*
* @return null|bool
*/
function httpPost(RequestInterface $request, ResponseInterface $response) {
public function httpPost(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
// Only handling xml
$contentType = $request->getHeader('Content-Type');
if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false)
if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
return;
}
// Making sure the node exists
try {
@ -123,11 +128,10 @@ class PublishPlugin extends ServerPlugin
switch ($documentType) {
case '{' . self::NS_CALENDARSERVER . '}publish-calendar' :
case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
// We can only deal with IShareableCalendar objects
if (!$node instanceof IShareableCalendar) {
if (!$node instanceof Calendar) {
return;
}
$this->server->transactionType = 'post-publish-calendar';
@ -152,10 +156,10 @@ class PublishPlugin extends ServerPlugin
// Breaking the event chain
return false;
case '{' . self::NS_CALENDARSERVER . '}unpublish-calendar' :
case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
// We can only deal with IShareableCalendar objects
if (!$node instanceof IShareableCalendar) {
if (!$node instanceof Calendar) {
return;
}
$this->server->transactionType = 'post-unpublish-calendar';
@ -180,8 +184,5 @@ class PublishPlugin extends ServerPlugin
return false;
}
}
}

@ -13,11 +13,18 @@ class Publisher implements XmlSerializable {
*/
protected $publishUrl;
/**
* @var $isPublished
*/
protected $isPublished;
/**
* @param str $publishUrl
* @param boolean $isPublished
*/
function __construct($publishUrl) {
function __construct($publishUrl, $isPublished) {
$this->publishUrl = $publishUrl;
$this->isPublished = $isPublished;
}
/**
@ -49,7 +56,11 @@ class Publisher implements XmlSerializable {
function xmlSerialize(Writer $writer) {
$cs = '{' . Plugin::NS_CALENDARSERVER . '}';
$writer->write($this->publishUrl);
if (!$this->isPublished) {
$writer->write($this->publishUrl);
} else {
$writer->writeElement('{DAV:}href', $this->publishUrl);
}
}
}

Loading…
Cancel
Save