Merge pull request #59078 from nextcloud/backport/58897/stable32

[stable32] feat(CalDAV): Add function to get the token of a publicly shared calendar
This commit is contained in:
Andy Scherzinger 2026-03-19 17:15:13 +01:00 committed by GitHub
commit 33d9fd3ebc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 5 deletions

View file

@ -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<string, mixed> */
@ -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
}
}
}
}

View file

@ -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());
}
}

View file

@ -218,6 +218,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',

View file

@ -259,6 +259,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',

View file

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Calendar;
/**
* @since 33.0.1, 32.0.7, 31.0.14.1, 30.0.17.8
*/
interface ICalendarIsPublic {
/**
* Gets the token of a publicly shared calendar.
*
* @since 33.0.1, 32.0.7, 31.0.14.1, 30.0.17.8
*/
public function getPublicToken(): ?string;
}