]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add new root collection public-calendars which holds all public calendars
authorThomas Müller <thomas.mueller@tmit.eu>
Fri, 8 Jul 2016 14:13:34 +0000 (16:13 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Mon, 26 Sep 2016 09:55:36 +0000 (11:55 +0200)
apps/dav/lib/CalDAV/CalDavBackend.php
apps/dav/lib/CalDAV/PublicCalendarRoot.php [new file with mode: 0644]
apps/dav/lib/RootCollection.php

index b1d85e098082dbcd0752f93fe2a8e1917d4e09a3..303e97fd308f22e7bf8876cc8786b1b850096f80 100644 (file)
@@ -118,6 +118,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
 
        /** @var IUserManager */
        private $userManager;
+       
+       /** @var \OCP\IConfig */
+       private $config;
 
        /**
         * CalDavBackend constructor.
@@ -131,6 +134,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
                $this->principalBackend = $principalBackend;
                $this->userManager = $userManager;
                $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar');
+               // TODO: inject
+               $this->config = \OC::$server->getConfig();
        }
 
        /**
@@ -283,6 +288,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
                return array_values($calendars);
        }
 
+<<<<<<< HEAD
        private function getUserDisplayName($uid) {
                if (!isset($this->userDisplayNames[$uid])) {
                        $user = $this->userManager->get($uid);
@@ -295,6 +301,58 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
                }
 
                return $this->userDisplayNames[$uid];
+=======
+
+       public function getPublicCalendars() {
+               $fields = array_values($this->propertyMap);
+               $fields[] = 'a.id';
+               $fields[] = 'a.uri';
+               $fields[] = 'a.synctoken';
+               $fields[] = 'a.components';
+               $fields[] = 'a.principaluri';
+               $fields[] = 'a.transparent';
+               $fields[] = 's.access';
+               $calendars = [];
+               $query = $this->db->getQueryBuilder();
+               $result = $query->select($fields)
+                       ->from('dav_shares', 's')
+                       ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id'))
+                       ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC)))
+                       ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar')))
+                       ->execute();
+
+               while($row = $result->fetch()) {
+                       list(, $name) = URLUtil::splitPath($row['principaluri']);
+                       $row['displayname'] = $row['displayname'] . "($name)";
+                       $components = [];
+                       if ($row['components']) {
+                               $components = explode(',',$row['components']);
+                       }
+                       $uri = md5($this->config->getSystemValue('secret', '') . $row['id']);
+                       $calendar = [
+                               'id' => $row['id'],
+                               'uri' => $uri,
+                               'principaluri' => $row['principaluri'],
+                               '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
+                               '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
+                               '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components),
+                               '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
+                               '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $row['principaluri'],
+                               '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ,
+                       ];
+
+                       foreach($this->propertyMap as $xmlName=>$dbName) {
+                               $calendar[$xmlName] = $row[$dbName];
+                       }
+
+                       if (!isset($calendars[$calendar['id']])) {
+                               $calendars[$calendar['id']] = $calendar;
+                       }
+               }
+               $result->closeCursor();
+
+               return array_values($calendars);
+>>>>>>> bf223b9... Add new root collection public-calendars which holds all public calendars
        }
 
        /**
diff --git a/apps/dav/lib/CalDAV/PublicCalendarRoot.php b/apps/dav/lib/CalDAV/PublicCalendarRoot.php
new file mode 100644 (file)
index 0000000..f1ff23a
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OCA\DAV\CalDAV;
+
+use Sabre\DAV\Collection;
+
+class PublicCalendarRoot extends Collection {
+
+       /** @var CalDavBackend */
+       protected $caldavBackend;
+
+       function __construct(CalDavBackend $caldavBackend) {
+               $this->caldavBackend = $caldavBackend;
+       }
+
+       /**
+        * @inheritdoc
+        */
+       function getName() {
+               return 'public-calendars';
+       }
+
+       function getChild($name) {
+               // TODO: for performance reason this needs to have a custom implementation
+               return parent::getChild($name);
+       }
+
+       /**
+        * @inheritdoc
+        */
+       function getChildren() {
+               $l10n = \OC::$server->getL10N('dav');
+               $calendars = $this->caldavBackend->getPublicCalendars();
+               $children = [];
+               foreach ($calendars as $calendar) {
+                       // TODO: maybe implement a new class PublicCalendar ???
+                       $children[] = new Calendar($this->caldavBackend, $calendar, $l10n);
+               }
+
+               return $children;
+       }
+}
index 974d08bc34f87017cf541c84f5623e2990b9ed32..f7b9c7079a0d68153c8b6c321134345e9cdff146 100644 (file)
@@ -26,6 +26,7 @@ namespace OCA\DAV;
 
 use OCA\DAV\CalDAV\CalDavBackend;
 use OCA\DAV\CalDAV\CalendarRoot;
+use OCA\DAV\CalDAV\PublicCalendarRoot;
 use OCA\DAV\CardDAV\AddressBookRoot;
 use OCA\DAV\CardDAV\CardDavBackend;
 use OCA\DAV\Connector\Sabre\Principal;
@@ -62,6 +63,8 @@ class RootCollection extends SimpleCollection {
                $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager());
                $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
                $calendarRoot->disableListing = $disableListing;
+               $publicCalendarRoot = new PublicCalendarRoot($caldavBackend);
+               $publicCalendarRoot->disableListing = $disableListing;
 
                $systemTagCollection = new SystemTag\SystemTagsByIdCollection(
                        \OC::$server->getSystemTagManager(),
@@ -101,6 +104,7 @@ class RootCollection extends SimpleCollection {
                                                $systemPrincipals]),
                                $filesCollection,
                                $calendarRoot,
+                               $publicCalendarRoot,
                                new SimpleCollection('addressbooks', [
                                                $usersAddressBookRoot,
                                                $systemAddressBookRoot]),