Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apps/dav/lib/CalDAV/Status/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ public function processCalendarStatus(string $userId): void {
}

// 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();
Expand All @@ -108,7 +111,7 @@ public function processCalendarStatus(string $userId): void {
}
}
// 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;
Expand Down
44 changes: 44 additions & 0 deletions apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,50 @@ public function testNoCalendarEvents(): void {
$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',
Expand Down