|
17 | 17 | use OCA\DAV\CalDAV\Federation\FederatedCalendarMapper; |
18 | 18 | use OCA\DAV\CalDAV\Sharing\Backend; |
19 | 19 | use OCA\DAV\Connector\Sabre\Principal; |
| 20 | +use OCA\DAV\DAV\CustomPropertiesBackend; |
| 21 | +use OCA\DAV\DAV\CustomPropertiesService; |
20 | 22 | use OCA\DAV\DAV\Sharing\IShareable; |
21 | 23 | use OCA\DAV\Events\CachedCalendarObjectCreatedEvent; |
22 | 24 | use OCA\DAV\Events\CachedCalendarObjectDeletedEvent; |
@@ -220,6 +222,7 @@ public function __construct( |
220 | 222 | private IConfig $config, |
221 | 223 | private Sharing\Backend $calendarSharingBackend, |
222 | 224 | private FederatedCalendarMapper $federatedCalendarMapper, |
| 225 | + private CustomPropertiesService $customPropertiesService, |
223 | 226 | ICacheFactory $cacheFactory, |
224 | 227 | private bool $legacyEndpoint = false, |
225 | 228 | ) { |
@@ -459,7 +462,7 @@ public function getCalendarsForUser($principalUri) { |
459 | 462 | } |
460 | 463 | $result->closeCursor(); |
461 | 464 |
|
462 | | - return array_values($calendars); |
| 465 | + return $this->addAdditionalPropertiesToCalendars(array_values($calendars)); |
463 | 466 | }, $this->db); |
464 | 467 | } |
465 | 468 |
|
@@ -508,7 +511,7 @@ public function getUsersOwnCalendars($principalUri) { |
508 | 511 | } |
509 | 512 | } |
510 | 513 | $stmt->closeCursor(); |
511 | | - return array_values($calendars); |
| 514 | + return $this->addAdditionalPropertiesToCalendars(array_values($calendars)); |
512 | 515 | } |
513 | 516 |
|
514 | 517 | /** |
@@ -674,6 +677,8 @@ public function getCalendarByUri($principal, $uri) { |
674 | 677 | $calendar = $this->addOwnerPrincipalToCalendar($calendar); |
675 | 678 | $calendar = $this->addResourceTypeToCalendar($row, $calendar); |
676 | 679 |
|
| 680 | + [$calendar] = $this->addAdditionalPropertiesToCalendars([$calendar]); |
| 681 | + |
677 | 682 | return $calendar; |
678 | 683 | } |
679 | 684 |
|
@@ -4011,6 +4016,49 @@ private function convertPrincipal($principalUri, $toV2) { |
4011 | 4016 | return $principalUri; |
4012 | 4017 | } |
4013 | 4018 |
|
| 4019 | + /** |
| 4020 | + * Adds the properties the user whose calendar home a calendar is in has stored on it |
| 4021 | + * |
| 4022 | + * Stored properties only fill in values the calendar does not provide itself. On calendars |
| 4023 | + * shared with the user, the properties a sharee can customize override the owner's values. |
| 4024 | + * |
| 4025 | + * @param array[] $calendars |
| 4026 | + * @return array[] |
| 4027 | + */ |
| 4028 | + private function addAdditionalPropertiesToCalendars(array $calendars): array { |
| 4029 | + $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
| 4030 | + |
| 4031 | + $paths = []; |
| 4032 | + $calendarPaths = []; |
| 4033 | + foreach ($calendars as $key => $calendar) { |
| 4034 | + [$prefix, $userId] = Uri\split($calendar['principaluri']); |
| 4035 | + if ($prefix !== 'principals/users' && $prefix !== 'principals') { |
| 4036 | + continue; |
| 4037 | + } |
| 4038 | + $path = 'calendars/' . $userId . '/' . $calendar['uri']; |
| 4039 | + $paths[$userId][] = $path; |
| 4040 | + $calendarPaths[$key] = [$userId, $path]; |
| 4041 | + } |
| 4042 | + if ($paths === []) { |
| 4043 | + return $calendars; |
| 4044 | + } |
| 4045 | + |
| 4046 | + $properties = $this->customPropertiesService->getProperties($paths); |
| 4047 | + foreach ($calendarPaths as $key => [$userId, $path]) { |
| 4048 | + $storedProperties = $properties[$userId][$path] ?? []; |
| 4049 | + if ($storedProperties === []) { |
| 4050 | + continue; |
| 4051 | + } |
| 4052 | + $calendar = array_merge($storedProperties, $calendars[$key]); |
| 4053 | + if (isset($calendar[$ownerPrincipalKey]) && $calendar[$ownerPrincipalKey] !== $calendar['principaluri']) { |
| 4054 | + $calendar = array_merge($calendar, array_intersect_key($storedProperties, array_flip(CustomPropertiesBackend::SHARED_CALENDAR_PROPERTIES))); |
| 4055 | + } |
| 4056 | + $calendars[$key] = $calendar; |
| 4057 | + } |
| 4058 | + |
| 4059 | + return $calendars; |
| 4060 | + } |
| 4061 | + |
4014 | 4062 | /** |
4015 | 4063 | * adds information about an owner to the calendar data |
4016 | 4064 | * |
|
0 commit comments