Start work on returning CalDAV published calendars

This commit is contained in:
Thomas Citharel 2016-07-07 16:28:30 +02:00 committed by Lukas Reschke
parent bd0aae8636
commit 8da2100e7d
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
3 changed files with 63 additions and 3 deletions

View File

@ -1513,6 +1513,34 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return $row;
}
/**
* @param string $token
* @param string secret
* @return int | boolean
*
* Function to get the ressource we're insteressed in. Most probably to put somewhere else.
*/
public function getResourceIdFromToken($token, $secret) {
$query = $this->db->getQueryBuilder();
$result = $query->select('resourceid')
->from('dav_shares')
->where($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC)))
->execute();
$publications = [];
while($row = $result->fetch()) {
$publications[] = $row['resourceid'];
}
$i = 0;
$found = false;
while ($i < count($publications) && !$found) {
$found = md5($secret.$publications[$i]) === $token;
if (!$found) $i++;
}
return ($found) ? $publications[$i] : false;
}
/**
* @param int $resourceId
* @param array $acl

View File

@ -59,7 +59,7 @@ class PublishPlugin extends ServerPlugin
*/
public function getFeatures()
{
return ['oc-calendar-publishing'];
return ['oc-calendar-publishing']; // May have to be changed to be detected
}
/**
@ -91,6 +91,7 @@ class PublishPlugin extends ServerPlugin
$this->server->on('method:POST', [$this, 'httpPost']);
$this->server->on('propFind', [$this, 'propFind']);
$this->server->on('method:GET', [$this, 'httpGet'], 90); // 90 because it needs to be called before auth
}
public function propFind(PropFind $propFind, INode $node)
@ -102,12 +103,12 @@ class PublishPlugin extends ServerPlugin
$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $publishUrl) {
if ($node->getPublishStatus()) {
return new Publisher($publishUrl, true);
return new Publisher($publishUrl, true); // We return the publish-url only if the calendar is published.
}
});
$propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $publishUrl) {
return new Publisher($publishUrl, false);
return new Publisher($publishUrl, false); // The pre-publish-url is always returned
});
}
}
@ -209,4 +210,31 @@ class PublishPlugin extends ServerPlugin
}
}
/**
* We intercept the GET requests to provide our shared calendars.
*
* @param Sabre\HTTP\RequestInterface $request
* @param Sabre\HTTP\ResponseInterface $response
*/
public function httpGet(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
// TODO : Find a better way to do this
list($path, $token) = explode('/', $path);
if ($path !== 'public-calendars') {
return;
}
// This is where the magic happens
// Find a place to put the functions getResourceIdFromToken($token) and getRessource($id)
$this->server->transactionType = 'access-published-calendar';
$response->setStatus(200);
$response->setBody('Success !');
return false;
}
}

View File

@ -244,6 +244,10 @@ class FilesPlugin extends ServerPlugin {
* @param ResponseInterface $response
*/
function httpGet(RequestInterface $request, ResponseInterface $response) {
// Exclude published calendars
// TODO : Find a better way to do this
if (explode('/', $request->getPath())[0] === 'public-calendars') return;
// Only handle valid files
$node = $this->tree->getNodeForPath($request->getPath());
if (!($node instanceof IFile)) return;