Files
Grigory Vodyanov 5422c003b8 fix(dav): scope stored and principal properties to their owner
Published properties such as calendar availability and the default
calendar URL were looked up in oc_properties by path only. Rows that
another user stored under the same path, which the legacy webdav
endpoint does because its paths are relative to the user's home, were
returned as well, together with any other property on that path. Only
rows stored by the node's owner, and only the published property
names, are read now, as UserStatusAutomation and TimezoneService
already do.

CalendarProvider merged every property a user stored for their view
of a calendar over the backend's calendar info, so stored values for
computed properties such as read-only or owner-principal overrode the
real ones for IManager consumers like calendar import and upcoming
events. Only per-user display properties are taken from oc_properties
now.

Group memberships and calendar delegations of a principal are only
served to the principal itself. Clients only need them for the
current user; other principals answer 403 for these properties.

Not included: prefixing legacy webdav property paths on write, which
needs a repair step for existing rows, and rejecting computed property
names in propPatch(), which the provider now ignores.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Grigory Vodyanov <scratchx@gmx.com>
2026-11-25 08:37:40 +01:00

130 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CalDAV;
use OCA\DAV\CalDAV\Federation\FederatedCalendarImpl;
use OCA\DAV\Db\Property;
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendarProvider;
use OCP\IConfig;
use OCP\IL10N;
use Psr\Log\LoggerInterface;
class CalendarProvider implements ICalendarProvider {
/**
* Properties a user may store for their own view of a calendar. Everything
* else, in particular what access decisions are based on (read-only,
* owner-principal, ...), only comes from the backend.
*/
private const USER_PROPERTIES = [
'{DAV:}displayname',
'{urn:ietf:params:xml:ns:caldav}calendar-description',
'{urn:ietf:params:xml:ns:caldav}calendar-timezone',
'{http://apple.com/ns/ical/}calendar-order',
'{http://apple.com/ns/ical/}calendar-color',
'{http://nextcloud.com/ns}disable-alarm-notifications',
'{http://owncloud.org/ns}calendar-enabled',
];
public function __construct(
private CalDavBackend $calDavBackend,
private IL10N $l10n,
private IConfig $config,
private LoggerInterface $logger,
private PropertyMapper $propertyMapper,
) {
}
#[\Override]
public function getCalendars(string $principalUri, array $calendarUris = []): array {
/** @var array{uri: string, principaluri: string}[] $calendarInfos */
$calendarInfos = $this->calDavBackend->getCalendarsForUser($principalUri) ?? [];
/** @var array{uri: string, principaluri: string}[] $federatedCalendarInfos */
$federatedCalendarInfos = $this->calDavBackend->getFederatedCalendarsForUser($principalUri);
if (!empty($calendarUris)) {
$calendarInfos = array_filter($calendarInfos, function ($calendar) use ($calendarUris) {
return in_array($calendar['uri'], $calendarUris, true);
});
$federatedCalendarInfos = array_filter($federatedCalendarInfos, function ($federatedCalendar) use ($calendarUris) {
return in_array($federatedCalendar['uri'], $calendarUris, true);
});
}
$iCalendars = [];
$additionalProperties = $this->getAdditionalPropertiesForCalendars($calendarInfos);
foreach ($calendarInfos as $calendarInfo) {
$user = str_replace('principals/users/', '', $calendarInfo['principaluri']);
$path = 'calendars/' . $user . '/' . $calendarInfo['uri'];
$calendarInfo = array_merge($calendarInfo, $additionalProperties[$path] ?? []);
$calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$iCalendars[] = new CalendarImpl(
$calendar,
$calendarInfo,
$this->calDavBackend,
);
}
$additionalFederatedProps = $this->getAdditionalPropertiesForCalendars($federatedCalendarInfos);
foreach ($federatedCalendarInfos as $calendarInfo) {
$user = str_replace('principals/users/', '', $calendarInfo['principaluri']);
$path = 'calendars/' . $user . '/' . $calendarInfo['uri'];
if (isset($additionalFederatedProps[$path])) {
$calendarInfo = array_merge($calendarInfo, $additionalFederatedProps[$path]);
}
$iCalendars[] = new FederatedCalendarImpl($calendarInfo, $this->calDavBackend);
}
return $iCalendars;
}
/**
* @param array{
* principaluri: string,
* uri: string,
* }[] $uris
* @return array<string, array<string, string|bool>>
*/
private function getAdditionalPropertiesForCalendars(array $uris): array {
$calendars = [];
foreach ($uris as $uri) {
/** @var string $user */
$user = str_replace('principals/users/', '', $uri['principaluri']);
if (!array_key_exists($user, $calendars)) {
$calendars[$user] = [];
}
$calendars[$user][] = 'calendars/' . $user . '/' . $uri['uri'];
}
$properties = $this->propertyMapper->findPropertiesByPathsAndUsers($calendars);
$list = [];
foreach ($properties as $property) {
if ($property instanceof Property && in_array($property->getPropertyname(), self::USER_PROPERTIES, true)) {
if (!isset($list[$property->getPropertypath()])) {
$list[$property->getPropertypath()] = [];
}
$list[$property->getPropertypath()][$property->getPropertyname()] = match ($property->getPropertyname()) {
'{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(),
default => $property->getPropertyvalue()
};
}
}
return $list;
}
}