Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
69d3601
Proper work on Publishing
tcitworld Jul 6, 2016
5824c24
Make little corrections
tcitworld Jul 6, 2016
981c38f
Remove unnecessary implementation
tcitworld Jul 6, 2016
1652a74
Fix publish-url property & getPublishStatus() fct
tcitworld Jul 6, 2016
4a0e6e2
Remove unnecessary line
tcitworld Jul 7, 2016
f89961d
Fix annotations
tcitworld Jul 7, 2016
72f35f8
Use ressource ID instead of name
tcitworld Jul 7, 2016
7e5a82b
Use urlgenerator to generate an absolute url
tcitworld Jul 7, 2016
bd0aae8
No need to call database twice
tcitworld Jul 7, 2016
8da2100
Start work on returning CalDAV published calendars
tcitworld Jul 7, 2016
90ab6e4
Add new root collection public-calendars which holds all public calen…
DeepDiver1975 Jul 8, 2016
e7085aa
Allow not-authenticated access to specific urls
DeepDiver1975 Jul 8, 2016
00dc157
Fix requests for browser plugin as well as for the public calendar ro…
DeepDiver1975 Jul 11, 2016
994001c
Dirty hack to disable dav plugins on public calendar urls
tcitworld Jul 11, 2016
aca3053
Fix DB call for MySQL databases
tcitworld Jul 12, 2016
2df69ec
correct get published status and minor fixes
tcitworld Jul 12, 2016
f09c46d
Fix some tests
tcitworld Jul 12, 2016
aadb56d
Fix wrong way to get publish status
tcitworld Jul 18, 2016
e783d01
Allow public access to the principals/system/public
DeepDiver1975 Jul 19, 2016
d0ec6b9
Disable OPTIONS handling - done by sabre
DeepDiver1975 Jul 19, 2016
77216e7
a few tests
tcitworld Jul 20, 2016
de5e212
fix plugin test
tcitworld Jul 20, 2016
ebf2377
fix unpublishing test
tcitworld Jul 20, 2016
3921385
fix things (indentation, tests, comments, backend custom implementation
tcitworld Jul 31, 2016
762726d
fix indent once and for all
tcitworld Aug 1, 2016
1899116
move getPublicCalendar inside the caldav backend
tcitworld Aug 1, 2016
dd248ca
fix some bracket positions
tcitworld Aug 1, 2016
691b3ab
Add publicuri to oc_dav_shares table and start working with it
tcitworld Aug 1, 2016
9af2a9f
test serializer
tcitworld Aug 1, 2016
8433c3c
fix getChild()
tcitworld Aug 3, 2016
a4fe596
add space between calendarname and owner name
tcitworld Aug 11, 2016
f16ea48
add can-be-published property
tcitworld Aug 12, 2016
f0421e1
add missing tests
tcitworld Aug 14, 2016
6378dbc
fix can-be-published
tcitworld Aug 14, 2016
ad0eeaa
use AllowedSharingModes for can-be-published & can-be-shared
tcitworld Aug 15, 2016
3e9a346
add calendarserver-sharing to the list of advertised features
tcitworld Aug 16, 2016
ff67cbc
Add test for PublicCalendarRoot
tcitworld Aug 18, 2016
2fff203
Add missing constructor argument
LukasReschke Aug 30, 2016
4659e3a
Add new constructor args
LukasReschke Aug 30, 2016
d884370
Use true random string as uri for public calendars - as a result we c…
DeepDiver1975 Sep 3, 2016
8360222
fix public calendars
tcitworld Sep 14, 2016
17d5dfd
add in same request
tcitworld Sep 15, 2016
9c75b00
fix tests
tcitworld Sep 15, 2016
dcc2311
fix annotations & copyright headers
tcitworld Sep 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/dav/appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -715,6 +720,9 @@ CREATE TABLE calendarobjects (
<field>
<name>type</name>
</field>
<field>
<name>publicuri</name>
</field>
</index>
</declaration>
</table>
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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/>
Expand Down
5 changes: 4 additions & 1 deletion apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
'principals/'
);
$db = \OC::$server->getDatabaseConnection();
$calDavBackend = new CalDavBackend($db, $principalBackend, \OC::$server->getUserManager());
$config = \OC::$server->getConfig();
$userManager = \OC::$server->getUserManager();
$random = \OC::$server->getSecureRandom();
$calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, $config, $random);

$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);

