diff --git a/apps/dav/lib/CalDAV/Status/StatusService.php b/apps/dav/lib/CalDAV/Status/StatusService.php index 63f865d13ced6..5c5041d3a1c4e 100644 --- a/apps/dav/lib/CalDAV/Status/StatusService.php +++ b/apps/dav/lib/CalDAV/Status/StatusService.php @@ -85,9 +85,11 @@ public function processCalendarStatus(string $userId): void { } catch (DoesNotExistException) { } - if($currentStatus !== null && $currentStatus->getMessageId() === IUserStatus::MESSAGE_CALL) { - // We don't overwrite the call status - $this->logger->debug('Call status detected, skipping calendar status change', ['user' => $userId]); + if($currentStatus !== null && $currentStatus->getMessageId() === IUserStatus::MESSAGE_CALL + || $currentStatus !== null && $currentStatus->getStatus() === IUserStatus::DND + || $currentStatus !== null && $currentStatus->getStatus() === IUserStatus::INVISIBLE) { + // We don't overwrite the call status, DND status or Invisible status + $this->logger->debug('Higher priority status detected, skipping calendar status change', ['user' => $userId]); return; } diff --git a/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php b/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php index 68110ab23d2ec..7073c02b8e429 100644 --- a/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php @@ -316,6 +316,100 @@ public function testCallStatus(): void { ->method('setUserStatus'); + $this->service->processCalendarStatus('admin'); + } + + public function testInvisibleStatus(): 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->calendarManager->expects(self::once()) + ->method('searchForPrincipal') + ->willReturn([['objects' => [[]]]]); + $userStatus = new UserStatus(); + $userStatus->setStatus(IUserStatus::INVISIBLE); + $userStatus->setStatusTimestamp(123456); + $this->userStatusService->expects(self::once()) + ->method('findByUserId') + ->willReturn($userStatus); + $this->logger->expects(self::once()) + ->method('debug'); + $this->userStatusService->expects(self::never()) + ->method('revertUserStatus'); + $this->userStatusService->expects(self::never()) + ->method('setUserStatus'); + + + $this->service->processCalendarStatus('admin'); + } + + public function testDNDStatus(): 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->calendarManager->expects(self::once()) + ->method('searchForPrincipal') + ->willReturn([['objects' => [[]]]]); + $userStatus = new UserStatus(); + $userStatus->setStatus(IUserStatus::DND); + $userStatus->setStatusTimestamp(123456); + $this->userStatusService->expects(self::once()) + ->method('findByUserId') + ->willReturn($userStatus); + $this->logger->expects(self::once()) + ->method('debug'); + $this->userStatusService->expects(self::never()) + ->method('revertUserStatus'); + $this->userStatusService->expects(self::never()) + ->method('setUserStatus'); + + $this->service->processCalendarStatus('admin'); } }