Feature: [calendar sync msgraph] Allow to show the calendar details if the user does not have msgraph mapping

We first check that there are "msgraph" attributes before forcing redirection to MSGraph authorization. If not, we let's the user see the calendar edit/create page.
This commit is contained in:
Julien Fastré 2023-03-23 12:48:37 +01:00
parent 4eb7d10e45
commit 96ddc73e45
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

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();
} }