Expand Down
178 changes: 177 additions & 1 deletion apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\DAV\Sharing\Backend;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use Sabre\CalDAV\Backend\AbstractBackend;
use Sabre\CalDAV\Backend\SchedulingSupport;
use Sabre\CalDAV\Backend\SubscriptionSupport;
Expand All @@ -41,6 +43,7 @@
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
use Sabre\DAV;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\PropPatch;
use Sabre\HTTP\URLUtil;
use Sabre\VObject\DateTimeParser;
Expand All @@ -66,6 +69,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;
Expand Down Expand Up @@ -117,19 +121,33 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription

/** @var IUserManager */
private $userManager;

/** @var IConfig */
private $config;

/** @var ISecureRandom */
private $random;

/**
* CalDavBackend constructor.
*
* @param IDBConnection $db
* @param Principal $principalBackend
* @param IUserManager $userManager
* @param IConfig $config
* @param ISecureRandom $random
*/
public function __construct(IDBConnection $db, Principal $principalBackend, IUserManager $userManager) {
public function __construct(IDBConnection $db,
Principal $principalBackend,
IUserManager $userManager,
IConfig $config,
ISecureRandom $random) {
$this->db = $db;
$this->principalBackend = $principalBackend;
$this->userManager = $userManager;
$this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar');
$this->config = $config;
$this->random = $random;
}

/**
Expand Down Expand Up @@ -295,6 +313,120 @@ private function getUserDisplayName($uid) {

return $this->userDisplayNames[$uid];
}

/**
* @return array
*/
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';
$fields[] = 's.publicuri';
$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']);
}
$calendar = [
'id' => $row['id'],
'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',
'{' . 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];
}

if (!isset($calendars[$calendar['id']])) {
$calendars[$calendar['id']] = $calendar;
}
}
$result->closeCursor();

return array_values($calendars);
}

/**
* @param string $uri
* @return array
* @throws NotFound
*/
public function getPublicCalendar($uri) {
$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');
}

list(, $name) = URLUtil::splitPath($row['principaluri']);
$row['displayname'] = $row['displayname'] . ' ' . "($name)";
$components = [];
if ($row['components']) {
$components = explode(',',$row['components']);
}
$calendar = [
'id' => $row['id'],
'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',
'{' . 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 $calendar;

}

/**
* @param string $principal
Expand Down Expand Up @@ -1472,6 +1604,50 @@ public function getShares($resourceId) {
return $this->sharingBackend->getShares($resourceId);
}

/**
* @param boolean $value
* @param \OCA\DAV\CalDAV\Calendar $calendar
* @return string|null
*/
public function setPublishStatus($value, $calendar) {
$query = $this->db->getQueryBuilder();
if ($value) {
$publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS);
$query->insert('dav_shares')
->values([
'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()),
'type' => $query->createNamedParameter('calendar'),
'access' => $query->createNamedParameter(self::ACCESS_PUBLIC),
'resourceid' => $query->createNamedParameter($calendar->getResourceId()),
'publicuri' => $query->createNamedParameter($publicUri)
]);
$query->execute();
return $publicUri;
}
$query->delete('dav_shares')
->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId())))
->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC)));
$query->execute();
return null;
}

/**
* @param \OCA\DAV\CalDAV\Calendar $calendar
* @return mixed
*/
public function getPublishStatus($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 $row ? reset($row) : false;
}

/**
* @param int $resourceId
* @param array $acl
Expand Down
39 changes: 39 additions & 0 deletions apps/dav/lib/CalDAV/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public function getResourceId() {
return $this->calendarInfo['id'];
}

/**
* @return string
*/
public function getPrincipalURI() {
return $this->calendarInfo['principaluri'];
}

function getACL() {
$acl = [
[
Expand Down Expand Up @@ -117,6 +124,13 @@ function getACL() {
];
}
}
if ($this->isPublic()) {
$acl[] = [
'privilege' => '{DAV:}read',
'principal' => 'principals/system/public',
'protected' => true,
];
}

/** @var CalDavBackend $calDavBackend */
$calDavBackend = $this->caldavBackend;
Expand Down Expand Up @@ -236,15 +250,40 @@ function calendarQuery(array $filters) {
return $uris;
}

/**
* @param boolean $value
* @return string|null
*/
function setPublishStatus($value) {
$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
$this->calendarInfo['publicuri'] = $publicUri;
return $publicUri;
}

/**
* @return mixed $value
*/
function getPublishStatus() {
return $this->caldavBackend->getPublishStatus($this);
}

private function canWrite() {
if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
}
return true;
}

private function isPublic() {
return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
}

private function isShared() {
return isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']);
}

public function isSubscription() {
return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
}

}
Loading