-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! feat(ocp): add calendar api to retrieve availability of attendees
- Loading branch information
Showing
4 changed files
with
98 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ PRODID:-//Sabre//Sabre VObject 4.5.6//EN | |
CALSCALE:GREGORIAN | ||
METHOD:REQUEST | ||
BEGIN:VFREEBUSY | ||
DTSTART:20250109T082136Z | ||
DTEND:20250109T102136Z | ||
ORGANIZER:mailto:[email protected] | ||
ATTENDEE:mailto:[email protected] | ||
ATTENDEE:mailto:[email protected] | ||
DTSTART:20250116T060000Z | ||
DTEND:20250117T060000Z | ||
ORGANIZER:mailto:[email protected] | ||
ATTENDEE:mailto:[email protected] | ||
ATTENDEE:mailto:[email protected] | ||
ATTENDEE:mailto:[email protected] | ||
END:VFREEBUSY | ||
END:VCALENDAR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
use Sabre\HTTP\RequestInterface; | ||
use Sabre\HTTP\ResponseInterface; | ||
use Sabre\VObject\Component\VCalendar; | ||
use Sabre\VObject\Component\VFreeBusy; | ||
use Sabre\VObject\Document; | ||
use Sabre\VObject\Reader; | ||
use Test\TestCase; | ||
|
@@ -994,10 +995,10 @@ private function getVCalendarCancel(): Document { | |
private function getFreeBusyResponse(): string { | ||
return <<<EOF | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<cal:schedule-response xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/"> | ||
<cal:schedule-response xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"> | ||
<cal:response> | ||
<cal:recipient> | ||
<d:href>mailto:[email protected]</d:href> | ||
<d:href>mailto:[email protected]</d:href> | ||
</cal:recipient> | ||
<cal:request-status>2.0;Success</cal:request-status> | ||
<cal:calendar-data>BEGIN:VCALENDAR | ||
|
@@ -1006,20 +1007,21 @@ private function getFreeBusyResponse(): string { | |
CALSCALE:GREGORIAN | ||
METHOD:REPLY | ||
BEGIN:VFREEBUSY | ||
DTSTART:20250109T082136Z | ||
DTEND:20250109T102136Z | ||
DTSTAMP:20250109T082136Z | ||
FREEBUSY::20250109T084500Z/20250109T090000Z | ||
ATTENDEE:mailto:[email protected] | ||
UID: | ||
ORGANIZER:mailto:[email protected] | ||
DTSTART:20250116T060000Z | ||
DTEND:20250117T060000Z | ||
DTSTAMP:20250111T125634Z | ||
FREEBUSY:20250116T060000Z/20250116T230000Z | ||
FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20250116T230000Z/20250117T060000Z | ||
ATTENDEE:mailto:[email protected] | ||
UID:6099eab3-9bf1-4c7a-809e-4d46957cc372 | ||
ORGANIZER;CN=admin:mailto:[email protected] | ||
END:VFREEBUSY | ||
END:VCALENDAR | ||
</cal:calendar-data> | ||
</cal:response> | ||
<cal:response> | ||
<cal:recipient> | ||
<d:href>mailto:[email protected]</d:href> | ||
<d:href>mailto:[email protected]</d:href> | ||
</cal:recipient> | ||
<cal:request-status>2.0;Success</cal:request-status> | ||
<cal:calendar-data>BEGIN:VCALENDAR | ||
|
@@ -1028,16 +1030,45 @@ private function getFreeBusyResponse(): string { | |
CALSCALE:GREGORIAN | ||
METHOD:REPLY | ||
BEGIN:VFREEBUSY | ||
DTSTART:20250109T082136Z | ||
DTEND:20250109T102136Z | ||
DTSTAMP:20250109T082136Z | ||
ATTENDEE:mailto:[email protected] | ||
UID: | ||
ORGANIZER:mailto:[email protected] | ||
DTSTART:20250116T060000Z | ||
DTEND:20250117T060000Z | ||
DTSTAMP:20250111T125634Z | ||
ATTENDEE:mailto:[email protected] | ||
UID:6099eab3-9bf1-4c7a-809e-4d46957cc372 | ||
ORGANIZER;CN=admin:mailto:[email protected] | ||
END:VFREEBUSY | ||
END:VCALENDAR | ||
</cal:calendar-data> | ||
</cal:response> | ||
<cal:response> | ||
<cal:recipient> | ||
<d:href>mailto:[email protected]</d:href> | ||
</cal:recipient> | ||
<cal:request-status>2.0;Success</cal:request-status> | ||
<cal:calendar-data>BEGIN:VCALENDAR | ||
VERSION:2.0 | ||
PRODID:-//Sabre//Sabre VObject 4.5.6//EN | ||
CALSCALE:GREGORIAN | ||
METHOD:REPLY | ||
BEGIN:VFREEBUSY | ||
DTSTART:20250116T060000Z | ||
DTEND:20250117T060000Z | ||
DTSTAMP:20250111T125634Z | ||
FREEBUSY:20250116T060000Z/20250116T230000Z | ||
FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20250116T230000Z/20250117T060000Z | ||
ATTENDEE:mailto:[email protected] | ||
UID:6099eab3-9bf1-4c7a-809e-4d46957cc372 | ||
ORGANIZER;CN=admin:mailto:[email protected] | ||
END:VFREEBUSY | ||
END:VCALENDAR | ||
</cal:calendar-data> | ||
</cal:response> | ||
<cal:response> | ||
<cal:recipient> | ||
<d:href>mailto:[email protected]</d:href> | ||
</cal:recipient> | ||
<cal:request-status>3.7;Could not find principal</cal:request-status> | ||
</cal:response> | ||
</cal:schedule-response> | ||
EOF; | ||
} | ||
|
@@ -1046,25 +1077,26 @@ public function testCheckAvailability(): void { | |
$organizer = $this->createMock(IUser::class); | ||
$organizer->expects(self::once()) | ||
->method('getUID') | ||
->willReturn('organizer'); | ||
->willReturn('admin'); | ||
$organizer->expects(self::once()) | ||
->method('getEMailAddress') | ||
->willReturn('[email protected]'); | ||
->willReturn('[email protected]'); | ||
|
||
$user1 = $this->createMock(IUser::class); | ||
$user2 = $this->createMock(IUser::class); | ||
|
||
$this->userManager->expects(self::exactly(2)) | ||
$this->userManager->expects(self::exactly(3)) | ||
->method('getByEmail') | ||
->willReturnMap([ | ||
['[email protected]', $user1], | ||
['[email protected]', $user2], | ||
['[email protected]', [$user1]], | ||
['[email protected]', [$user2]], | ||
['[email protected]', []], | ||
]); | ||
|
||
$authPlugin = $this->createMock(CustomPrincipalPlugin::class); | ||
$authPlugin->expects(self::once()) | ||
->method('setCurrentPrincipal') | ||
->with('principals/users/organizer'); | ||
->with('principals/users/admin'); | ||
|
||
$server = $this->createMock(\OCA\DAV\Connector\Sabre\Server::class); | ||
$server->expects(self::once()) | ||
|
@@ -1080,7 +1112,7 @@ public function testCheckAvailability(): void { | |
) { | ||
$requestBody = file_get_contents(__DIR__ . '/../../data/ics/free-busy-request.ics'); | ||
$this->assertEquals('POST', $request->getMethod()); | ||
$this->assertEquals('calendars/organizer/outbox', $request->getPath()); | ||
$this->assertEquals('calendars/admin/outbox', $request->getPath()); | ||
$this->assertEquals('text/calendar', $request->getHeader('Content-Type')); | ||
$this->assertEquals('0', $request->getHeader('Depth')); | ||
$this->assertEquals($requestBody, $request->getBodyAsString()); | ||
|
@@ -1093,15 +1125,17 @@ public function testCheckAvailability(): void { | |
->method('createAttendeeAvailabilityServer') | ||
->willReturn($server); | ||
|
||
$start = new DateTimeImmutable('2025-01-09T08:21:36Z'); | ||
$end = new DateTimeImmutable('2025-01-09T10:21:36Z'); | ||
$start = new DateTimeImmutable('2025-01-16T06:00:00Z'); | ||
$end = new DateTimeImmutable('2025-01-17T06:00:00Z'); | ||
$actual = $this->manager->checkAvailability($start, $end, $organizer, [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
]); | ||
$expected = [ | ||
new AvailabilityResult('[email protected]', false), | ||
new AvailabilityResult('[email protected]', true), | ||
new AvailabilityResult('[email protected]', false), | ||
new AvailabilityResult('[email protected]', true), | ||
new AvailabilityResult('[email protected]', false), | ||
]; | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
@@ -1110,25 +1144,26 @@ public function testCheckAvailabilityWithMailtoPrefix(): void { | |
$organizer = $this->createMock(IUser::class); | ||
$organizer->expects(self::once()) | ||
->method('getUID') | ||
->willReturn('organizer'); | ||
->willReturn('admin'); | ||
$organizer->expects(self::once()) | ||
->method('getEMailAddress') | ||
->willReturn('[email protected]'); | ||
->willReturn('[email protected]'); | ||
|
||
$user1 = $this->createMock(IUser::class); | ||
$user2 = $this->createMock(IUser::class); | ||
|
||
$this->userManager->expects(self::exactly(2)) | ||
$this->userManager->expects(self::exactly(3)) | ||
->method('getByEmail') | ||
->willReturnMap([ | ||
['[email protected]', $user1], | ||
['[email protected]', $user2], | ||
['[email protected]', [$user1]], | ||
['[email protected]', [$user2]], | ||
['[email protected]', []], | ||
]); | ||
|
||
$authPlugin = $this->createMock(CustomPrincipalPlugin::class); | ||
$authPlugin->expects(self::once()) | ||
->method('setCurrentPrincipal') | ||
->with('principals/users/organizer'); | ||
->with('principals/users/admin'); | ||
|
||
$server = $this->createMock(\OCA\DAV\Connector\Sabre\Server::class); | ||
$server->expects(self::once()) | ||
|
@@ -1144,7 +1179,7 @@ public function testCheckAvailabilityWithMailtoPrefix(): void { | |
) { | ||
$requestBody = file_get_contents(__DIR__ . '/../../data/ics/free-busy-request.ics'); | ||
$this->assertEquals('POST', $request->getMethod()); | ||
$this->assertEquals('calendars/organizer/outbox', $request->getPath()); | ||
$this->assertEquals('calendars/admin/outbox', $request->getPath()); | ||
$this->assertEquals('text/calendar', $request->getHeader('Content-Type')); | ||
$this->assertEquals('0', $request->getHeader('Depth')); | ||
$this->assertEquals($requestBody, $request->getBodyAsString()); | ||
|
@@ -1157,15 +1192,17 @@ public function testCheckAvailabilityWithMailtoPrefix(): void { | |
->method('createAttendeeAvailabilityServer') | ||
->willReturn($server); | ||
|
||
$start = new DateTimeImmutable('2025-01-09T08:21:36Z'); | ||
$end = new DateTimeImmutable('2025-01-09T10:21:36Z'); | ||
$start = new DateTimeImmutable('2025-01-16T06:00:00Z'); | ||
$end = new DateTimeImmutable('2025-01-17T06:00:00Z'); | ||
$actual = $this->manager->checkAvailability($start, $end, $organizer, [ | ||
'mailto:[email protected]', | ||
'mailto:[email protected]', | ||
'mailto:[email protected]', | ||
'mailto:[email protected]', | ||
'mailto:[email protected]', | ||
]); | ||
$expected = [ | ||
new AvailabilityResult('[email protected]', false), | ||
new AvailabilityResult('[email protected]', true), | ||
new AvailabilityResult('[email protected]', false), | ||
new AvailabilityResult('[email protected]', true), | ||
new AvailabilityResult('[email protected]', false), | ||
]; | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|