Skip to content

Commit bd3026f

Browse files
SebastianKrupinskikesselb
authored andcommitted
fix: add calendar enable
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 8450efc commit bd3026f

File tree

7 files changed

+83
-2
lines changed

7 files changed

+83
-2
lines changed

apps/dav/lib/CalDAV/CachedSubscriptionImpl.php

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

1111
use OCP\Calendar\ICalendar;
12+
use OCP\Calendar\ICalendarIsEnabled;
1213
use OCP\Calendar\ICalendarIsShared;
1314
use OCP\Calendar\ICalendarIsWritable;
1415
use OCP\Constants;
1516

16-
class CachedSubscriptionImpl implements ICalendar, ICalendarIsShared, ICalendarIsWritable {
17+
class CachedSubscriptionImpl implements ICalendar, ICalendarIsEnabled, ICalendarIsShared, ICalendarIsWritable {
1718

1819
public function __construct(
1920
private CachedSubscription $calendar,
@@ -86,6 +87,13 @@ public function getPermissions(): int {
8687
return $result;
8788
}
8889

90+
/**
91+
* @since 31.0.6
92+
*/
93+
public function isEnabled(): bool {
94+
return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true;
95+
}
96+
8997
public function isWritable(): bool {
9098
return false;
9199
}

apps/dav/lib/CalDAV/CalendarImpl.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
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;
15+
use OCP\Calendar\ICalendarIsShared;
16+
use OCP\Calendar\ICalendarIsWritable;
1417
use OCP\Calendar\ICreateFromString;
1518
use OCP\Calendar\IHandleImipMessage;
1619
use OCP\Constants;
@@ -24,7 +27,7 @@
2427
use Sabre\VObject\Reader;
2528
use function Sabre\Uri\split as uriSplit;
2629

27-
class CalendarImpl implements ICreateFromString, IHandleImipMessage {
30+
class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarIsEnabled {
2831
public function __construct(
2932
private Calendar $calendar,
3033
/** @var array<string, mixed> */
@@ -131,6 +134,13 @@ public function getPermissions(): int {
131134
return $result;
132135
}
133136

137+
/**
138+
* @since 31.0.6
139+
*/
140+
public function isEnabled(): bool {
141+
return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true;
142+
}
143+
134144
/**
135145
* @since 31.0.0
136146
*/

apps/dav/lib/CalDAV/CalendarProvider.php

Lines changed: 23 additions & 0 deletions
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;
@@ -20,6 +22,7 @@ public function __construct(
2022
private IL10N $l10n,
2123
private IConfig $config,
2224
private LoggerInterface $logger,
25+
private PropertyMapper $propertyMapper,
2326
) {
2427
}
2528

@@ -35,6 +38,7 @@ public function getCalendars(string $principalUri, array $calendarUris = []): ar
3538

3639
$iCalendars = [];
3740
foreach ($calendarInfos as $calendarInfo) {
41+
$calendarInfo = array_merge($calendarInfo, $this->getAdditionalProperties($calendarInfo['principaluri'], $calendarInfo['uri']));
3842
$calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
3943
$iCalendars[] = new CalendarImpl(
4044
$calendar,
@@ -44,4 +48,23 @@ public function getCalendars(string $principalUri, array $calendarUris = []): ar
4448
}
4549
return $iCalendars;
4650
}
51+
52+
public function getAdditionalProperties(string $principalUri, string $calendarUri): array {
53+
$user = str_replace('principals/users/', '', $principalUri);
54+
$path = 'calendars/' . $user . '/' . $calendarUri;
55+
56+
$properties = $this->propertyMapper->findPropertiesByPath($user, $path);
57+
58+
$list = [];
59+
foreach ($properties as $property) {
60+
if ($property instanceof Property) {
61+
$list[$property->getPropertyname()] = match ($property->getPropertyname()) {
62+
'{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(),
63+
default => $property->getPropertyvalue()
64+
};
65+
}
66+
}
67+
68+
return $list;
69+
}
4770
}

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
@@ -202,6 +202,7 @@
202202
'OCP\\Calendar\\IAvailabilityResult' => $baseDir . '/lib/public/Calendar/IAvailabilityResult.php',
203203
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
204204
'OCP\\Calendar\\ICalendarEventBuilder' => $baseDir . '/lib/public/Calendar/ICalendarEventBuilder.php',
205+
'OCP\\Calendar\\ICalendarIsEnabled' => $baseDir . '/lib/public/Calendar/ICalendarIsEnabled.php',
205206
'OCP\\Calendar\\ICalendarIsShared' => $baseDir . '/lib/public/Calendar/ICalendarIsShared.php',
206207
'OCP\\Calendar\\ICalendarIsWritable' => $baseDir . '/lib/public/Calendar/ICalendarIsWritable.php',
207208
'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
251251
'OCP\\Calendar\\IAvailabilityResult' => __DIR__ . '/../../..' . '/lib/public/Calendar/IAvailabilityResult.php',
252252
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
253253
'OCP\\Calendar\\ICalendarEventBuilder' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarEventBuilder.php',
254+
'OCP\\Calendar\\ICalendarIsEnabled' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsEnabled.php',
254255
'OCP\\Calendar\\ICalendarIsShared' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsShared.php',
255256
'OCP\\Calendar\\ICalendarIsWritable' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsWritable.php',
256257
'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.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 31.0.6
14+
*/
15+
interface ICalendarIsEnabled {
16+
17+
/**
18+
* Indicates whether the calendar is enabled
19+
*
20+
* @since 31.0.6
21+
*/
22+
public function isEnabled(): bool;
23+
24+
}

0 commit comments

Comments
 (0)