summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2021-10-22 12:07:39 +0200
committerGitHub <noreply@github.com>2021-10-22 12:07:39 +0200
commit8b742ab39401ac4e4a40aa3aab01742ea09b8344 (patch)
tree73940c5ccff06cec84291867bef495fa2052d811 /apps/dav
parent2be0eda47cb3891573f4e0c609a46a080095b017 (diff)
parentfab887cb7c577a3e70219e686707bb52e0bc9bbe (diff)
downloadnextcloud-server-8b742ab39401ac4e4a40aa3aab01742ea09b8344.tar.gz
nextcloud-server-8b742ab39401ac4e4a40aa3aab01742ea09b8344.zip
Merge pull request #28997 from nextcloud/fix/set-attendee-as-recipient
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php6
-rw-r--r--apps/dav/lib/Controller/InvitationResponseController.php7
-rw-r--r--apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php97
3 files changed, 85 insertions, 25 deletions
diff --git a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
index 90e2e478e1c..af3d7c1269a 100644
--- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
+++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
@@ -124,4 +124,10 @@ class InvitationResponseServer {
$schedulingPlugin = $this->server->getPlugin('caldav-schedule');
$schedulingPlugin->scheduleLocalDelivery($iTipMessage);
}
+
+ public function isExternalAttendee(string $principalUri): bool {
+ /** @var \Sabre\DAVACL\Plugin $aclPlugin */
+ $aclPlugin = $this->server->getPlugin('acl');
+ return $aclPlugin->getPrincipalByUri($principalUri) === null;
+ }
}
diff --git a/apps/dav/lib/Controller/InvitationResponseController.php b/apps/dav/lib/Controller/InvitationResponseController.php
index f6923152dce..de22e3ba6a9 100644
--- a/apps/dav/lib/Controller/InvitationResponseController.php
+++ b/apps/dav/lib/Controller/InvitationResponseController.php
@@ -198,7 +198,12 @@ class InvitationResponseController extends Controller {
$iTipMessage->method = 'REPLY';
$iTipMessage->sequence = $row['sequence'];
$iTipMessage->sender = $row['attendee'];
- $iTipMessage->recipient = $row['organizer'];
+
+ if ($this->responseServer->isExternalAttendee($row['attendee'])) {
+ $iTipMessage->recipient = $row['organizer'];
+ } else {
+ $iTipMessage->recipient = $row['attendee'];
+ }
$message = <<<EOF
BEGIN:VCALENDAR
diff --git a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
index e8b6af9fcea..cd3269d657c 100644
--- a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
+++ b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
@@ -27,6 +27,7 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace OCA\DAV\Tests\Unit\DAV\Controller;
use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer;
@@ -77,7 +78,17 @@ class InvitationResponseControllerTest extends TestCase {
);
}
- public function testAccept() {
+ public function attendeeProvider(): array {
+ return [
+ 'local attendee' => [false],
+ 'external attendee' => [true]
+ ];
+ }
+
+ /**
+ * @dataProvider attendeeProvider
+ */
+ public function testAccept(bool $isExternalAttendee): void {
$this->buildQueryExpects('TOKEN123', [
'id' => 0,
'uid' => 'this-is-the-events-uid',
@@ -110,21 +121,26 @@ EOF;
$called = false;
$this->responseServer->expects($this->once())
->method('handleITipMessage')
- ->willReturnCallback(function (Message $iTipMessage) use (&$called, $expected) {
+ ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) {
$called = true;
$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
$this->assertEquals('VEVENT', $iTipMessage->component);
$this->assertEquals('REPLY', $iTipMessage->method);
$this->assertEquals(null, $iTipMessage->sequence);
$this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
- $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ if ($isExternalAttendee) {
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ } else {
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->recipient);
+ }
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
$this->assertEquals($expected, $iTipMessage->message->serialize());
});
-
-
+ $this->responseServer->expects($this->once())
+ ->method('isExternalAttendee')
+ ->willReturn($isExternalAttendee);
$response = $this->controller->accept('TOKEN123');
$this->assertInstanceOf(TemplateResponse::class, $response);
@@ -133,7 +149,10 @@ EOF;
$this->assertTrue($called);
}
- public function testAcceptSequence() {
+ /**
+ * @dataProvider attendeeProvider
+ */
+ public function testAcceptSequence(bool $isExternalAttendee): void {
$this->buildQueryExpects('TOKEN123', [
'id' => 0,
'uid' => 'this-is-the-events-uid',
@@ -166,21 +185,26 @@ EOF;
$called = false;
$this->responseServer->expects($this->once())
->method('handleITipMessage')
- ->willReturnCallback(function (Message $iTipMessage) use (&$called, $expected) {
+ ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) {
$called = true;
$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
$this->assertEquals('VEVENT', $iTipMessage->component);
$this->assertEquals('REPLY', $iTipMessage->method);
$this->assertEquals(1337, $iTipMessage->sequence);
$this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
- $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ if ($isExternalAttendee) {
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ } else {
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->recipient);
+ }
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
$this->assertEquals($expected, $iTipMessage->message->serialize());
});
-
-
+ $this->responseServer->expects($this->once())
+ ->method('isExternalAttendee')
+ ->willReturn($isExternalAttendee);
$response = $this->controller->accept('TOKEN123');
$this->assertInstanceOf(TemplateResponse::class, $response);
@@ -189,7 +213,10 @@ EOF;
$this->assertTrue($called);
}
- public function testAcceptRecurrenceId() {
+ /**
+ * @dataProvider attendeeProvider
+ */
+ public function testAcceptRecurrenceId(bool $isExternalAttendee): void {
$this->buildQueryExpects('TOKEN123', [
'id' => 0,
'uid' => 'this-is-the-events-uid',
@@ -223,21 +250,26 @@ EOF;
$called = false;
$this->responseServer->expects($this->once())
->method('handleITipMessage')
- ->willReturnCallback(function (Message $iTipMessage) use (&$called, $expected) {
+ ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) {
$called = true;
$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
$this->assertEquals('VEVENT', $iTipMessage->component);
$this->assertEquals('REPLY', $iTipMessage->method);
$this->assertEquals(0, $iTipMessage->sequence);
$this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
- $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ if ($isExternalAttendee) {
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ } else {
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->recipient);
+ }
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
$this->assertEquals($expected, $iTipMessage->message->serialize());
});
-
-
+ $this->responseServer->expects($this->once())
+ ->method('isExternalAttendee')
+ ->willReturn($isExternalAttendee);
$response = $this->controller->accept('TOKEN123');
$this->assertInstanceOf(TemplateResponse::class, $response);
@@ -273,7 +305,10 @@ EOF;
$this->assertEquals([], $response->getParams());
}
- public function testDecline() {
+ /**
+ * @dataProvider attendeeProvider
+ */
+ public function testDecline(bool $isExternalAttendee): void {
$this->buildQueryExpects('TOKEN123', [
'id' => 0,
'uid' => 'this-is-the-events-uid',
@@ -306,21 +341,26 @@ EOF;
$called = false;
$this->responseServer->expects($this->once())
->method('handleITipMessage')
- ->willReturnCallback(function (Message $iTipMessage) use (&$called, $expected) {
+ ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) {
$called = true;
$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
$this->assertEquals('VEVENT', $iTipMessage->component);
$this->assertEquals('REPLY', $iTipMessage->method);
$this->assertEquals(null, $iTipMessage->sequence);
$this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
- $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ if ($isExternalAttendee) {
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ } else {
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->recipient);
+ }
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
$this->assertEquals($expected, $iTipMessage->message->serialize());
});
-
-
+ $this->responseServer->expects($this->once())
+ ->method('isExternalAttendee')
+ ->willReturn($isExternalAttendee);
$response = $this->controller->decline('TOKEN123');
$this->assertInstanceOf(TemplateResponse::class, $response);
@@ -336,7 +376,10 @@ EOF;
$this->assertEquals(['token' => 'TOKEN123'], $response->getParams());
}
- public function testProcessMoreOptionsResult() {
+ /**
+ * @dataProvider attendeeProvider
+ */
+ public function testProcessMoreOptionsResult(bool $isExternalAttendee): void {
$this->request->expects($this->at(0))
->method('getParam')
->with('partStat')
@@ -384,20 +427,26 @@ EOF;
$called = false;
$this->responseServer->expects($this->once())
->method('handleITipMessage')
- ->willReturnCallback(function (Message $iTipMessage) use (&$called, $expected) {
+ ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) {
$called = true;
$this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
$this->assertEquals('VEVENT', $iTipMessage->component);
$this->assertEquals('REPLY', $iTipMessage->method);
$this->assertEquals(null, $iTipMessage->sequence);
$this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
- $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ if ($isExternalAttendee) {
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+ } else {
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->recipient);
+ }
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
$this->assertEquals($expected, $iTipMessage->message->serialize());
});
-
+ $this->responseServer->expects($this->once())
+ ->method('isExternalAttendee')
+ ->willReturn($isExternalAttendee);
$response = $this->controller->processMoreOptionsResult('TOKEN123');