Skip to content

Commit 736ef9a

Browse files
Merge pull request #52704 from nextcloud/backport/51081/stable30
[stable30] fix(CalDAV): add calendar enable
2 parents 87a7f49 + b7d1691 commit 736ef9a

7 files changed

Lines changed: 85 additions & 3 deletions

File tree

apps/dav/lib/CalDAV/CachedSubscriptionImpl.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
namespace OCA\DAV\CalDAV;
1010

1111
use OCP\Calendar\ICalendar;
12+
use OCP\Calendar\ICalendarIsEnabled;
1213
use OCP\Constants;
1314

14-
class CachedSubscriptionImpl implements ICalendar {
15+
class CachedSubscriptionImpl implements ICalendar, ICalendarIsEnabled {
1516
private CalDavBackend $backend;
1617
private CachedSubscription $calendar;
1718
/** @var array<string, mixed> */
@@ -90,6 +91,13 @@ public function getPermissions(): int {
9091
return $result;
9192
}
9293

94+
/**
95+
* @since 30.0.12
96+
*/
97+
public function isEnabled(): bool {
98+
return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true;
99+
}
100+
93101
public function isDeleted(): bool {
94102
return false;
95103
}

apps/dav/lib/CalDAV/CalendarImpl.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
1212
use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer;
1313
use OCP\Calendar\Exceptions\CalendarException;
14+
use OCP\Calendar\ICalendarIsEnabled;
1415
use OCP\Calendar\ICreateFromString;
1516
use OCP\Calendar\IHandleImipMessage;
1617
use OCP\Constants;
@@ -24,7 +25,7 @@
2425
use Sabre\VObject\Reader;
2526
use function Sabre\Uri\split as uriSplit;
2627

27-
class CalendarImpl implements ICreateFromString, IHandleImipMessage {
28+
class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsEnabled {
2829
private CalDavBackend $backend;
2930
private Calendar $calendar;
3031
/** @var array<string, mixed> */
@@ -132,6 +133,13 @@ public function getPermissions(): int {
132133
return $result;
133134
}
134135

136+
/**
137+
* @since 30.0.12
138+
*/
139+
public function isEnabled(): bool {
140+
return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true;
141+
}
142+
135143
/**
136144
* @since 26.0.0
137145
*/

apps/dav/lib/CalDAV/CalendarProvider.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
namespace OCA\DAV\CalDAV;
1010

11+
use OCA\DAV\Db\Property;
12+
use OCA\DAV\Db\PropertyMapper;
1113
use OCP\Calendar\ICalendarProvider;
1214
use OCP\IConfig;
1315
use OCP\IL10N;
@@ -27,11 +29,15 @@ class CalendarProvider implements ICalendarProvider {
2729
/** @var LoggerInterface */
2830
private $logger;
2931

30-
public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
32+
/** @var PropertyMapper */
33+
private $propertyMapper;
34+
35+
public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config, LoggerInterface $logger, PropertyMapper $propertyMapper) {
3136
$this->calDavBackend = $calDavBackend;
3237
$this->l10n = $l10n;
3338
$this->config = $config;
3439
$this->logger = $logger;
40+
$this->propertyMapper = $propertyMapper;
3541
}
3642

3743
public function getCalendars(string $principalUri, array $calendarUris = []): array {
@@ -48,6 +54,7 @@ public function getCalendars(string $principalUri, array $calendarUris = []): ar
4854

4955
$iCalendars = [];
5056
foreach ($calendarInfos as $calendarInfo) {
57+
$calendarInfo = array_merge($calendarInfo, $this->getAdditionalProperties($calendarInfo['principaluri'], $calendarInfo['uri']));
5158
$calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
5259
$iCalendars[] = new CalendarImpl(
5360
$calendar,
@@ -57,4 +64,23 @@ public function getCalendars(string $principalUri, array $calendarUris = []): ar
5764
}
5865
return $iCalendars;
5966
}
67+
68+
public function getAdditionalProperties(string $principalUri, string $calendarUri): array {
69+
$user = str_replace('principals/users/', '', $principalUri);
70+
$path = 'calendars/' . $user . '/' . $calendarUri;
71+
72+
$properties = $this->propertyMapper->findPropertiesByPath($user, $path);
73+
74+
$list = [];
75+
foreach ($properties as $property) {
76+
if ($property instanceof Property) {
77+
$list[$property->getPropertyname()] = match ($property->getPropertyname()) {
78+
'{http://owncloud.org/ns}calendar-enabled' => (bool) $property->getPropertyvalue(),
79+
default => $property->getPropertyvalue()
80+
};
81+
}
82+
}
83+
84+
return $list;
85+
}
6086
}

apps/dav/lib/Db/PropertyMapper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,18 @@ public function findPropertyByPathAndName(string $userId, string $path, string $
3838
return $this->findEntities($selectQb);
3939
}
4040

41+
/**
42+
* @return Property[]
43+
*/
44+
public function findPropertiesByPath(string $userId, string $path): array {
45+
$selectQb = $this->db->getQueryBuilder();
46+
$selectQb->select('*')
47+
->from(self::TABLE_NAME)
48+
->where(
49+
$selectQb->expr()->eq('userid', $selectQb->createNamedParameter($userId)),
50+
$selectQb->expr()->eq('propertypath', $selectQb->createNamedParameter($path)),
51+
);
52+
return $this->findEntities($selectQb);
53+
}
54+
4155
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
164164
'OCP\\Calendar\\Exceptions\\CalendarException' => $baseDir . '/lib/public/Calendar/Exceptions/CalendarException.php',
165165
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
166+
'OCP\\Calendar\\ICalendarIsEnabled' => $baseDir . '/lib/public/Calendar/ICalendarIsEnabled.php',
166167
'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php',
167168
'OCP\\Calendar\\ICalendarQuery' => $baseDir . '/lib/public/Calendar/ICalendarQuery.php',
168169
'OCP\\Calendar\\ICreateFromString' => $baseDir . '/lib/public/Calendar/ICreateFromString.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
196196
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
197197
'OCP\\Calendar\\Exceptions\\CalendarException' => __DIR__ . '/../../..' . '/lib/public/Calendar/Exceptions/CalendarException.php',
198198
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
199+
'OCP\\Calendar\\ICalendarIsEnabled' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsEnabled.php',
199200
'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.php',
200201
'OCP\\Calendar\\ICalendarQuery' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarQuery.php',
201202
'OCP\\Calendar\\ICreateFromString' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICreateFromString.php',
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
namespace OCP\Calendar;
9+
10+
/**
11+
* ICalendar Interface Extension
12+
*
13+
* @since 30.0.12
14+
*/
15+
interface ICalendarIsEnabled {
16+
17+
/**
18+
* Indicates whether the calendar is enabled
19+
*
20+
* @since 30.0.12
21+
*/
22+
public function isEnabled(): bool;
23+
24+
}

0 commit comments

Comments
 (0)