Skip to content

Commit

Permalink
Update attendence for external users
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kesselb authored and backportbot[bot] committed Oct 22, 2021
1 parent a44e728 commit 6df4391
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ public function handleITipMessage(Message $iTipMessage) {
$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;
}
}
7 changes: 6 additions & 1 deletion apps/dav/lib/Controller/InvitationResponseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ private function buildITipResponse(array $row, string $partStat, int $guests = n
$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
Expand Down
96 changes: 72 additions & 24 deletions apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ protected function setUp(): void {
);
}

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',
Expand Down Expand Up @@ -109,21 +119,26 @@ public function testAccept() {
$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:[email protected]', $iTipMessage->sender);
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
if ($isExternalAttendee) {
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
} else {
$this->assertEquals('mailto:[email protected]', $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);
Expand All @@ -132,7 +147,10 @@ public function testAccept() {
$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',
Expand Down Expand Up @@ -165,21 +183,26 @@ public function testAcceptSequence() {
$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:[email protected]', $iTipMessage->sender);
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
if ($isExternalAttendee) {
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
} else {
$this->assertEquals('mailto:[email protected]', $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);
Expand All @@ -188,7 +211,10 @@ public function testAcceptSequence() {
$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',
Expand Down Expand Up @@ -222,21 +248,26 @@ public function testAcceptRecurrenceId() {
$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:[email protected]', $iTipMessage->sender);
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
if ($isExternalAttendee) {
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
} else {
$this->assertEquals('mailto:[email protected]', $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);
Expand Down Expand Up @@ -272,7 +303,10 @@ public function testAcceptExpiredToken() {
$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',
Expand Down Expand Up @@ -305,21 +339,26 @@ public function testDecline() {
$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:[email protected]', $iTipMessage->sender);
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
if ($isExternalAttendee) {
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
} else {
$this->assertEquals('mailto:[email protected]', $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);
Expand All @@ -335,7 +374,10 @@ public function testOptions() {
$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')
Expand Down Expand Up @@ -383,20 +425,26 @@ public function testProcessMoreOptionsResult() {
$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:[email protected]', $iTipMessage->sender);
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
if ($isExternalAttendee) {
$this->assertEquals('mailto:[email protected]', $iTipMessage->recipient);
} else {
$this->assertEquals('mailto:[email protected]', $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');
Expand Down

0 comments on commit 6df4391

Please sign in to comment.