Skip to content

Commit 08b1e01

Browse files
committed
fix(ICalendar): allow to search for event URI
Signed-off-by: Jonas <jonas@freesources.org>
1 parent 9beed5c commit 08b1e01

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,10 @@ public function search(
20622062
$outerQuery->andWhere($outerQuery->expr()->eq('uid', $outerQuery->createNamedParameter($options['uid'])));
20632063
}
20642064

2065+
if (isset($options['uri'])) {
2066+
$outerQuery->andWhere($outerQuery->expr()->eq('uri', $outerQuery->createNamedParameter($options['uri'])));
2067+
}
2068+
20652069
if (!empty($options['types'])) {
20662070
$or = [];
20672071
foreach ($options['types'] as $type) {

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,72 @@ public function testSearchShouldReturnObjectsInTheSameOrderMissingDate(): void {
18401840
$this->assertEquals('Missing DTSTART 2', $results[3]['objects'][0]['SUMMARY'][0]);
18411841
}
18421842

1843+
public function testSearchByUri(): void {
1844+
$calendarId = $this->createTestCalendar();
1845+
$uris = [];
1846+
$calData = [];
1847+
1848+
$uris[] = static::getUniqueID('calobj');
1849+
$calData[] = <<<'EOD'
1850+
BEGIN:VCALENDAR
1851+
VERSION:2.0
1852+
PRODID:Nextcloud Calendar
1853+
BEGIN:VEVENT
1854+
CREATED;VALUE=DATE-TIME:20260323T093039Z
1855+
UID:search-by-uri-test1
1856+
LAST-MODIFIED;VALUE=DATE-TIME:20260323T093039Z
1857+
DTSTAMP;VALUE=DATE-TIME:20260323T093039Z
1858+
SUMMARY:First Test Event
1859+
DTSTART;VALUE=DATE-TIME:20260323T093039Z
1860+
DTEND;VALUE=DATE-TIME:20260323T093039Z
1861+
CLASS:PUBLIC
1862+
END:VEVENT
1863+
END:VCALENDAR
1864+
EOD;
1865+
1866+
$uris[] = static::getUniqueID('calobj');
1867+
$calData[] = <<<'EOD'
1868+
BEGIN:VCALENDAR
1869+
VERSION:2.0
1870+
PRODID:Nextcloud Calendar
1871+
BEGIN:VEVENT
1872+
CREATED;VALUE=DATE-TIME:20260323T093039Z
1873+
UID:search-by-uri-test2
1874+
LAST-MODIFIED;VALUE=DATE-TIME:20260323T093039Z
1875+
DTSTAMP;VALUE=DATE-TIME:20260323T093039Z
1876+
SUMMARY:Second Test Event
1877+
DTSTART;VALUE=DATE-TIME:20260323T093039Z
1878+
DTEND;VALUE=DATE-TIME:20260323T093039Z
1879+
CLASS:PUBLIC
1880+
END:VEVENT
1881+
END:VCALENDAR
1882+
EOD;
1883+
1884+
foreach ($uris as $i => $uri) {
1885+
$this->backend->createCalendarObject($calendarId, $uri, $calData[$i]);
1886+
}
1887+
1888+
$calendarInfo = [
1889+
'id' => $calendarId,
1890+
'principaluri' => 'user1',
1891+
'{http://owncloud.org/ns}owner-principal' => 'user1',
1892+
];
1893+
1894+
// Searching by first event's URI returns this event
1895+
$results = $this->backend->search($calendarInfo, '', [], ['uri' => $uris[0]]);
1896+
$this->assertCount(1, $results);
1897+
$this->assertEquals($uris[0], $results[0]['uri']);
1898+
1899+
// Searching by second event's URI returns this event
1900+
$results = $this->backend->search($calendarInfo, '', [], ['uri' => $uris[1]]);
1901+
$this->assertCount(1, $results);
1902+
$this->assertEquals($uris[1], $results[0]['uri']);
1903+
1904+
// Searching by a non-existent URI returns nothing
1905+
$result = $this->backend->search($calendarInfo, '', [], ['uri' => 'nonexistant.ical']);
1906+
$this->assertCount(0, $result);
1907+
}
1908+
18431909
public function testUnshare(): void {
18441910
$principalGroup = 'principal:' . self::UNIT_TEST_GROUP;
18451911
$principalUser = 'principal:' . self::UNIT_TEST_USER;

lib/public/Calendar/ICalendar.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @psalm-type CalendarSearchOptions = array{
1919
* timerange?: array{start?: DateTimeInterface, end?: DateTimeInterface},
2020
* uid?: string,
21+
* uri?: string,
2122
* types?: string[],
2223
* }
2324
*/
@@ -60,6 +61,7 @@ public function getDisplayColor(): ?string;
6061
* @param array $options Optional parameters for the search:
6162
* - 'timerange' element that can have 'start' (DateTimeInterface), 'end' (DateTimeInterface), or both.
6263
* - 'uid' element to look for events with a given uid.
64+
* - 'uri' element to look for events with a given uri.
6365
* - 'types' element to only return events for a given type (e.g. VEVENT or VTODO)
6466
* @psalm-param CalendarSearchOptions $options
6567
* @param int|null $limit Limit the number of search results.

0 commit comments

Comments
 (0)