-
-
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.
feat: enable invitations for shared calendars
This is basically the original commit, but with the addition that shared calendars in to account and adjusts their uri s.t. the Sabre library can find the returned object uri in the user's calendar collection. Signed-off-by: Claus-Justus Heine <[email protected]> Try to fix some psalm things. No change to the code apart from that. Signed-off-by: Claus-Justus Heine <[email protected]> getCalendarObjectByUID(): prefer objects in shared writable calendars over private objects. Signed-off-by: Claus-Justus Heine <[email protected]> fix: include the principalUri for dav_shares clause Signed-off-by: Daniel Kesselberg <[email protected]> feat: use getPrincipalURI only for shared calendars Signed-off-by: Daniel Kesselberg <[email protected]>
- Loading branch information
Showing
3 changed files
with
238 additions
and
13 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 |
---|---|---|
|
@@ -36,15 +36,23 @@ | |
use OCP\IL10N; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\Log\NullLogger; | ||
use Sabre\CalDAV\Backend\BackendInterface; | ||
use Sabre\DAV\PropFind; | ||
use Sabre\DAV\Server; | ||
use Sabre\DAV\Tree; | ||
use Sabre\DAV\Xml\Property\Href; | ||
use Sabre\DAV\Xml\Property\LocalHref; | ||
use Sabre\DAVACL\IPrincipal; | ||
use Sabre\HTTP\Request; | ||
use Sabre\HTTP\Response; | ||
use Sabre\HTTP\ResponseInterface; | ||
use Sabre\VObject\Component\VCalendar; | ||
use Sabre\VObject\Component\VEvent; | ||
use Sabre\VObject\ITip\Message; | ||
use Sabre\VObject\Parameter; | ||
use Sabre\VObject\Property\ICalendar\CalAddress; | ||
use Sabre\VObject\Reader; | ||
use Sabre\Xml\Service; | ||
use Test\TestCase; | ||
|
||
|
@@ -408,4 +416,113 @@ public function testPropFindDefaultCalendarUrl(string $principalUri, ?string $ca | |
$result = $propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL); | ||
$this->assertEquals('/remote.php/dav/'. $calendarHome . '/' . $calendarUri, $result->getHref()); | ||
} | ||
|
||
public function testCalendarObjectChangeShared() { | ||
// Calendar | ||
$calendarNode = new Calendar( | ||
$this->createMock(BackendInterface::class), | ||
[ | ||
'uri' => 'alice-bob_shared_by_alice', | ||
'principaluri' => 'principals/users/bob', | ||
'{http://owncloud.org/ns}owner-principal' => 'principals/users/alice' | ||
], | ||
$this->createMock(IL10N::class), | ||
$this->createMock(IConfig::class), | ||
new NullLogger() | ||
); | ||
|
||
// Tree | ||
$tree = $this->createMock(Tree::class); | ||
$tree->expects($this->once()) | ||
->method('getNodeForPath') | ||
->with('calendars/bob/alice-bob_shared_by_alice') | ||
->willReturn($calendarNode); | ||
|
||
$this->server->tree = $tree; | ||
|
||
// Request | ||
$request = new Request( | ||
'PUT', | ||
'/remote.php/dav/calendars/bob/alice-bob_shared_by_alice/B0DC78AE-6DD7-47E3-80BE-89F23E6D5383.ics' | ||
); | ||
$request->setBaseUrl('/remote.php/dav/'); | ||
|
||
$this->server->httpRequest = $request; | ||
|
||
// Server.getProperties | ||
$addresses = new LocalHref([ | ||
'mailto:[email protected]', | ||
'/remote.php/dav/principals/users/bob/' | ||
]); | ||
|
||
$this->server->expects($this->once()) | ||
->method('getProperties') | ||
->with('principals/users/bob', ['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set']) | ||
->willReturn([ | ||
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => $addresses | ||
]); | ||
|
||
$response = new Response(); | ||
|
||
// VCalendar / VEvent | ||
$data = 'BEGIN:VCALENDAR | ||
CALSCALE:GREGORIAN | ||
VERSION:2.0 | ||
PRODID:-//IDN nextcloud.com//Calendar app 4.5.0-alpha.1//EN | ||
BEGIN:VEVENT | ||
CREATED:20230808T153326Z | ||
DTSTAMP:20230808T164811Z | ||
LAST-MODIFIED:20230808T164811Z | ||
UID:B0DC78AE-6DD7-47E3-80BE-89F23E6D5383 | ||
DTSTART:20330810T150000 | ||
DTEND:20330810T153000 | ||
SUMMARY:Event in shared calendar | ||
ATTENDEE;CN=Jane;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE;LANGUAGE=en:mailto:[email protected] | ||
ATTENDEE;CN=John;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE;LANGUAGE=en:mailto:[email protected] | ||
ORGANIZER;CN=Bob:mailto:[email protected] | ||
END:VEVENT | ||
END:VCALENDAR | ||
'; | ||
|
||
/** @var VCalendar $vCal */ | ||
$vCal = Reader::read($data); | ||
|
||
$modified = false; | ||
$isNew = true; | ||
|
||
/** @var Message[] $iTipMessages */ | ||
$iTipMessages = []; | ||
|
||
$this->server->expects($this->exactly(2)) | ||
->method('emit') | ||
->willReturnCallback(function (string $eventName, array $arguments = [], ?callable $continueCallBack = null) use (&$iTipMessages) { | ||
$this->assertEquals('schedule', $eventName); | ||
$this->assertCount(1, $arguments); | ||
$iTipMessages[] = $arguments[0]; | ||
return true; | ||
}); | ||
|
||
$this->plugin->calendarObjectChange( | ||
$request, | ||
$response, | ||
$vCal, | ||
'calendars/bob/alice-bob_shared_by_alice', | ||
$modified, | ||
$isNew | ||
); | ||
|
||
/** | ||
* VCalendar contains an event organized by Bob with Jane and John as attendees. | ||
* The expected outcome is that for Jane and John an iTip message is generated. | ||
*/ | ||
$this->assertCount(2, $iTipMessages); | ||
|
||
$this->assertEquals('mailto:[email protected]', $iTipMessages[0]->sender); | ||
$this->assertEquals('mailto:[email protected]', $iTipMessages[0]->recipient); | ||
$this->assertTrue($iTipMessages[0]->significantChange); | ||
|
||
$this->assertEquals('mailto:[email protected]', $iTipMessages[1]->sender); | ||
$this->assertEquals('mailto:[email protected]', $iTipMessages[1]->recipient); | ||
$this->assertTrue($iTipMessages[1]->significantChange); | ||
} | ||
} |