From 7c61e06b7407fc6833dbdd1c3f9e99c8338f1309 Mon Sep 17 00:00:00 2001 From: David Dreschner Date: Thu, 12 Mar 2026 16:56:41 +0100 Subject: [PATCH] feat(CalDAV): Add function to get the token of a publicly shared calendar Signed-off-by: David Dreschner --- apps/dav/lib/CalDAV/CalendarImpl.php | 11 ++++++++-- .../tests/unit/CalDAV/CalendarImplTest.php | 17 ++++++++++++--- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/public/Calendar/ICalendarIsPublic.php | 21 +++++++++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 lib/public/Calendar/ICalendarIsPublic.php diff --git a/apps/dav/lib/CalDAV/CalendarImpl.php b/apps/dav/lib/CalDAV/CalendarImpl.php index 7b47963240e..80e4d14f5f6 100644 --- a/apps/dav/lib/CalDAV/CalendarImpl.php +++ b/apps/dav/lib/CalDAV/CalendarImpl.php @@ -16,6 +16,7 @@ use OCP\Calendar\CalendarExportOptions; use OCP\Calendar\Exceptions\CalendarException; use OCP\Calendar\ICalendarExport; use OCP\Calendar\ICalendarIsEnabled; +use OCP\Calendar\ICalendarIsPublic; use OCP\Calendar\ICalendarIsShared; use OCP\Calendar\ICalendarIsWritable; use OCP\Calendar\ICreateFromString; @@ -32,7 +33,7 @@ use Sabre\VObject\Reader; use function Sabre\Uri\split as uriSplit; -class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarExport, ICalendarIsEnabled { +class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarExport, ICalendarIsEnabled, ICalendarIsPublic { public function __construct( private Calendar $calendar, /** @var array */ @@ -168,6 +169,13 @@ class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIs return $this->calendar->isShared(); } + /** + * @since 33.0.1, 32.0.7, 31.0.14.1, 30.0.17.8 + */ + public function getPublicToken(): ?string { + return $this->calendar->getPublishStatus() ?: null; + } + /** * @throws CalendarException */ @@ -336,5 +344,4 @@ class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIs } } } - } diff --git a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php index 6c966d800c7..5df78b02d8f 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php @@ -33,7 +33,7 @@ class CalendarImplTest extends \Test\TestCase { $this->backend = $this->createMock(CalDavBackend::class); $this->calendar = $this->createMock(Calendar::class); $this->calendarInfo = [ - 'id' => 'fancy_id_123', + 'id' => 123, '{DAV:}displayname' => 'user readable name 123', '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC', 'uri' => '/this/is/a/uri', @@ -62,7 +62,7 @@ class CalendarImplTest extends \Test\TestCase { public function testGetKey(): void { - $this->assertEquals($this->calendarImpl->getKey(), 'fancy_id_123'); + $this->assertEquals($this->calendarImpl->getKey(), '123'); } public function testGetDisplayname(): void { @@ -73,6 +73,18 @@ class CalendarImplTest extends \Test\TestCase { $this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC'); } + public function testGetPublicToken(): void { + $publicToken = $this->calendar->setPublishStatus(true); + + $this->assertEquals($this->calendarImpl->getPublicToken(), $publicToken); + } + + public function testGetPublicTokenWithPrivateCalendar(): void { + $this->calendar->setPublishStatus(false); + + $this->assertNull($this->calendarImpl->getPublicToken()); + } + public function testSearch(): void { $this->backend->expects($this->once()) ->method('search') @@ -266,5 +278,4 @@ class CalendarImplTest extends \Test\TestCase { $calendarImpl->handleIMipMessage('fakeUser', $vObject->serialize()); } - } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 93f5def20a5..aaf6df28101 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -222,6 +222,7 @@ return array( 'OCP\\Calendar\\ICalendarEventBuilder' => $baseDir . '/lib/public/Calendar/ICalendarEventBuilder.php', 'OCP\\Calendar\\ICalendarExport' => $baseDir . '/lib/public/Calendar/ICalendarExport.php', 'OCP\\Calendar\\ICalendarIsEnabled' => $baseDir . '/lib/public/Calendar/ICalendarIsEnabled.php', + 'OCP\\Calendar\\ICalendarIsPublic' => $baseDir . '/lib/public/Calendar/ICalendarIsPublic.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', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index bc27a12cf46..c395e56acae 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -263,6 +263,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Calendar\\ICalendarEventBuilder' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarEventBuilder.php', 'OCP\\Calendar\\ICalendarExport' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarExport.php', 'OCP\\Calendar\\ICalendarIsEnabled' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsEnabled.php', + 'OCP\\Calendar\\ICalendarIsPublic' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsPublic.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', diff --git a/lib/public/Calendar/ICalendarIsPublic.php b/lib/public/Calendar/ICalendarIsPublic.php new file mode 100644 index 00000000000..1cf66de2ddc --- /dev/null +++ b/lib/public/Calendar/ICalendarIsPublic.php @@ -0,0 +1,21 @@ +