summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2021-10-08 16:34:43 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2021-10-22 10:14:00 +0000
commit6df439177d93e82a983852835dd6048648c532b4 (patch)
tree6249e3f3fff11ee388c3cb1212a72ca9031844a4 /apps
parenta44e728a895b1b24081a79ec187b4102aea55821 (diff)
downloadnextcloud-server-6df439177d93e82a983852835dd6048648c532b4.tar.gz
nextcloud-server-6df439177d93e82a983852835dd6048648c532b4.zip
Update attendence for external users
For local users it's possible to select their calendar via the principal url and first update their own attendance status. External users have no calendar event hence the recipient is the organizer. Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps')
-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.php96
3 files changed, 84 insertions, 25 deletions
diff --git a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
index 7b0ee1bbef2..a24fc6856b6 100644
--- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
+++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php
@@ -122,4 +122,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 9cc1f97e658..b021878655e 100644
--- a/apps/dav/lib/Controller/InvitationResponseController.php
+++ b/apps/dav/lib/Controller/InvitationResponseController.php
@@ -200,7 +200,12 @@ class InvitationResponseController extends Controller {
$iTipMessage->method = 'REPLY';
$iTipMessage->sequence = $row['sequence'];
$iTipMessage->sender = $row['attendee'];
- $iTipMessage->recipient = $row['attendee'];
+
+ 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 2fb97969655..f959f45a8a5 100644
--- a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
+++ b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
@@ -76,7 +76,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',
@@ -109,21 +119,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);
@@ -132,7 +147,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',
@@ -165,21 +183,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);
@@ -188,7 +211,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',
@@ -222,21 +248,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);
@@ -272,7 +303,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',
@@ -305,21 +339,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);
@@ -335,7 +374,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')
@@ -383,20 +425,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');