]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add publicuri to oc_dav_shares table and start working with it
authorThomas Citharel <tcit@tcit.fr>
Mon, 1 Aug 2016 14:44:28 +0000 (16:44 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Mon, 26 Sep 2016 09:55:39 +0000 (11:55 +0200)
apps/dav/appinfo/database.xml
apps/dav/appinfo/info.xml
apps/dav/lib/CalDAV/CalDavBackend.php
apps/dav/lib/CalDAV/PublicCalendarRoot.php

index 9578526a7051a1552aabc0c195980d30e24beaaf..eb8f70e7c95129a65252c2d92daa4cff58eedeaa 100644 (file)
@@ -703,6 +703,11 @@ CREATE TABLE calendarobjects (
                                <notnull>true</notnull>
                                <unsigned>true</unsigned>
                        </field>
+                       <field>
+                               <name>publicuri</name>
+                               <type>text</type>
+                               <length>255</length>
+                       </field>
                        <index>
                                <name>dav_shares_index</name>
                                <unique>true</unique>
@@ -715,6 +720,9 @@ CREATE TABLE calendarobjects (
                                <field>
                                        <name>type</name>
                                </field>
+                               <field>
+                                       <name>publicuri</name>
+                               </field>
                        </index>
                </declaration>
        </table>
index 19b65d84327e627f1b84086a7888da7e0b3e3966..33621ce70aa32fe640885cdedb2a15f884557fce 100644 (file)
@@ -5,7 +5,7 @@
        <description>WebDAV endpoint</description>
        <licence>AGPL</licence>
        <author>owncloud.org</author>
-       <version>1.1.0</version>
+       <version>1.1.1</version>
        <default_enable/>
        <types>
                <filesystem/>
index 1be8db160cba09794fff0f2cb22ca76e50e437bf..2daecc7249666ac2015cf12039034d7a09edbe4c 100644 (file)
@@ -316,6 +316,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
                $fields[] = 'a.principaluri';
                $fields[] = 'a.transparent';
                $fields[] = 's.access';
+               $fields[] = 's.publicuri';
                $calendars = [];
                $query = $this->db->getQueryBuilder();
                $result = $query->select($fields)
@@ -332,10 +333,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
                        if ($row['components']) {
                                $components = explode(',',$row['components']);
                        }
-                       $uri = md5($this->config->getSystemValue('secret', '') . $row['id']);
                        $calendar = [
                                'id' => $row['id'],
-                               'uri' => $uri,
+                               'uri' => $row['publicuri'],
                                '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',
@@ -361,18 +361,62 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
 
        /**
         * @param string $uri
-        * @return Calendar
+        * @return array
         * @throws NotFound
         */
        public function getPublicCalendar($uri) {
-               $l10n = \OC::$server->getL10N('dav');
-               foreach ($this->getPublicCalendars() as $calendar) {
-                       if ($calendar['uri'] === $uri) {
-                               // TODO: maybe implement a new class PublicCalendar ???
-                               return new Calendar($this, $calendar, $l10n);
-                       }
+               $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';
+               $fields[] = 's.publicuri';
+               $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')))
+                       ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri)))
+                       ->execute();
+
+               $row = $result->fetch(\PDO::FETCH_ASSOC);
+
+               $result->closeCursor();
+
+               if ($row === false) {
+                       throw new NotFound('Node with name \'' . $uri . '\' could not be found');
                }
-               throw new NotFound('Node with name \'' . $uri . '\' could not be found');
+
+               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,
+                       '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC,
+               ];
+
+               foreach($this->propertyMap as $xmlName=>$dbName) {
+                       $calendar[$xmlName] = $row[$dbName];
+               }
+
+               return array_values($calendar);
+
        }
 
        /**
@@ -1563,7 +1607,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
                                        'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()),
                                        'type' => $query->createNamedParameter('calendar'),
                                        'access' => $query->createNamedParameter(self::ACCESS_PUBLIC),
-                                       'resourceid' => $query->createNamedParameter($calendar->getResourceId())
+                                       'resourceid' => $query->createNamedParameter($calendar->getResourceId()),
+                                       'publicuri' => $query->createNamedParameter(md5($this->config->getSystemValue('secret', '') . $calendar->getResourceId()))
                                ]);
                } else {
                        $query->delete('dav_shares')
index b8d209d7073f568febe1c886f593ce00bceb49a8..6d74b97f96ea92581582b306b92356faa6b27d7d 100644 (file)
@@ -47,7 +47,8 @@ class PublicCalendarRoot extends Collection {
         * @inheritdoc
         */
        function getChild($name) {
-               return $this->caldavBackend->getPublicCalendar($name);
+               $calendar = $this->caldavBackend->getPublicCalendar($name);
+               return new Calendar($this->caldavBackend, $calendar, $this->l10n);
        }
 
        /**