Skip to content

Commit

Permalink
Merge pull request #6741 from nextcloud/fix/issue-6326-check-for-dele…
Browse files Browse the repository at this point in the history
…ted-calendar

fix: do not show items from deleted calendars in widget
  • Loading branch information
SebastianKrupinski authored Feb 19, 2025
2 parents 77d1943 + 9d1d26f commit 5bfb904
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Dashboard/CalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
];
$widgetItems = [];
foreach ($calendars as $calendar) {
if ($calendar->isDeleted()) {
continue;
}
$searchResult = $calendar->search('', [], $options, $limit);
foreach ($searchResult as $calendarEvent) {
// Find first recurrence in the future
Expand Down
47 changes: 47 additions & 0 deletions tests/php/unit/Dashbaord/CalendarWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,51 @@ public function testGetItems() : void {
$this->assertCount(1, $widgets);
$this->assertEquals($widgets[0], $widget);
}

public function testGetItemsWithDeletedCalendar() {
$userId = 'admin';
$calendar = $this->createMock(CalendarImpl::class);
$calendars = [$calendar];
$time = 1665550936;
$start = (new DateTimeImmutable())->setTimestamp($time);
$twoWeeks = $start->add(new \DateInterval('P14D'));
$options = [
'timerange' => [
'start' => $start,
'end' => $twoWeeks,
]
];
$limit = 7;
$result = [
'id' => '3599',
'uid' => '59d30b6c-5a31-4d28-b1d6-c8f928180e96',
'uri' => '60EE4FCB-2144-4811-BBD3-FFEA44739F40.ics',
'objects' => [
[
'DTSTART' => [
$start
],
'SUMMARY' => [
'Test',
]
]
]
];

$this->calendarManager->expects(self::once())
->method('getCalendarsForPrincipal')
->with('principals/users/' . $userId)
->willReturn($calendars);
$this->timeFactory->expects(self::once())
->method('getTime')
->willReturn($time);
$calendar->expects(self::once())
->method('isDeleted')
->willReturn(true);
$calendar->expects(self::never())
->method('search');

$widgets = $this->widget->getItems($userId);
$this->assertCount(0, $widgets);
}
}

0 comments on commit 5bfb904

Please sign in to comment.