Files
Ferdinand Thiessen b9bcaadb67 fix(dav): respect link share group exclusions for calendar publishing
Use IShareManager::shareApiAllowLinks() to decide whether a calendar
may be published, so that users in `shareapi_allow_links_exclude_groups`
cannot publish calendars either.

Keep the PublishPlugin registered when link sharing is disabled and only
reject publishing new calendars. Users can still see and remove existing
publications, while public access to them stays blocked.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-11-06 23:55:29 +01:00

57 lines
1.4 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\DAV\CalDAV;
use OCA\DAV\DAV\Sharing\CanChangeSharingTrait;
use OCP\Share\IManager as IShareManager;
use Override;
use Sabre\CalDAV\Xml\Property\AllowedSharingModes;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
class SharingPlugin extends ServerPlugin {
use CanChangeSharingTrait;
public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
protected Server $server;
public function __construct(
private readonly IShareManager $shareManager,
) {
}
#[Override]
public function getFeatures(): array {
return ['calendarserver-sharing'];
}
#[Override]
public function getPluginName(): string {
return 'oc-calendar-sharing';
}
#[Override]
public function initialize(Server $server): void {
$this->server = $server;
$this->server->on('propFind', $this->propFind(...));
}
public function propFind(PropFind $propFind, INode $node): void {
if ($node instanceof Calendar) {
$propFind->handle('{' . self::NS_CALENDARSERVER . '}allowed-sharing-modes', function () use ($propFind, $node) {
$canShare = !$node->isSubscription() && $this->canChangeSharing($propFind->getPath());
$canPublish = $canShare && $this->shareManager->shareApiAllowLinks();
return new AllowedSharingModes($canShare, $canPublish);
});
}
}
}