Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
'OCA\\DAV\\CalDAV\\ResourceBooking\\ResourcePrincipalBackend' => $baseDir . '/../lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php',
'OCA\\DAV\\CalDAV\\ResourceBooking\\RoomPrincipalBackend' => $baseDir . '/../lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php',
'OCA\\DAV\\CalDAV\\RetentionService' => $baseDir . '/../lib/CalDAV/RetentionService.php',
'OCA\\DAV\\CalDAV\\Schedule\\DelegateActionCapturePlugin' => $baseDir . '/../lib/CalDAV/Schedule/DelegateActionCapturePlugin.php',
'OCA\\DAV\\CalDAV\\Schedule\\DelegateActionContext' => $baseDir . '/../lib/CalDAV/Schedule/DelegateActionContext.php',
'OCA\\DAV\\CalDAV\\Schedule\\IMipPlugin' => $baseDir . '/../lib/CalDAV/Schedule/IMipPlugin.php',
'OCA\\DAV\\CalDAV\\Schedule\\IMipService' => $baseDir . '/../lib/CalDAV/Schedule/IMipService.php',
'OCA\\DAV\\CalDAV\\Schedule\\Plugin' => $baseDir . '/../lib/CalDAV/Schedule/Plugin.php',
Expand Down Expand Up @@ -331,6 +333,7 @@
'OCA\\DAV\\Listener\\AddressbookListener' => $baseDir . '/../lib/Listener/AddressbookListener.php',
'OCA\\DAV\\Listener\\BirthdayListener' => $baseDir . '/../lib/Listener/BirthdayListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => $baseDir . '/../lib/Listener/CalendarContactInteractionListener.php',
'OCA\\DAV\\Listener\\CalendarDelegateActionListener' => $baseDir . '/../lib/Listener/CalendarDelegateActionListener.php',
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => $baseDir . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarFederationNotificationListener' => $baseDir . '/../lib/Listener/CalendarFederationNotificationListener.php',
'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => $baseDir . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class ComposerStaticInitDAV
'OCA\\DAV\\CalDAV\\ResourceBooking\\ResourcePrincipalBackend' => __DIR__ . '/..' . '/../lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php',
'OCA\\DAV\\CalDAV\\ResourceBooking\\RoomPrincipalBackend' => __DIR__ . '/..' . '/../lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php',
'OCA\\DAV\\CalDAV\\RetentionService' => __DIR__ . '/..' . '/../lib/CalDAV/RetentionService.php',
'OCA\\DAV\\CalDAV\\Schedule\\DelegateActionCapturePlugin' => __DIR__ . '/..' . '/../lib/CalDAV/Schedule/DelegateActionCapturePlugin.php',
'OCA\\DAV\\CalDAV\\Schedule\\DelegateActionContext' => __DIR__ . '/..' . '/../lib/CalDAV/Schedule/DelegateActionContext.php',
'OCA\\DAV\\CalDAV\\Schedule\\IMipPlugin' => __DIR__ . '/..' . '/../lib/CalDAV/Schedule/IMipPlugin.php',
'OCA\\DAV\\CalDAV\\Schedule\\IMipService' => __DIR__ . '/..' . '/../lib/CalDAV/Schedule/IMipService.php',
'OCA\\DAV\\CalDAV\\Schedule\\Plugin' => __DIR__ . '/..' . '/../lib/CalDAV/Schedule/Plugin.php',
Expand Down Expand Up @@ -346,6 +348,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Listener\\AddressbookListener' => __DIR__ . '/..' . '/../lib/Listener/AddressbookListener.php',
'OCA\\DAV\\Listener\\BirthdayListener' => __DIR__ . '/..' . '/../lib/Listener/BirthdayListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarContactInteractionListener.php',
'OCA\\DAV\\Listener\\CalendarDelegateActionListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarDelegateActionListener.php',
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarFederationNotificationListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarFederationNotificationListener.php',
'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
Expand Down
7 changes: 7 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCA\DAV\Listener\AddressbookListener;
use OCA\DAV\Listener\BirthdayListener;
use OCA\DAV\Listener\CalendarContactInteractionListener;
use OCA\DAV\Listener\CalendarDelegateActionListener;
use OCA\DAV\Listener\CalendarDeletionDefaultUpdaterListener;
use OCA\DAV\Listener\CalendarFederationNotificationListener;
use OCA\DAV\Listener\CalendarObjectReminderUpdaterListener;
Expand Down Expand Up @@ -217,6 +218,12 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarFederationNotificationListener::class);
$context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarFederationNotificationListener::class);

