From 83602225549d1df67403a333ed4a53e8a02d1619 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 14 Sep 2016 11:34:21 +0200 Subject: [PATCH] fix public calendars --- apps/dav/lib/CalDAV/CalDavBackend.php | 17 +++++++++++++++++ apps/dav/lib/CalDAV/Calendar.php | 4 ++++ .../dav/lib/CalDAV/Publishing/PublishPlugin.php | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 7b8c1be51f5..34bc0b3c8be 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1648,6 +1648,23 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription return reset($row) > 0; } + /** + * @param \OCA\DAV\CalDAV\Calendar $calendar + * @return string + */ + public function getPublishToken($calendar) { + $query = $this->db->getQueryBuilder(); + $result = $query->select('publicuri') + ->from('dav_shares') + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) + ->execute(); + + $row = $result->fetch(); + $result->closeCursor(); + return reset($row); + } + /** * @param int $resourceId * @param array $acl diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php index 5fe9be8957d..17cc4780f78 100644 --- a/apps/dav/lib/CalDAV/Calendar.php +++ b/apps/dav/lib/CalDAV/Calendar.php @@ -267,6 +267,10 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { return $this->caldavBackend->getPublishStatus($this); } + function getPublishToken() { + return $this->caldavBackend->getPublishToken($this); + } + private function canWrite() { if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; diff --git a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php index 0e5377d30c1..aaa2868a86d 100644 --- a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php +++ b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php @@ -97,7 +97,7 @@ class PublishPlugin extends ServerPlugin { $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { if ($node->getPublishStatus()) { // We return the publish-url only if the calendar is published. - $token = $node->getName(); + $token = $node->getPublishToken(); $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; return new Publisher($publishUrl, true); -- 2.39.5