Skip to content

Commit

Permalink
Merge pull request #49503 from nextcloud/fix/issue-48528-disable-itip…
Browse files Browse the repository at this point in the history
…-and-imip-messages-2

fix(CalDAV): disable both iTip and iMip messages
  • Loading branch information
kesselb authored Dec 10, 2024
2 parents 28ec9c7 + 04cb122 commit 85f4f4f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
8 changes: 0 additions & 8 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ public function beforeWriteContent($uri, INode $node, $data, $modified): void {
*/
public function schedule(Message $iTipMessage) {

// do not send imip messages if external system already did
/** @psalm-suppress UndefinedPropertyFetch */
if ($iTipMessage->message?->VEVENT?->{'X-NC-DISABLE-SCHEDULING'}?->getValue() === 'true') {
if (!$iTipMessage->scheduleStatus) {
$iTipMessage->scheduleStatus = '1.0;We got the message, but iMip messages are disabled for this event';
}
return;
}
// Not sending any emails if the system considers the update insignificant
if (!$iTipMessage->significantChange) {
if (!$iTipMessage->scheduleStatus) {
Expand Down
8 changes: 7 additions & 1 deletion apps/dav/lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -162,10 +163,15 @@ public function calendarObjectChange(RequestInterface $request, ResponseInterfac

try {

// Do not generate iTip and iMip messages if scheduling is disabled for this message
if ($request->getHeader('x-nc-scheduling') === 'false') {
return;
}

if (!$this->scheduleReply($this->server->httpRequest)) {
return;
}

/** @var Calendar $calendarNode */
$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
// extract addresses for owner
Expand Down
19 changes: 0 additions & 19 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,23 +997,4 @@ public function testNoButtons(): void {
$this->plugin->schedule($message);
$this->assertEquals('1.1', $message->getScheduleStatus());
}

public function testImipDisabledForEvent(): void {
// construct iTip message with event and attendees
$calendar = new VCalendar();
$calendar->add('VEVENT', ['UID' => 'uid-1234']);
$event = $calendar->VEVENT;
$event->add('ORGANIZER', 'mailto:[email protected]');
$event->add('ATTENDEE', 'mailto:' . '[email protected]', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
$event->add('X-NC-DISABLE-SCHEDULING', 'true');
$message = new Message();
$message->method = 'REQUEST';
$message->message = $calendar;
$message->sender = 'mailto:[email protected]';
$message->senderName = 'Mr. Wizard';
$message->recipient = 'mailto:' . '[email protected]';

$this->plugin->schedule($message);
$this->assertEquals('1.0;We got the message, but iMip messages are disabled for this event', $message->scheduleStatus);
}
}
39 changes: 39 additions & 0 deletions apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -738,4 +739,42 @@ function (string $eventName, array $arguments = [], ?callable $continueCallBack

}

/**
* Test Calendar Event Creation with iTip and iMip disabled
*
* Should generate 2 messages for attendees User 2 and User External
*/
public function testCalendarObjectChangeWithSchedulingDisabled(): void {
// construct server request
$request = new Request(
'PUT',
'/remote.php/dav/calendars/user1/personal/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics',
['x-nc-scheduling' => 'false']
);
$request->setBaseUrl('/remote.php/dav/');
// construct server response
$response = new Response();
// construct server tree
$tree = $this->createMock(Tree::class);
$tree->expects($this->never())
->method('getNodeForPath');
// construct server properties and returns
$this->server->httpRequest = $request;
$this->server->tree = $tree;
// construct empty calendar event
$vCalendar = new VCalendar();
$vEvent = $vCalendar->add('VEVENT', []);
// define flags
$newFlag = true;
$modifiedFlag = false;
// execute method
$this->plugin->calendarObjectChange(
$request,
$response,
$vCalendar,
'calendars/user1/personal',
$modifiedFlag,
$newFlag
);
}
}

0 comments on commit 85f4f4f

Please sign in to comment.