Merge pull request #52704 from nextcloud/backport/51081/stable30

[stable30] fix(CalDAV): add calendar enable
pull/53078/head
Sebastian Krupinski 2025-05-23 09:57:45 +07:00 committed by GitHub
commit 736ef9ab27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 85 additions and 3 deletions

@ -9,9 +9,10 @@ declare(strict_types=1);
namespace OCA\DAV\CalDAV;
use OCP\Calendar\ICalendar;
use OCP\Calendar\ICalendarIsEnabled;
use OCP\Constants;
class CachedSubscriptionImpl implements ICalendar {
class CachedSubscriptionImpl implements ICalendar, ICalendarIsEnabled {
private CalDavBackend $backend;
private CachedSubscription $calendar;
/** @var array<string, mixed> */
@ -90,6 +91,13 @@ class CachedSubscriptionImpl implements ICalendar {
return $result;
}
/**
* @since 30.0.12
*/
public function isEnabled(): bool {
return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true;
}
public function isDeleted(): bool {
return false;
}

@ -11,6 +11,7 @@ namespace OCA\DAV\CalDAV;
use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer;
use OCP\Calendar\Exceptions\CalendarException;
use OCP\Calendar\ICalendarIsEnabled;
use OCP\Calendar\ICreateFromString;
use OCP\Calendar\IHandleImipMessage;
use OCP\Constants;
@ -24,7 +25,7 @@ use Sabre\VObject\Property;
use Sabre\VObject\Reader;
use function Sabre\Uri\split as uriSplit;
class CalendarImpl implements ICreateFromString, IHandleImipMessage {
class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsEnabled {
private CalDavBackend $backend;
private Calendar $calendar;
/** @var array<string, mixed> */
@ -132,6 +133,13 @@ class CalendarImpl implements ICreateFromString, IHandleImipMessage {
return $result;
}
/**
* @since 30.0.12
*/
public function isEnabled(): bool {
return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true;
}
/**
* @since 26.0.0
*/

@ -8,6 +8,8 @@ declare(strict_types=1);
*/
namespace OCA\DAV\CalDAV;
use OCA\DAV\Db\Property;
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendarProvider;
use OCP\IConfig;
use OCP\IL10N;
@ -27,11 +29,15 @@ class CalendarProvider implements ICalendarProvider {
/** @var LoggerInterface */
private $logger;
public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
/** @var PropertyMapper */
private $propertyMapper;
public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config, LoggerInterface $logger, PropertyMapper $propertyMapper) {
$this->calDavBackend = $calDavBackend;
$this->l10n = $l10n;
$this->config = $config;
$this->logger = $logger;
$this->propertyMapper = $propertyMapper;
}
public function getCalendars(string $principalUri, array $calendarUris = []): array {
@ -48,6 +54,7 @@ class CalendarProvider implements ICalendarProvider {
$iCalendars = [];
foreach ($calendarInfos as $calendarInfo) {
$calendarInfo = array_merge($calendarInfo, $this->getAdditionalProperties($calendarInfo['principaluri'], $calendarInfo['uri']));
$calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$iCalendars[] = new CalendarImpl(
$calendar,
@ -57,4 +64,23 @@ class CalendarProvider implements ICalendarProvider {
}
return $iCalendars;
}
public function getAdditionalProperties(string $principalUri, string $calendarUri): array {
$user = str_replace('principals/users/', '', $principalUri);
$path = 'calendars/' . $user . '/' . $calendarUri;
$properties = $this->propertyMapper->findPropertiesByPath($user, $path);
$list = [];
foreach ($properties as $property) {
if ($property instanceof Property) {
$list[$property->getPropertyname()] = match ($property->getPropertyname()) {
'{http://owncloud.org/ns}calendar-enabled' => (bool) $property->getPropertyvalue(),
default => $property->getPropertyvalue()
};
}
}
return $list;
}
}

@ -38,4 +38,18 @@ class PropertyMapper extends QBMapper {
return $this->findEntities($selectQb);
}
/**
* @return Property[]
*/
public function findPropertiesByPath(string $userId, string $path): array {
$selectQb = $this->db->getQueryBuilder();
$selectQb->select('*')
->from(self::TABLE_NAME)
->where(
$selectQb->expr()->eq('userid', $selectQb->createNamedParameter($userId)),
$selectQb->expr()->eq('propertypath', $selectQb->createNamedParameter($path)),
);
return $this->findEntities($selectQb);
}
}

@ -163,6 +163,7 @@ return array(
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\Exceptions\\CalendarException' => $baseDir . '/lib/public/Calendar/Exceptions/CalendarException.php',
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
'OCP\\Calendar\\ICalendarIsEnabled' => $baseDir . '/lib/public/Calendar/ICalendarIsEnabled.php',
'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php',
'OCP\\Calendar\\ICalendarQuery' => $baseDir . '/lib/public/Calendar/ICalendarQuery.php',
'OCP\\Calendar\\ICreateFromString' => $baseDir . '/lib/public/Calendar/ICreateFromString.php',

@ -196,6 +196,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\Exceptions\\CalendarException' => __DIR__ . '/../../..' . '/lib/public/Calendar/Exceptions/CalendarException.php',
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
'OCP\\Calendar\\ICalendarIsEnabled' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsEnabled.php',
'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.php',
'OCP\\Calendar\\ICalendarQuery' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarQuery.php',
'OCP\\Calendar\\ICreateFromString' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICreateFromString.php',

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Calendar;
/**
* ICalendar Interface Extension
*
* @since 30.0.12
*/
interface ICalendarIsEnabled {
/**
* Indicates whether the calendar is enabled
*
* @since 30.0.12
*/
public function isEnabled(): bool;
}