Skip to content

Commit 85f4f4f

Browse files
authored
Merge pull request #49503 from nextcloud/fix/issue-48528-disable-itip-and-imip-messages-2
fix(CalDAV): disable both iTip and iMip messages
2 parents 28ec9c7 + 04cb122 commit 85f4f4f

4 files changed

Lines changed: 46 additions & 28 deletions

File tree

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,6 @@ public function beforeWriteContent($uri, INode $node, $data, $modified): void {
9797
*/
9898
public function schedule(Message $iTipMessage) {
9999

100-
// do not send imip messages if external system already did
101-
/** @psalm-suppress UndefinedPropertyFetch */
102-
if ($iTipMessage->message?->VEVENT?->{'X-NC-DISABLE-SCHEDULING'}?->getValue() === 'true') {
103-
if (!$iTipMessage->scheduleStatus) {
104-
$iTipMessage->scheduleStatus = '1.0;We got the message, but iMip messages are disabled for this event';
105-
}
106-
return;
107-
}
108100
// Not sending any emails if the system considers the update insignificant
109101
if (!$iTipMessage->significantChange) {
110102
if (!$iTipMessage->scheduleStatus) {

apps/dav/lib/CalDAV/Schedule/Plugin.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -162,10 +163,15 @@ public function calendarObjectChange(RequestInterface $request, ResponseInterfac
162163

163164
try {
164165

166+
// Do not generate iTip and iMip messages if scheduling is disabled for this message
167+
if ($request->getHeader('x-nc-scheduling') === 'false') {
168+
return;
169+
}
170+
165171
if (!$this->scheduleReply($this->server->httpRequest)) {
166172
return;
167173
}
168-
174+
169175
/** @var Calendar $calendarNode */
170176
$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
171177
// extract addresses for owner

apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -997,23 +997,4 @@ public function testNoButtons(): void {
997997
$this->plugin->schedule($message);
998998
$this->assertEquals('1.1', $message->getScheduleStatus());
999999
}
1000-
1001-
public function testImipDisabledForEvent(): void {
1002-
// construct iTip message with event and attendees
1003-
$calendar = new VCalendar();
1004-
$calendar->add('VEVENT', ['UID' => 'uid-1234']);
1005-
$event = $calendar->VEVENT;
1006-
$event->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
1007-
$event->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
1008-
$event->add('X-NC-DISABLE-SCHEDULING', 'true');
1009-
$message = new Message();
1010-
$message->method = 'REQUEST';
1011-
$message->message = $calendar;
1012-
$message->sender = 'mailto:gandalf@wiz.ard';
1013-
$message->senderName = 'Mr. Wizard';
1014-
$message->recipient = 'mailto:' . 'frodo@hobb.it';
1015-
1016-
$this->plugin->schedule($message);
1017-
$this->assertEquals('1.0;We got the message, but iMip messages are disabled for this event', $message->scheduleStatus);
1018-
}
10191000
}

apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -738,4 +739,42 @@ function (string $eventName, array $arguments = [], ?callable $continueCallBack
738739

739740
}
740741

742+
/**
743+
* Test Calendar Event Creation with iTip and iMip disabled
744+
*
745+
* Should generate 2 messages for attendees User 2 and User External
746+
*/
747+
public function testCalendarObjectChangeWithSchedulingDisabled(): void {
748+
// construct server request
749+
$request = new Request(
750+
'PUT',
751+
'/remote.php/dav/calendars/user1/personal/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics',
752+
['x-nc-scheduling' => 'false']
753+
);
754+
$request->setBaseUrl('/remote.php/dav/');
755+
// construct server response
756+
$response = new Response();
757+
// construct server tree
758+
$tree = $this->createMock(Tree::class);
759+
$tree->expects($this->never())
760+
->method('getNodeForPath');
761+
// construct server properties and returns
762+
$this->server->httpRequest = $request;
763+
$this->server->tree = $tree;
764+
// construct empty calendar event
765+
$vCalendar = new VCalendar();
766+
$vEvent = $vCalendar->add('VEVENT', []);
767+
// define flags
768+
$newFlag = true;
769+
$modifiedFlag = false;
770+
// execute method
771+
$this->plugin->calendarObjectChange(
772+
$request,
773+
$response,
774+
$vCalendar,
775+
'calendars/user1/personal',
776+
$modifiedFlag,
777+
$newFlag
778+
);
779+
}
741780
}

0 commit comments

Comments
 (0)