diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-01-15 08:53:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 08:53:34 +0100 |
commit | eda8a4169b57810135396b8865280628d452939f (patch) | |
tree | 57f06a5b6ca90dcb5afa5f345a463c34290b9a4a /apps/dav | |
parent | 7fdb16affcf2d59676d6b8d91d8f163af3d49715 (diff) | |
parent | e981619c0183619e0e63e6cc4b42b3dcc7ebeee8 (diff) | |
download | nextcloud-server-eda8a4169b57810135396b8865280628d452939f.tar.gz nextcloud-server-eda8a4169b57810135396b8865280628d452939f.zip |
Merge pull request #42619 from nextcloud/bugfix/noid/caldav-status-undefined-index-0
fix(dav): Fix user status "Undefined array key 0 at StatusService.php…
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CalDAV/Status/StatusService.php | 11 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php | 44 |
2 files changed, 51 insertions, 4 deletions
diff --git a/apps/dav/lib/CalDAV/Status/StatusService.php b/apps/dav/lib/CalDAV/Status/StatusService.php index 11be9d8b2b8..3fcd4957fa2 100644 --- a/apps/dav/lib/CalDAV/Status/StatusService.php +++ b/apps/dav/lib/CalDAV/Status/StatusService.php @@ -94,12 +94,15 @@ class StatusService { } // Filter events to see if we have any that apply to the calendar status - $applicableEvents = array_filter($calendarEvents, function (array $calendarEvent) use ($userStatusTimestamp) { + $applicableEvents = array_filter($calendarEvents, static function (array $calendarEvent) use ($userStatusTimestamp): bool { + if (empty($calendarEvent['objects'])) { + return false; + } $component = $calendarEvent['objects'][0]; - if(isset($component['X-NEXTCLOUD-OUT-OF-OFFICE'])) { + if (isset($component['X-NEXTCLOUD-OUT-OF-OFFICE'])) { return false; } - if(isset($component['DTSTART']) && $userStatusTimestamp !== null) { + if (isset($component['DTSTART']) && $userStatusTimestamp !== null) { /** @var DateTimeImmutable $dateTime */ $dateTime = $component['DTSTART'][0]; $timestamp = $dateTime->getTimestamp(); @@ -108,7 +111,7 @@ class StatusService { } } // Ignore events that are transparent - if(isset($component['TRANSP']) && strcasecmp($component['TRANSP'][0], 'TRANSPARENT') === 0) { + if (isset($component['TRANSP']) && strcasecmp($component['TRANSP'][0], 'TRANSPARENT') === 0) { return false; } return true; diff --git a/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php b/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php index 498a0b849fa..c60f3a0c325 100644 --- a/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php @@ -229,6 +229,50 @@ class StatusServiceTest extends TestCase { $this->service->processCalendarStatus('admin'); } + public function testCalendarNoEventObjects(): void { + $user = $this->createConfiguredMock(IUser::class, [ + 'getUID' => 'admin', + ]); + + $this->userManager->expects(self::once()) + ->method('get') + ->willReturn($user); + $this->availabilityCoordinator->expects(self::once()) + ->method('getCurrentOutOfOfficeData') + ->willReturn(null); + $this->availabilityCoordinator->expects(self::never()) + ->method('isInEffect'); + $this->cache->expects(self::once()) + ->method('get') + ->willReturn(null); + $this->cache->expects(self::once()) + ->method('set'); + $this->calendarManager->expects(self::once()) + ->method('getCalendarsForPrincipal') + ->willReturn([$this->createMock(CalendarImpl::class)]); + $this->calendarManager->expects(self::once()) + ->method('newQuery') + ->willReturn(new CalendarQuery('admin')); + $this->timeFactory->expects(self::exactly(2)) + ->method('getDateTime') + ->willReturn(new \DateTime()); + $this->userStatusService->expects(self::once()) + ->method('findByUserId') + ->willThrowException(new DoesNotExistException('')); + $this->calendarManager->expects(self::once()) + ->method('searchForPrincipal') + ->willReturn([['objects' => []]]); + $this->userStatusService->expects(self::once()) + ->method('revertUserStatus'); + $this->logger->expects(self::once()) + ->method('debug'); + $this->userStatusService->expects(self::never()) + ->method('setUserStatus'); + + + $this->service->processCalendarStatus('admin'); + } + public function testCalendarEvent(): void { $user = $this->createConfiguredMock(IUser::class, [ 'getUID' => 'admin', |