Merge remote-tracking branch 'origin/master' into 709-notification-eval-action

This commit is contained in:
Lucas Silva 2023-03-23 13:34:59 +01:00
commit f4a7145627

View File

@ -34,6 +34,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -64,6 +65,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
private OnBehalfOfUserHttpClient $userHttpClient; private OnBehalfOfUserHttpClient $userHttpClient;
private Security $security;
public function __construct( public function __construct(
CalendarRepository $calendarRepository, CalendarRepository $calendarRepository,
CalendarRangeRepository $calendarRangeRepository, CalendarRangeRepository $calendarRangeRepository,
@ -74,7 +77,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
OnBehalfOfUserHttpClient $userHttpClient, OnBehalfOfUserHttpClient $userHttpClient,
RemoteEventConverter $remoteEventConverter, RemoteEventConverter $remoteEventConverter,
TranslatorInterface $translator, TranslatorInterface $translator,
UrlGeneratorInterface $urlGenerator UrlGeneratorInterface $urlGenerator,
Security $security
) { ) {
$this->calendarRepository = $calendarRepository; $this->calendarRepository = $calendarRepository;
$this->calendarRangeRepository = $calendarRangeRepository; $this->calendarRangeRepository = $calendarRangeRepository;
@ -86,6 +90,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
$this->translator = $translator; $this->translator = $translator;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->userHttpClient = $userHttpClient; $this->userHttpClient = $userHttpClient;
$this->security = $security;
} }
public function countEventsForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate): int public function countEventsForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate): int
@ -133,6 +138,24 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
public function isReady(): bool public function isReady(): bool
{ {
$user = $this->security->getUser();
if (!$user instanceof User) {
// this is not a user from chill. This is not the role of this class to
// restrict access, so we will just say that we do not have to do anything more
// here...
return true;
}
if (null === $this->mapCalendarToUser->getUserId($user)) {
// this user is not mapped with remote calendar. The user will have to wait for
// the next calendar subscription iteration
$this->logger->debug('mark user ready for msgraph calendar as he does not have any mapping', [
'userId' => $user->getId(),
]);
return true;
}
return $this->tokenStorage->hasToken(); return $this->tokenStorage->hasToken();
} }