Skip to content

Commit

Permalink
fix(dav): don't schedule out-of-office jobs for dates in the past
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny authored and backportbot-nextcloud[bot] committed Nov 28, 2023
1 parent 699ee7a commit ba72471
Show file tree
Hide file tree
Showing 2 changed files with 492 additions and 20 deletions.
41 changes: 21 additions & 20 deletions apps/dav/lib/Service/AbsenceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Calendar\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IUser;
use OCP\User\Events\OutOfOfficeChangedEvent;
use OCP\User\Events\OutOfOfficeClearedEvent;
Expand All @@ -50,8 +48,6 @@ public function __construct(
private IJobList $jobList,
private TimezoneService $timezoneService,
private ITimeFactory $timeFactory,
private IConfig $appConfig,
private IManager $calendarManager,
) {
}

Expand Down Expand Up @@ -97,22 +93,27 @@ public function createOrUpdateAbsence(
$this->eventDispatcher->dispatchTyped(new OutOfOfficeChangedEvent($eventData));
}

$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getStartDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
],
);
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getEndDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
],
);
$now = $this->timeFactory->getTime();
if ($eventData->getStartDate() > $now) {
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getStartDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
],
);
}
if ($eventData->getEndDate() > $now) {
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getEndDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
],
);
}

return $absence;
}
Expand Down

0 comments on commit ba72471

Please sign in to comment.