Skip to content

Commit

Permalink
Add Public Calendar Provider
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <[email protected]>
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
miaulalala authored and ChristophWurst committed Oct 13, 2021
1 parent 581862b commit 116140b
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 10 deletions.
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'OCA\\DAV\\CalDAV\\CalendarImpl' => $baseDir . '/../lib/CalDAV/CalendarImpl.php',
'OCA\\DAV\\CalDAV\\CalendarManager' => $baseDir . '/../lib/CalDAV/CalendarManager.php',
'OCA\\DAV\\CalDAV\\CalendarObject' => $baseDir . '/../lib/CalDAV/CalendarObject.php',
'OCA\\DAV\\CalDAV\\CalendarProvider' => $baseDir . '/../lib/CalDAV/CalendarProvider.php',
'OCA\\DAV\\CalDAV\\CalendarRoot' => $baseDir . '/../lib/CalDAV/CalendarRoot.php',
'OCA\\DAV\\CalDAV\\ICSExportPlugin\\ICSExportPlugin' => $baseDir . '/../lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php',
'OCA\\DAV\\CalDAV\\IRestorable' => $baseDir . '/../lib/CalDAV/IRestorable.php',
Expand Down
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\CalDAV\\CalendarImpl' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarImpl.php',
'OCA\\DAV\\CalDAV\\CalendarManager' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarManager.php',
'OCA\\DAV\\CalDAV\\CalendarObject' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarObject.php',
'OCA\\DAV\\CalDAV\\CalendarProvider' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarProvider.php',
'OCA\\DAV\\CalDAV\\CalendarRoot' => __DIR__ . '/..' . '/../lib/CalDAV/CalendarRoot.php',
'OCA\\DAV\\CalDAV\\ICSExportPlugin\\ICSExportPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php',
'OCA\\DAV\\CalDAV\\IRestorable' => __DIR__ . '/..' . '/../lib/CalDAV/IRestorable.php',
Expand Down
18 changes: 9 additions & 9 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1845,17 +1845,18 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
$outerQuery->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)));