$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarDelegateActionListener::class);
$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarDelegateActionListener::class);
$context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarDelegateActionListener::class);
$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarDelegateActionListener::class);
$context->registerEventListener(CalendarObjectRestoredEvent::class, CalendarDelegateActionListener::class);

$context->registerNotifierService(NotifierCalDAV::class);
$context->registerNotifierService(NotifierCardDAV::class);

Expand Down
2 changes: 2 additions & 0 deletions apps/dav/lib/CalDAV/EmbeddedCalDavServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
use OCA\DAV\CalDAV\Auth\PublicPrincipalPlugin;
use OCA\DAV\CalDAV\Publishing\PublishPlugin;
use OCA\DAV\CalDAV\Schedule\DelegateActionCapturePlugin;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin;
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
Expand Down Expand Up @@ -97,6 +98,7 @@ public function __construct(bool $public = true) {
if ($appConfig->getValueString('dav', 'sendInvitations', 'yes') === 'yes') {
$this->server->addPlugin(Server::get(IMipPlugin::class));
}
$this->server->addPlugin(Server::get(DelegateActionCapturePlugin::class));

// collection preload plugin
$this->server->addPlugin(new PropFindPreloadNotifyPlugin());
Expand Down
80 changes: 80 additions & 0 deletions apps/dav/lib/CalDAV/Schedule/DelegateActionCapturePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV\CalDAV\Schedule;

use OCA\DAV\CalDAV\CalendarObject;
use Sabre\DAV\INode;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Reader;
use Throwable;

/**
* Captures the iCalendar payload of a calendar object before it is overwritten
* (PUT) or deleted (DELETE), and stashes it in DelegateActionContext so that
* CalendarDelegateActionListener can diff old vs new when it fires later in
* the same request.
*/
class DelegateActionCapturePlugin extends ServerPlugin {

private ?Server $server = null;

public function __construct(
private readonly DelegateActionContext $context,
) {
}

#[\Override]
public function initialize(Server $server): void {
$this->server = $server;
$server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10);
$server->on('beforeUnbind', [$this, 'beforeUnbind'], 10);
}

#[\Override]
public function getPluginName(): string {
return 'nc-delegate-action-capture';
}

public function beforeWriteContent(string $uri, INode $node, $data, $modified): void {
$this->capture($node);
}

public function beforeUnbind(string $path): void {
if ($this->server === null) {
return;
}
try {
$node = $this->server->tree->getNodeForPath($path);
} catch (Throwable) {
return;
}
$this->capture($node);
}

private function capture(INode $node): void {
if (!$node instanceof CalendarObject) {
return;
}
try {
$raw = $node->get();
if ($raw === '') {
return;
}
$vCalendar = Reader::read($raw);
if ($vCalendar instanceof VCalendar) {
$this->context->setPrevious($vCalendar);
}
} catch (Throwable) {
// Capture is best-effort: swallow malformed iCalendar.
}
}
}
31 changes: 31 additions & 0 deletions apps/dav/lib/CalDAV/Schedule/DelegateActionContext.php
Copy link
Copy Markdown
Contributor

@SebastianKrupinski SebastianKrupinski May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

If I am reading this correctly, you are using a global context class to transport data from the plugin to the event listener. This is a bad idea, in my opinion.

Also this plugin is only really needed in one instance on update, that is wasteful and the calendar object update event already emits the new data:

CalendarObjectUpdatedEvent

What you do need is the CalendarObjectUpdatedEvent to also carry previous data, I would extend the event to also emit the previous object data also. It is only emitted in one place so you are save to change it.

I would recommend changing the updateCalendarObject method to first pull the existing record, then updated it and then use can use the array for both new and previous, just replace record in the array with the new data from $extraData

public function updateCalendarObject($calendarId, $objectUri, $calendarData, $calendarType = self::CALENDAR_TYPE_CALENDAR) {

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\DAV\CalDAV\Schedule;

use Sabre\VObject\Component\VCalendar;

/**
* Request-scoped container that lets a Sabre plugin (capturing the
* pre-write iCalendar in beforeWriteContent / beforeUnbind) hand the
* previous VCalendar to the CalendarDelegateActionListener, which fires
* later in the same request from the CalDavBackend event dispatcher.
*/
class DelegateActionContext {

private ?VCalendar $previous = null;

public function setPrevious(?VCalendar $vCalendar): void {
$this->previous = $vCalendar;
}

public function getPrevious(): ?VCalendar {
return $this->previous;
}
}
Loading
Loading