mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
some data in msgraph synchro and answer on calendar invite
This commit is contained in:
@@ -21,7 +21,6 @@ use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* Convert Chill Calendar event to Remote MS Graph event, and MS Graph
|
||||
@@ -35,14 +34,14 @@ class RemoteEventConverter
|
||||
|
||||
private DateTimeZone $defaultDateTimeZone;
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
private PersonRenderInterface $personRender;
|
||||
|
||||
private DateTimeZone $remoteDateTimeZone;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
public function __construct(EngineInterface $engine, PersonRenderInterface $personRender, TranslatorInterface $translator)
|
||||
{
|
||||
$this->engine = $engine;
|
||||
@@ -112,7 +111,7 @@ class RemoteEventConverter
|
||||
'@ChillCalendar/MSGraph/calendar_event_body.html.twig',
|
||||
['calendar' => $calendar]
|
||||
),
|
||||
]
|
||||
],
|
||||
],
|
||||
$this->calendarToEventAttendeesOnly($calendar)
|
||||
);
|
||||
@@ -129,17 +128,6 @@ class RemoteEventConverter
|
||||
];
|
||||
}
|
||||
|
||||
private function buildInviteToAttendee(Invite $invite): array
|
||||
{
|
||||
return [
|
||||
'emailAddress' => [
|
||||
'address' => $invite->getUser()->getEmail(),
|
||||
'name' => $invite->getUser()->getLabel(),
|
||||
],
|
||||
'type' => 'Required',
|
||||
];
|
||||
}
|
||||
|
||||
public function convertAvailabilityToRemoteEvent(array $event): RemoteEvent
|
||||
{
|
||||
$startDate =
|
||||
@@ -193,4 +181,15 @@ class RemoteEventConverter
|
||||
{
|
||||
return new DateTimeZone('UTC');
|
||||
}
|
||||
|
||||
private function buildInviteToAttendee(Invite $invite): array
|
||||
{
|
||||
return [
|
||||
'emailAddress' => [
|
||||
'address' => $invite->getUser()->getEmail(),
|
||||
'name' => $invite->getUser()->getLabel(),
|
||||
],
|
||||
'type' => 'Required',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function count;
|
||||
|
||||
class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
{
|
||||
@@ -41,10 +42,10 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
|
||||
private RemoteEventConverter $remoteEventConverter;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private OnBehalfOfUserTokenStorage $tokenStorage;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private UrlGeneratorInterface $urlGenerator;
|
||||
|
||||
private OnBehalfOfUserHttpClient $userHttpClient;
|
||||
@@ -171,7 +172,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$calendar->getRemoteId(),
|
||||
$this->translator->trans('remote_ms_graph.cancel_event_because_main_user_is_%label%', ['%label%' => $calendar->getMainUser()]),
|
||||
$previousMainUser,
|
||||
'calendar_'.$calendar->getRemoteId()
|
||||
'calendar_' . $calendar->getRemoteId()
|
||||
);
|
||||
$this->createCalendarOnRemote($calendar);
|
||||
} else {
|
||||
@@ -189,10 +190,9 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
->addRemoteAttributes([
|
||||
'lastModifiedDateTime' => null,
|
||||
'changeKey' => null,
|
||||
'previousId' => $calendar->getCalendarRange()->getRemoteId()
|
||||
'previousId' => $calendar->getCalendarRange()->getRemoteId(),
|
||||
])
|
||||
->setRemoteId('')
|
||||
;
|
||||
->setRemoteId('');
|
||||
}
|
||||
|
||||
if (null !== $previousCalendarRange) {
|
||||
@@ -209,31 +209,30 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function patchCalendarOnRemote(Calendar $calendar, array $newInvites): void
|
||||
private function cancelOnRemote(string $remoteId, string $comment, User $user, string $identifier): void
|
||||
{
|
||||
$eventDatas = [];
|
||||
$eventDatas[] = $this->remoteEventConverter->calendarToEvent($calendar);
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
|
||||
if (0 < count($newInvites)) {
|
||||
$eventDatas[] = $this->remoteEventConverter->calendarToEventAttendeesOnly($calendar);
|
||||
if (null === $userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($eventDatas as $eventData) {
|
||||
[
|
||||
'id' => $id,
|
||||
'lastModifiedDateTime' => $lastModified,
|
||||
'changeKey' => $changeKey
|
||||
] = $this->patchOnRemote(
|
||||
$calendar->getRemoteId(),
|
||||
$eventData,
|
||||
$calendar->getMainUser(),
|
||||
'calendar_'.$calendar->getId()
|
||||
try {
|
||||
$this->machineHttpClient->request(
|
||||
'POST',
|
||||
"users/{$userId}/calendar/events/{$remoteId}/cancel",
|
||||
[
|
||||
'json' => ['Comment' => $comment],
|
||||
]
|
||||
);
|
||||
|
||||
$calendar->addRemoteAttributes([
|
||||
'lastModifiedDateTime' => $lastModified,
|
||||
'changeKey' => $changeKey,
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->logger->warning('could not update calendar range to remote', [
|
||||
'exception' => $e->getTraceAsString(),
|
||||
'content' => $e->getResponse()->getContent(),
|
||||
'calendarRangeId' => $identifier,
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +329,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$calendarRange->setRemoteId($id)
|
||||
->addRemoteAttributes([
|
||||
'lastModifiedDateTime' => $lastModified,
|
||||
'changeKey' => $changeKey
|
||||
'changeKey' => $changeKey,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -404,33 +403,32 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
);
|
||||
}
|
||||
|
||||
private function cancelOnRemote(string $remoteId, string $comment, User $user, string $identifier): void
|
||||
private function patchCalendarOnRemote(Calendar $calendar, array $newInvites): void
|
||||
{
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
$eventDatas = [];
|
||||
$eventDatas[] = $this->remoteEventConverter->calendarToEvent($calendar);
|
||||
|
||||
if (null === $userId) {
|
||||
return;
|
||||
if (0 < count($newInvites)) {
|
||||
$eventDatas[] = $this->remoteEventConverter->calendarToEventAttendeesOnly($calendar);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->machineHttpClient->request(
|
||||
'POST',
|
||||
"users/{$userId}/calendar/events/{$remoteId}/cancel",
|
||||
[
|
||||
'json' => ['Comment' => $comment]
|
||||
]
|
||||
foreach ($eventDatas as $eventData) {
|
||||
[
|
||||
'id' => $id,
|
||||
'lastModifiedDateTime' => $lastModified,
|
||||
'changeKey' => $changeKey
|
||||
] = $this->patchOnRemote(
|
||||
$calendar->getRemoteId(),
|
||||
$eventData,
|
||||
$calendar->getMainUser(),
|
||||
'calendar_' . $calendar->getId()
|
||||
);
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->logger->warning('could not update calendar range to remote', [
|
||||
'exception' => $e->getTraceAsString(),
|
||||
'content' => $e->getResponse()->getContent(),
|
||||
'calendarRangeId' => $identifier,
|
||||
|
||||
$calendar->addRemoteAttributes([
|
||||
'lastModifiedDateTime' => $lastModified,
|
||||
'changeKey' => $changeKey,
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user