// only return public items for shared calendars for now
if ($calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) {
if (isset($calendarInfo['{http://owncloud.org/ns}owner-principal']) === false || $calendarInfo['principaluri'] !== $calendarInfo['{http://owncloud.org/ns}owner-principal']) {
$innerQuery->andWhere($innerQuery->expr()->eq('c.classification',
$outerQuery->createNamedParameter(self::CLASSIFICATION_PUBLIC)));
}

$or = $innerQuery->expr()->orX();
foreach ($searchProperties as $searchProperty) {
$or->add($innerQuery->expr()->eq('op.name',
$outerQuery->createNamedParameter($searchProperty)));
if (!empty($searchProperties)) {
$or = $innerQuery->expr()->orX();
foreach ($searchProperties as $searchProperty) {
$or->add($innerQuery->expr()->eq('op.name',
$outerQuery->createNamedParameter($searchProperty)));
}
}
$innerQuery->andWhere($or);

if ($pattern !== '') {
$innerQuery->andWhere($innerQuery->expr()->iLike('op.value',
Expand All @@ -1878,7 +1879,7 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
}
}

if (isset($options['types'])) {
if (!empty($options['types'])) {
$or = $outerQuery->expr()->orX();
foreach ($options['types'] as $type) {
$or->add($outerQuery->expr()->eq('componenttype',
Expand All @@ -1887,8 +1888,7 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
$outerQuery->andWhere($or);
}

$outerQuery->andWhere($outerQuery->expr()->in('c.id',
$outerQuery->createFunction($innerQuery->getSQL())));
$outerQuery->andWhere($outerQuery->expr()->in('c.id', $outerQuery->createFunction($innerQuery->getSQL())));

if ($offset) {
$outerQuery->setFirstResult($offset);
Expand Down
5 changes: 4 additions & 1 deletion apps/dav/lib/CalDAV/CalendarImpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright 2017, Georg Ehrke <[email protected]>
*
Expand Down Expand Up @@ -51,7 +54,7 @@ public function __construct(Calendar $calendar, array $calendarInfo,
$this->calendarInfo = $calendarInfo;
$this->backend = $backend;
}

/**
* @return string defining the technical unique key
* @since 13.0.0
Expand Down
73 changes: 73 additions & 0 deletions apps/dav/lib/CalDAV/CalendarProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

/**
* @copyright 2021 Anna Larch <[email protected]>
*
* @author Anna Larch <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\DAV\CalDAV;

use OCP\Calendar\ICalendarProvider;
use OCP\IConfig;
use OCP\IL10N;

class CalendarProvider implements ICalendarProvider {

/** @var CalDavBackend */
private $calDavBackend;

/** @var IL10N */
private $l10n;

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

public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config) {
$this->calDavBackend = $calDavBackend;
$this->l10n = $l10n;
$this->config = $config;
}

public function getCalendars(string $principalUri, array $calendarUris = []): array {
$calendarInfos = [];
if (empty($calendarUris)) {
$calendarInfos[] = $this->calDavBackend->getCalendarsForUser($principalUri);
} else {
foreach ($calendarUris as $calendarUri) {
$calendarByUri = $this->calDavBackend->getCalendarByUri($principalUri, $calendarUri);
if ($calendarByUri !== null) {
$calendarInfos[] = $calendarByUri;
}
}
}

$iCalendars = [];
foreach ($calendarInfos as $calendarInfo) {
$calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config);
$iCalendars[] = new CalendarImpl(
$calendar,
$calendarInfo,
$this->calDavBackend,
);
}
return $iCalendars;
}
}
3 changes: 3 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
'OCP\\Broadcast\\Events\\IBroadcastEvent' => $baseDir . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php',
'OCP\\Calendar\\ICalendarQuery' => $baseDir . '/lib/public/Calendar/ICalendarQuery.php',
'OCP\\Calendar\\IManager' => $baseDir . '/lib/public/Calendar/IManager.php',
'OCP\\Calendar\\IMetadataProvider' => $baseDir . '/lib/public/Calendar/IMetadataProvider.php',
'OCP\\Calendar\\Resource\\IBackend' => $baseDir . '/lib/public/Calendar/Resource/IBackend.php',
Expand Down Expand Up @@ -759,6 +761,7 @@
'OC\\Broadcast\\Events\\BroadcastEvent' => $baseDir . '/lib/private/Broadcast/Events/BroadcastEvent.php',
'OC\\Cache\\CappedMemoryCache' => $baseDir . '/lib/private/Cache/CappedMemoryCache.php',
'OC\\Cache\\File' => $baseDir . '/lib/private/Cache/File.php',
'OC\\Calendar\\CalendarQuery' => $baseDir . '/lib/private/Calendar/CalendarQuery.php',
'OC\\Calendar\\Manager' => $baseDir . '/lib/private/Calendar/Manager.php',
'OC\\Calendar\\Resource\\Manager' => $baseDir . '/lib/private/Calendar/Resource/Manager.php',
'OC\\Calendar\\Room\\Manager' => $baseDir . '/lib/private/Calendar/Room/Manager.php',
Expand Down
3 changes: 3 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Broadcast\\Events\\IBroadcastEvent' => __DIR__ . '/../../..' . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.php',
'OCP\\Calendar\\ICalendarQuery' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarQuery.php',
'OCP\\Calendar\\IManager' => __DIR__ . '/../../..' . '/lib/public/Calendar/IManager.php',
'OCP\\Calendar\\IMetadataProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/IMetadataProvider.php',
'OCP\\Calendar\\Resource\\IBackend' => __DIR__ . '/../../..' . '/lib/public/Calendar/Resource/IBackend.php',
Expand Down Expand Up @@ -788,6 +790,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Broadcast\\Events\\BroadcastEvent' => __DIR__ . '/../../..' . '/lib/private/Broadcast/Events/BroadcastEvent.php',
'OC\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/private/Cache/CappedMemoryCache.php',
'OC\\Cache\\File' => __DIR__ . '/../../..' . '/lib/private/Cache/File.php',
'OC\\Calendar\\CalendarQuery' => __DIR__ . '/../../..' . '/lib/private/Calendar/CalendarQuery.php',
'OC\\Calendar\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Manager.php',
'OC\\Calendar\\Resource\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Resource/Manager.php',
'OC\\Calendar\\Room\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Room/Manager.php',
Expand Down
22 changes: 22 additions & 0 deletions lib/private/AppFramework/Bootstrap/RegistrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Services\InitialStateProvider;
use OCP\Authentication\IAlternativeLogin;
use OCP\Calendar\ICalendarProvider;
use OCP\Capabilities\ICapability;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
Expand Down Expand Up @@ -95,6 +96,9 @@ class RegistrationContext {
/** @var ServiceRegistration<\OCP\Authentication\TwoFactorAuth\IProvider>[] */
private $twoFactorProviders = [];

/** @var ServiceRegistration<ICalendarProvider>[] */
private $calendarProviders = [];

/** @var LoggerInterface */
private $logger;

Expand Down Expand Up @@ -225,6 +229,13 @@ public function registerTwoFactorProvider(string $twoFactorProviderClass): void
$twoFactorProviderClass
);
}

public function registerCalendarProvider(string $class): void {
$this->context->registerCalendarProvider(
$this->appId,
$class
);
}
};
}

Expand Down Expand Up @@ -300,6 +311,10 @@ public function registerTwoFactorProvider(string $appId, string $class): void {
$this->twoFactorProviders[] = new ServiceRegistration($appId, $class);
}

public function registerCalendarProvider(string $appId, string $class): void {
$this->calendarProviders[] = new ServiceRegistration($appId, $class);
}

/**
* @param App[] $apps
*/
Expand Down Expand Up @@ -530,4 +545,11 @@ public function getNotifierServices(): array {
public function getTwoFactorProviders(): array {
return $this->twoFactorProviders;
}

/**
* @return ServiceRegistration<ICalendarProvider>[]
*/
public function getCalendarProviders(): array {
return $this->calendarProviders;
}
}
124 changes: 124 additions & 0 deletions lib/private/Calendar/CalendarQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

declare(strict_types=1);

/**
* @copyright 2021 Anna Larch <[email protected]>
*
* @author Anna Larch <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Calendar;

use OCP\Calendar\ICalendarQuery;

class CalendarQuery implements ICalendarQuery {

/** @var string */
private $principalUri;

/** @var array */
public $searchProperties;

/** @var string|null */
private $searchPattern;

/** @var array */
private $options;

/** @var int|null */
private $offset;

/** @var int|null */
private $limit;

/** @var array */
private $calendarUris;

public function __construct(string $principalUri) {
$this->principalUri = $principalUri;
$this->searchProperties = [];
$this->options = [
'types' => [],
];
}

public function getPrincipalUri(): string {
return $this->principalUri;
}

public function setPrincipalUri(string $principalUri): void {
$this->principalUri = $principalUri;
}

public function setSearchPattern(string $pattern): void {
$this->searchPattern = $pattern;
}

public function getSearchPattern(): ?string {
return $this->searchPattern;
}

public function addSearchProperty(string $value): void {
$this->searchProperties[] = $value;
}

public function getSearchProperties(): array {
return $this->searchProperties;
}

public function addSearchCalendar(string $calendarUri): void {
$this->calendarUris[] = $calendarUri;
}

public function getCalendarUris(): array {
return $this->calendarUris;
}

public function getLimit(): ?int {
return $this->limit;
}

public function setLimit(int $limit): void {
$this->limit = $limit;
}

public function getOffset(): ?int {
return $this->offset;
}

public function setOffset(int $offset): void {
$this->offset = $offset;
}

public function addType(string $value): void {
$this->options['types'][] = $value;
}

public function setTimerangeStart(\DateTimeImmutable $startTime): void {
$this->options['timerange']['start'] = $startTime;
}

public function setTimerangeEnd(\DateTimeImmutable $endTime): void {
$this->options['timerange']['end'] = $endTime;
}

public function getOptions(): array {
return $this->options;
}
}
Loading

0 comments on commit 116140b

Please sign in to comment.