userSession->getUser(); if ($user === null) { return JsonResponse::fail([], Http::STATUS_FORBIDDEN); } $account = $this->accountService->findById($accountId); if ($account->getUserId() !== $user->getUID()) { return JsonResponse::fail([], Http::STATUS_NOT_FOUND); } $state = $this->outOfOfficeService->parseState($account->getMailAccount()); return JsonResponse::success($state); } /** * @NoAdminRequired */ #[TrapError] public function followSystem(int $accountId): JsonResponse { if (!$this->container->has(IAvailabilityCoordinator::class)) { return JsonResponse::fail([], Http::STATUS_NOT_IMPLEMENTED); } $user = $this->userSession->getUser(); if ($user === null) { return JsonResponse::fail([], Http::STATUS_FORBIDDEN); } $account = $this->accountService->findById($accountId); if ($account->getUserId() !== $user->getUID()) { return JsonResponse::fail([], Http::STATUS_NOT_FOUND); } $mailAccount = $account->getMailAccount(); if (!$mailAccount->getOutOfOfficeFollowsSystem()) { $mailAccount->setOutOfOfficeFollowsSystem(true); $this->accountService->update($mailAccount); } $state = $this->outOfOfficeService->updateFromSystem($mailAccount, $user); return JsonResponse::success($state); } /** * @NoAdminRequired */ #[TrapError] public function update( int $accountId, bool $enabled, ?string $start, ?string $end, string $subject, string $message, ): JsonResponse { $user = $this->userSession->getUser(); if ($user === null) { return JsonResponse::fail([], Http::STATUS_FORBIDDEN); } $account = $this->accountService->findById($accountId); if ($account->getUserId() !== $user->getUID()) { return JsonResponse::fail([], Http::STATUS_NOT_FOUND); } if ($enabled && $start === null) { throw new ServiceException('Missing start date'); } $mailAccount = $account->getMailAccount(); if ($mailAccount->getOutOfOfficeFollowsSystem()) { $mailAccount->setOutOfOfficeFollowsSystem(false); $this->accountService->update($mailAccount); } $state = new OutOfOfficeState( $enabled, $start ? new DateTimeImmutable($start) : null, $end ? new DateTimeImmutable($end) : null, $subject, $message, ); $this->outOfOfficeService->update($mailAccount, $state); $newState = $this->outOfOfficeService->parseState($mailAccount); return JsonResponse::success($newState); } }