Skip to content

Commit

Permalink
fixup! fix(userstatus): set user status to 'In a meeting' if calendar…
Browse files Browse the repository at this point in the history
… is busy
  • Loading branch information
miaulalala committed Dec 18, 2023
1 parent e1056ab commit f6336cf
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apps/dav/lib/CalDAV/Status/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
94 changes: 94 additions & 0 deletions apps/dav/tests/unit/CalDAV/Status/StatusServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit f6336cf

Please sign in to comment.