From 80bc1c2d6caad27514c9e8eb8f5feba3c330baea Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Mon, 16 Dec 2024 21:20:50 +0100 Subject: [PATCH 1/3] feat(ocp): calendar event builder api Signed-off-by: Richard Steinmetz --- .reuse/dep5 | 4 + lib/composer/composer/autoload_classmap.php | 2 + lib/composer/composer/autoload_static.php | 2 + lib/private/Calendar/CalendarEventBuilder.php | 132 ++++++++++++++++ lib/private/Calendar/Manager.php | 30 ++-- lib/public/Calendar/ICalendarEventBuilder.php | 106 +++++++++++++ lib/public/Calendar/IManager.php | 8 + tests/data/ics/event-builder-complete.ics | 16 ++ .../ics/event-builder-without-attendees.ics | 13 ++ .../lib/Calendar/CalendarEventBuilderTest.php | 146 ++++++++++++++++++ tests/lib/Calendar/ManagerTest.php | 53 +++++-- 11 files changed, 485 insertions(+), 27 deletions(-) create mode 100644 lib/private/Calendar/CalendarEventBuilder.php create mode 100644 lib/public/Calendar/ICalendarEventBuilder.php create mode 100644 tests/data/ics/event-builder-complete.ics create mode 100644 tests/data/ics/event-builder-without-attendees.ics create mode 100644 tests/lib/Calendar/CalendarEventBuilderTest.php diff --git a/.reuse/dep5 b/.reuse/dep5 index 12689bfc426..a3a24a3344d 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -334,3 +334,7 @@ License: CC0-1.0 Files: apps/theming/fonts/OpenDyslexic-Bold.otf apps/theming/fonts/OpenDyslexic-Regular.otf Copyright: 2012-2019 Abbie Gonzalez , with Reserved Font Name OpenDyslexic. License: OFL-1.1-RFN + +Files: tests/data/ics/event-builder-complete.ics tests/data/ics/event-builder-without-attendees.ics +Copyright: 2024 Nextcloud GmbH and Nextcloud contributors +License: AGPL-3.0-or-later diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index fd5d9e62ba6..200e2e75612 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -192,6 +192,7 @@ return array( 'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php', 'OCP\\Calendar\\Exceptions\\CalendarException' => $baseDir . '/lib/public/Calendar/Exceptions/CalendarException.php', 'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php', + 'OCP\\Calendar\\ICalendarEventBuilder' => $baseDir . '/lib/public/Calendar/ICalendarEventBuilder.php', 'OCP\\Calendar\\ICalendarIsShared' => $baseDir . '/lib/public/Calendar/ICalendarIsShared.php', 'OCP\\Calendar\\ICalendarIsWritable' => $baseDir . '/lib/public/Calendar/ICalendarIsWritable.php', 'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php', @@ -1116,6 +1117,7 @@ return array( 'OC\\Broadcast\\Events\\BroadcastEvent' => $baseDir . '/lib/private/Broadcast/Events/BroadcastEvent.php', 'OC\\Cache\\CappedMemoryCache' => $baseDir . '/lib/private/Cache/CappedMemoryCache.php', 'OC\\Cache\\File' => $baseDir . '/lib/private/Cache/File.php', + 'OC\\Calendar\\CalendarEventBuilder' => $baseDir . '/lib/private/Calendar/CalendarEventBuilder.php', 'OC\\Calendar\\CalendarQuery' => $baseDir . '/lib/private/Calendar/CalendarQuery.php', 'OC\\Calendar\\Manager' => $baseDir . '/lib/private/Calendar/Manager.php', 'OC\\Calendar\\Resource\\Manager' => $baseDir . '/lib/private/Calendar/Resource/Manager.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index d9af7846bd8..a7a8e5a800f 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -241,6 +241,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php', 'OCP\\Calendar\\Exceptions\\CalendarException' => __DIR__ . '/../../..' . '/lib/public/Calendar/Exceptions/CalendarException.php', 'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php', + 'OCP\\Calendar\\ICalendarEventBuilder' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarEventBuilder.php', 'OCP\\Calendar\\ICalendarIsShared' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsShared.php', 'OCP\\Calendar\\ICalendarIsWritable' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsWritable.php', 'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.php', @@ -1165,6 +1166,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Broadcast\\Events\\BroadcastEvent' => __DIR__ . '/../../..' . '/lib/private/Broadcast/Events/BroadcastEvent.php', 'OC\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/private/Cache/CappedMemoryCache.php', 'OC\\Cache\\File' => __DIR__ . '/../../..' . '/lib/private/Cache/File.php', + 'OC\\Calendar\\CalendarEventBuilder' => __DIR__ . '/../../..' . '/lib/private/Calendar/CalendarEventBuilder.php', 'OC\\Calendar\\CalendarQuery' => __DIR__ . '/../../..' . '/lib/private/Calendar/CalendarQuery.php', 'OC\\Calendar\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Manager.php', 'OC\\Calendar\\Resource\\Manager' => __DIR__ . '/../../..' . '/lib/private/Calendar/Resource/Manager.php', diff --git a/lib/private/Calendar/CalendarEventBuilder.php b/lib/private/Calendar/CalendarEventBuilder.php new file mode 100644 index 00000000000..9198d383ef9 --- /dev/null +++ b/lib/private/Calendar/CalendarEventBuilder.php @@ -0,0 +1,132 @@ +startDate = $start; + return $this; + } + + public function setEndDate(DateTimeInterface $end): ICalendarEventBuilder { + $this->endDate = $end; + return $this; + } + + public function setSummary(string $summary): ICalendarEventBuilder { + $this->summary = $summary; + return $this; + } + + public function setDescription(string $description): ICalendarEventBuilder { + $this->description = $description; + return $this; + } + + public function setLocation(string $location): ICalendarEventBuilder { + $this->location = $location; + return $this; + } + + public function setOrganizer(string $email, ?string $commonName = null): ICalendarEventBuilder { + $this->organizer = [$email, $commonName]; + return $this; + } + + public function addAttendee(string $email, ?string $commonName = null): ICalendarEventBuilder { + $this->attendees[] = [$email, $commonName]; + return $this; + } + + public function toIcs(): string { + if ($this->startDate === null) { + throw new InvalidArgumentException('Event is missing a start date'); + } + + if ($this->endDate === null) { + throw new InvalidArgumentException('Event is missing an end date'); + } + + if ($this->summary === null) { + throw new InvalidArgumentException('Event is missing a summary'); + } + + if ($this->organizer === null && $this->attendees !== []) { + throw new InvalidArgumentException('Event has attendees but is missing an organizer'); + } + + $vcalendar = new VCalendar(); + $props = [ + 'UID' => $this->uid, + 'DTSTAMP' => $this->timeFactory->now(), + 'SUMMARY' => $this->summary, + 'DTSTART' => $this->startDate, + 'DTEND' => $this->endDate, + ]; + if ($this->description !== null) { + $props['DESCRIPTION'] = $this->description; + } + if ($this->location !== null) { + $props['LOCATION'] = $this->location; + } + /** @var VEvent $vevent */ + $vevent = $vcalendar->add('VEVENT', $props); + if ($this->organizer !== null) { + self::addAttendeeToVEvent($vevent, 'ORGANIZER', $this->organizer); + } + foreach ($this->attendees as $attendee) { + self::addAttendeeToVEvent($vevent, 'ATTENDEE', $attendee); + } + return $vcalendar->serialize(); + } + + public function createInCalendar(ICreateFromString $calendar): string { + $fileName = $this->uid . '.ics'; + $calendar->createFromString($fileName, $this->toIcs()); + return $fileName; + } + + /** + * @param array{0: string, 1: ?string} $tuple A tuple of [$email, $commonName] where $commonName may be null. + */ + private static function addAttendeeToVEvent(VEvent $vevent, string $name, array $tuple): void { + [$email, $cn] = $tuple; + if (!str_starts_with($email, 'mailto:')) { + $email = "mailto:$email"; + } + $params = []; + if ($cn !== null) { + $params['CN'] = $cn; + } + $vevent->add($name, $email, $params); + } +} diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index ba2124a5c23..3469193a364 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -12,6 +12,7 @@ use OC\AppFramework\Bootstrap\Coordinator; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Calendar\Exceptions\CalendarException; use OCP\Calendar\ICalendar; +use OCP\Calendar\ICalendarEventBuilder; use OCP\Calendar\ICalendarIsShared; use OCP\Calendar\ICalendarIsWritable; use OCP\Calendar\ICalendarProvider; @@ -19,6 +20,7 @@ use OCP\Calendar\ICalendarQuery; use OCP\Calendar\ICreateFromString; use OCP\Calendar\IHandleImipMessage; use OCP\Calendar\IManager; +use OCP\Security\ISecureRandom; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Sabre\VObject\Component\VCalendar; @@ -45,6 +47,7 @@ class Manager implements IManager { private ContainerInterface $container, private LoggerInterface $logger, private ITimeFactory $timeFactory, + private ISecureRandom $random, ) { } @@ -216,21 +219,21 @@ class Manager implements IManager { string $recipient, string $calendarData, ): bool { - + $userCalendars = $this->getCalendarsForPrincipal($principalUri); if (empty($userCalendars)) { $this->logger->warning('iMip message could not be processed because user has no calendars'); return false; } - + /** @var VCalendar $vObject|null */ $calendarObject = Reader::read($calendarData); - + if (!isset($calendarObject->METHOD) || $calendarObject->METHOD->getValue() !== 'REQUEST') { $this->logger->warning('iMip message contains an incorrect or invalid method'); return false; } - + if (!isset($calendarObject->VEVENT)) { $this->logger->warning('iMip message contains no event'); return false; @@ -242,12 +245,12 @@ class Manager implements IManager { $this->logger->warning('iMip message event dose not contains a UID'); return false; } - + if (!isset($eventObject->ATTENDEE)) { $this->logger->warning('iMip message event dose not contains any attendees'); return false; } - + foreach ($eventObject->ATTENDEE as $entry) { $address = trim(str_replace('mailto:', '', $entry->getValue())); if ($address === $recipient) { @@ -259,17 +262,17 @@ class Manager implements IManager { $this->logger->warning('iMip message event does not contain a attendee that matches the recipient'); return false; } - + foreach ($userCalendars as $calendar) { - + if (!$calendar instanceof ICalendarIsWritable && !$calendar instanceof ICalendarIsShared) { continue; } - + if ($calendar->isDeleted() || !$calendar->isWritable() || $calendar->isShared()) { continue; } - + if (!empty($calendar->search($recipient, ['ATTENDEE'], ['uid' => $eventObject->UID->getValue()]))) { try { if ($calendar instanceof IHandleImipMessage) { @@ -282,7 +285,7 @@ class Manager implements IManager { } } } - + $this->logger->warning('iMip message event could not be processed because the no corresponding event was found in any calendar'); return false; } @@ -464,4 +467,9 @@ class Manager implements IManager { return false; } } + + public function createEventBuilder(): ICalendarEventBuilder { + $uid = $this->random->generate(32, ISecureRandom::CHAR_ALPHANUMERIC); + return new CalendarEventBuilder($uid, $this->timeFactory); + } } diff --git a/lib/public/Calendar/ICalendarEventBuilder.php b/lib/public/Calendar/ICalendarEventBuilder.php new file mode 100644 index 00000000000..88b8f06b60a --- /dev/null +++ b/lib/public/Calendar/ICalendarEventBuilder.php @@ -0,0 +1,106 @@ +timeFactory = $this->createMock(ITimeFactory::class); + $this->timeFactory->method('now') + ->willReturn(new DateTimeImmutable('20250105T000000Z')); + + $this->calendarEventBuilder = new CalendarEventBuilder( + 'event-uid-123', + $this->timeFactory, + ); + } + + public function testToIcs(): void { + $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z')); + $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z')); + $this->calendarEventBuilder->setSummary('My event'); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + $this->calendarEventBuilder->setOrganizer('mailto:organizer@domain.tld'); + $this->calendarEventBuilder->addAttendee('mailto:attendee1@domain.tld'); + $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld'); + + $expected = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-complete.ics'); + $actual = $this->calendarEventBuilder->toIcs(); + $this->assertEquals($expected, $actual); + } + + public function testToIcsWithoutOrganizerAndAttendees(): void { + $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z')); + $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z')); + $this->calendarEventBuilder->setSummary('My event'); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + + $expected = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-without-attendees.ics'); + $actual = $this->calendarEventBuilder->toIcs(); + $this->assertEquals($expected, $actual); + } + + public function testToIcsWithoutMailtoPrefix(): void { + $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z')); + $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z')); + $this->calendarEventBuilder->setSummary('My event'); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + $this->calendarEventBuilder->setOrganizer('organizer@domain.tld'); + $this->calendarEventBuilder->addAttendee('attendee1@domain.tld'); + $this->calendarEventBuilder->addAttendee('attendee2@domain.tld'); + + $expected = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-complete.ics'); + $actual = $this->calendarEventBuilder->toIcs(); + $this->assertEquals($expected, $actual); + } + + public function testCreateInCalendar(): void { + $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z')); + $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z')); + $this->calendarEventBuilder->setSummary('My event'); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + $this->calendarEventBuilder->setOrganizer('organizer@domain.tld'); + $this->calendarEventBuilder->addAttendee('attendee1@domain.tld'); + $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld'); + + $expectedIcs = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-complete.ics'); + $calendar = $this->createMock(ICreateFromString::class); + $calendar->expects(self::once()) + ->method('createFromString') + ->with('event-uid-123.ics', $expectedIcs); + + $actual = $this->calendarEventBuilder->createInCalendar($calendar); + $this->assertEquals('event-uid-123.ics', $actual); + } + + public function testToIcsWithoutStartDate(): void { + $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z')); + $this->calendarEventBuilder->setSummary('My event'); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + $this->calendarEventBuilder->setOrganizer('organizer@domain.tld'); + $this->calendarEventBuilder->addAttendee('attendee1@domain.tld'); + $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld'); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/start date/i'); + $this->calendarEventBuilder->toIcs(); + } + + public function testToIcsWithoutEndDate(): void { + $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z')); + $this->calendarEventBuilder->setSummary('My event'); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + $this->calendarEventBuilder->setOrganizer('organizer@domain.tld'); + $this->calendarEventBuilder->addAttendee('attendee1@domain.tld'); + $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld'); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/end date/i'); + $this->calendarEventBuilder->toIcs(); + } + + public function testToIcsWithoutSummary(): void { + $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z')); + $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z')); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + $this->calendarEventBuilder->setOrganizer('organizer@domain.tld'); + $this->calendarEventBuilder->addAttendee('attendee1@domain.tld'); + $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld'); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/summary/i'); + $this->calendarEventBuilder->toIcs(); + } + + public function testToIcsWithoutOrganizerWithAttendees(): void { + $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z')); + $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z')); + $this->calendarEventBuilder->setSummary('My event'); + $this->calendarEventBuilder->setDescription('Foo bar baz'); + $this->calendarEventBuilder->addAttendee('attendee1@domain.tld'); + $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld'); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessageMatches('/organizer/i'); + $this->calendarEventBuilder->toIcs(); + } +} diff --git a/tests/lib/Calendar/ManagerTest.php b/tests/lib/Calendar/ManagerTest.php index f0ca278f352..a7aeed98046 100644 --- a/tests/lib/Calendar/ManagerTest.php +++ b/tests/lib/Calendar/ManagerTest.php @@ -14,6 +14,7 @@ use OCP\Calendar\ICalendarIsShared; use OCP\Calendar\ICalendarIsWritable; use OCP\Calendar\ICreateFromString; use OCP\Calendar\IHandleImipMessage; +use OCP\Security\ISecureRandom; use PHPUnit\Framework\MockObject\MockObject; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -44,6 +45,9 @@ class ManagerTest extends TestCase { /** @var ITimeFactory&MockObject */ private $time; + /** @var ISecureRandom&MockObject */ + private ISecureRandom $secureRandom; + private VCalendar $vCalendar1a; protected function setUp(): void { @@ -53,12 +57,14 @@ class ManagerTest extends TestCase { $this->container = $this->createMock(ContainerInterface::class); $this->logger = $this->createMock(LoggerInterface::class); $this->time = $this->createMock(ITimeFactory::class); + $this->secureRandom = $this->createMock(ISecureRandom::class); $this->manager = new Manager( $this->coordinator, $this->container, $this->logger, $this->time, + $this->secureRandom, ); // construct calendar with a 1 hour event and same start/end time zones @@ -260,7 +266,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -291,7 +298,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -321,7 +329,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -352,7 +361,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -384,7 +394,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -416,7 +427,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -448,7 +460,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -491,7 +504,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -534,7 +548,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->onlyMethods(['getCalendarsForPrincipal']) ->getMock(); @@ -612,7 +627,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->setMethods([ 'getCalendarsForPrincipal' @@ -643,7 +659,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->setMethods([ 'getCalendarsForPrincipal' @@ -680,7 +697,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->setMethods([ 'getCalendarsForPrincipal' @@ -767,7 +785,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->setMethods([ 'getCalendarsForPrincipal' @@ -800,7 +819,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->setMethods([ 'getCalendarsForPrincipal' @@ -837,7 +857,8 @@ class ManagerTest extends TestCase { $this->coordinator, $this->container, $this->logger, - $this->time + $this->time, + $this->secureRandom, ]) ->setMethods([ 'getCalendarsForPrincipal' @@ -866,7 +887,7 @@ class ManagerTest extends TestCase { $result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); $this->assertTrue($result); } - + private function getVCalendarReply(): Document { $data = << Date: Wed, 8 Jan 2025 11:12:37 +0100 Subject: [PATCH 2/3] fix(license): Move license closer to file Signed-off-by: Joas Schilling --- .reuse/dep5 | 4 ---- tests/data/ics/event-builder-complete.ics.license | 2 ++ tests/data/ics/event-builder-without-attendees.ics.license | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 tests/data/ics/event-builder-complete.ics.license create mode 100644 tests/data/ics/event-builder-without-attendees.ics.license diff --git a/.reuse/dep5 b/.reuse/dep5 index a3a24a3344d..12689bfc426 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -334,7 +334,3 @@ License: CC0-1.0 Files: apps/theming/fonts/OpenDyslexic-Bold.otf apps/theming/fonts/OpenDyslexic-Regular.otf Copyright: 2012-2019 Abbie Gonzalez , with Reserved Font Name OpenDyslexic. License: OFL-1.1-RFN - -Files: tests/data/ics/event-builder-complete.ics tests/data/ics/event-builder-without-attendees.ics -Copyright: 2024 Nextcloud GmbH and Nextcloud contributors -License: AGPL-3.0-or-later diff --git a/tests/data/ics/event-builder-complete.ics.license b/tests/data/ics/event-builder-complete.ics.license new file mode 100644 index 00000000000..f7f52efa96f --- /dev/null +++ b/tests/data/ics/event-builder-complete.ics.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors +SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/data/ics/event-builder-without-attendees.ics.license b/tests/data/ics/event-builder-without-attendees.ics.license new file mode 100644 index 00000000000..f7f52efa96f --- /dev/null +++ b/tests/data/ics/event-builder-without-attendees.ics.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors +SPDX-License-Identifier: AGPL-3.0-or-later From 42fa3abc3ef31d6bfebc29b76c8f55da45c1d16c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Jan 2025 11:14:30 +0100 Subject: [PATCH 3/3] docs(eventbuilder): Mention how to get the EventBuilder from DI Signed-off-by: Joas Schilling --- lib/public/Calendar/ICalendarEventBuilder.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/public/Calendar/ICalendarEventBuilder.php b/lib/public/Calendar/ICalendarEventBuilder.php index 88b8f06b60a..8afc817a61e 100644 --- a/lib/public/Calendar/ICalendarEventBuilder.php +++ b/lib/public/Calendar/ICalendarEventBuilder.php @@ -16,7 +16,11 @@ use OCP\Calendar\Exceptions\CalendarException; /** * The calendar event builder can be used to conveniently build a calendar event and then serialize * it to a ICS string. The ICS string can be submitted to calendar instances implementing the - * \OCP\Calendar\ICreateFromString interface. + * {@see \OCP\Calendar\ICreateFromString} interface. + * + * Also note this class can not be injected directly with dependency injection. + * Instead, inject {@see \OCP\Calendar\IManager} and use + * {@see \OCP\Calendar\IManager::createEventBuilder()} afterwards. * * All setters return self to allow chaining method calls. *