Skip to content

Commit bfe9e36

Browse files
DerDreschnerbackportbot[bot]
authored andcommitted
feat(CalDAV): Add function to get the token of a publicly shared calendar
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
1 parent 27e51e5 commit bfe9e36

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

apps/dav/lib/CalDAV/CalendarImpl.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\Calendar\Exceptions\CalendarException;
1717
use OCP\Calendar\ICalendarExport;
1818
use OCP\Calendar\ICalendarIsEnabled;
19+
use OCP\Calendar\ICalendarIsPublic;
1920
use OCP\Calendar\ICalendarIsShared;
2021
use OCP\Calendar\ICalendarIsWritable;
2122
use OCP\Calendar\ICreateFromString;
@@ -32,7 +33,7 @@
3233

3334
use function Sabre\Uri\split as uriSplit;
3435

35-
class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarExport, ICalendarIsEnabled {
36+
class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarExport, ICalendarIsEnabled, ICalendarIsPublic {
3637
public function __construct(
3738
private Calendar $calendar,
3839
/** @var array<string, mixed> */
@@ -168,6 +169,13 @@ public function isShared(): bool {
168169
return $this->calendar->isShared();
169170
}
170171

172+
/**
173+
* @since 33.0.1, 32.0.7, 31.0.14.1, 30.0.17.8
174+
*/
175+
public function getPublicToken(): ?string {
176+
return $this->calendar->getPublishStatus() ?: null;
177+
}
178+
171179
/**
172180
* @throws CalendarException
173181
*/
@@ -336,5 +344,4 @@ public function export(?CalendarExportOptions $options = null): Generator {
336344
}
337345
}
338346
}
339-
340347
}

apps/dav/tests/unit/CalDAV/CalendarImplTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function setUp(): void {
3333
$this->backend = $this->createMock(CalDavBackend::class);
3434
$this->calendar = $this->createMock(Calendar::class);
3535
$this->calendarInfo = [
36-
'id' => 'fancy_id_123',
36+
'id' => 123,
3737
'{DAV:}displayname' => 'user readable name 123',
3838
'{http://apple.com/ns/ical/}calendar-color' => '#AABBCC',
3939
'uri' => '/this/is/a/uri',
@@ -62,7 +62,7 @@ protected function setUp(): void {
6262

6363

6464
public function testGetKey(): void {
65-
$this->assertEquals($this->calendarImpl->getKey(), 'fancy_id_123');
65+
$this->assertEquals($this->calendarImpl->getKey(), '123');
6666
}
6767

6868
public function testGetDisplayname(): void {
@@ -73,6 +73,18 @@ public function testGetDisplayColor(): void {
7373
$this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC');
7474
}
7575

76+
public function testGetPublicToken(): void {
77+
$publicToken = $this->calendar->setPublishStatus(true);
78+
79+
$this->assertEquals($this->calendarImpl->getPublicToken(), $publicToken);
80+
}
81+
82+
public function testGetPublicTokenWithPrivateCalendar(): void {
83+
$this->calendar->setPublishStatus(false);
84+
85+
$this->assertNull($this->calendarImpl->getPublicToken());
86+
}
87+
7688
public function testSearch(): void {
7789
$this->backend->expects($this->once())
7890
->method('search')
@@ -266,5 +278,4 @@ public function getHrefs(): array {
266278

267279
$calendarImpl->handleIMipMessage('fakeUser', $vObject->serialize());
268280
}
269-
270281
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
'OCP\\Calendar\\ICalendarEventBuilder' => $baseDir . '/lib/public/Calendar/ICalendarEventBuilder.php',
219219
'OCP\\Calendar\\ICalendarExport' => $baseDir . '/lib/public/Calendar/ICalendarExport.php',
220220
'OCP\\Calendar\\ICalendarIsEnabled' => $baseDir . '/lib/public/Calendar/ICalendarIsEnabled.php',
221+
'OCP\\Calendar\\ICalendarIsPublic' => $baseDir . '/lib/public/Calendar/ICalendarIsPublic.php',
221222
'OCP\\Calendar\\ICalendarIsShared' => $baseDir . '/lib/public/Calendar/ICalendarIsShared.php',
222223
'OCP\\Calendar\\ICalendarIsWritable' => $baseDir . '/lib/public/Calendar/ICalendarIsWritable.php',
223224
'OCP\\Calendar\\ICalendarProvider' => $baseDir . '/lib/public/Calendar/ICalendarProvider.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
259259
'OCP\\Calendar\\ICalendarEventBuilder' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarEventBuilder.php',
260260
'OCP\\Calendar\\ICalendarExport' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarExport.php',
261261
'OCP\\Calendar\\ICalendarIsEnabled' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsEnabled.php',
262+
'OCP\\Calendar\\ICalendarIsPublic' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsPublic.php',
262263
'OCP\\Calendar\\ICalendarIsShared' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsShared.php',
263264
'OCP\\Calendar\\ICalendarIsWritable' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarIsWritable.php',
264265
'OCP\\Calendar\\ICalendarProvider' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendarProvider.php',
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCP\Calendar;
10+
11+
/**
12+
* @since 33.0.1, 32.0.7, 31.0.14.1, 30.0.17.8
13+
*/
14+
interface ICalendarIsPublic {
15+
/**
16+
* Gets the token of a publicly shared calendar.
17+
*
18+
* @since 33.0.1, 32.0.7, 31.0.14.1, 30.0.17.8
19+
*/
20+
public function getPublicToken(): ?string;
21+
}

0 commit comments

Comments
 (0)