Skip to content

Commit 9f9cde9

Browse files
fix: add calendar enable
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com> [skip ci]
1 parent b6326db commit 9f9cde9

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
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 32.0.0
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ public function getPermissions(): int {
131131
return $result;
132132
}
133133

134+
/**
135+
* @since 32.0.0
136+
*/
137+
public function isEnabled(): bool {
138+
return $this->calendarInfo['{http://owncloud.org/ns}calendar-enabled'] ?? true;
139+
}
140+
134141
/**
135142
* @since 31.0.0
136143
*/

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
}
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 32.0.0
14+
*/
15+
interface ICalendarIsEnabled {
16+
17+
/**
18+
* Indicates whether the calendar is enabled
19+
*
20+
* @since 32.0.0
21+
*/
22+
public function isEnabled(): bool;
23+
24+
}

0 commit comments

Comments
 (0)