mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-29 15:14:34 +00:00
Compare commits
5 Commits
dutch-tran
...
472-zimbra
| Author | SHA1 | Date | |
|---|---|---|---|
|
4158e14ef9
|
|||
|
9c154eeae0
|
|||
|
3c110b2f1b
|
|||
|
b2a6a2170a
|
|||
|
09d81d8025
|
@@ -14,6 +14,7 @@ $finder = PhpCsFixer\Finder::create();
|
||||
$finder
|
||||
->in(__DIR__.'/src')
|
||||
->in(__DIR__.'/utils')
|
||||
->in(__DIR__.'/packages')
|
||||
->append([__FILE__])
|
||||
->exclude(['docs/', 'tests/app'])
|
||||
->notPath('tests/app')
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
"chill",
|
||||
"social worker"
|
||||
],
|
||||
"repositories": [{
|
||||
"type": "path",
|
||||
"url": "./packages/ChillZimbraBundle",
|
||||
"options": {
|
||||
"symlink": true
|
||||
}
|
||||
}],
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"ext-dom": "*",
|
||||
@@ -14,6 +21,7 @@
|
||||
"ext-openssl": "*",
|
||||
"ext-redis": "*",
|
||||
"ext-zlib": "*",
|
||||
"chill-project/chill-zimbra-bundle": "@dev",
|
||||
"champs-libres/wopi-bundle": "dev-symfony-v5@dev",
|
||||
"champs-libres/wopi-lib": "dev-master@dev",
|
||||
"doctrine/data-fixtures": "^1.8",
|
||||
|
||||
@@ -37,4 +37,5 @@ return [
|
||||
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
|
||||
Symfony\UX\Translator\UxTranslatorBundle::class => ['all' => true],
|
||||
loophp\PsrHttpMessageBridgeBundle\PsrHttpMessageBridgeBundle::class => ['all' => true],
|
||||
Chill\ZimbraBundle\ChillZimbraBundle::class => ['all' => true],
|
||||
];
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"@hotwired/stimulus": "^3.0.0",
|
||||
"@luminateone/eslint-baseline": "^1.0.9",
|
||||
"@symfony/stimulus-bridge": "^3.2.0",
|
||||
"@symfony/ux-translator": "file:vendor/symfony/ux-translator/assets",
|
||||
"@symfony/webpack-encore": "^4.1.0",
|
||||
"@tsconfig/node20": "^20.1.4",
|
||||
"@types/dompurify": "^3.0.5",
|
||||
|
||||
22
packages/ChillZimbraBundle/composer.json
Normal file
22
packages/ChillZimbraBundle/composer.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "chill-project/chill-zimbra-bundle",
|
||||
"description": "Provide connection between Zimbra agenda and Chill",
|
||||
"minimum-stability": "stable",
|
||||
"license": "AGPL-3.0",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"chill",
|
||||
"social worker"
|
||||
],
|
||||
"require": {
|
||||
"chill-project/chill-bundles": "dev-master@dev",
|
||||
"zimbra-api/soap-api": "^3.2.2",
|
||||
"psr/http-client": "^1.0",
|
||||
"nyholm/psr7": "^1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Chill\\ZimbraBundle\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Calendar\Connector;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\CalendarBundle\Entity\Invite;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector\CreateEvent;
|
||||
use Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector\UpdateEvent;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final readonly class ZimbraConnector implements RemoteCalendarConnectorInterface
|
||||
{
|
||||
private const LOG_PREFIX = '[ZimbraConnector] ';
|
||||
|
||||
public function __construct(
|
||||
private CreateEvent $createEvent,
|
||||
private UpdateEvent $updateEvent,
|
||||
private LoggerInterface $logger,
|
||||
) {}
|
||||
|
||||
public function countEventsForUser(User $user, \DateTimeImmutable $startDate, \DateTimeImmutable $endDate): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getMakeReadyResponse(string $returnPath): Response
|
||||
{
|
||||
throw new \BadMethodCallException('Zimbra connector is always ready');
|
||||
}
|
||||
|
||||
public function isReady(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function listEventsForUser(User $user, \DateTimeImmutable $startDate, \DateTimeImmutable $endDate, ?int $offset = 0, ?int $limit = 50): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function removeCalendar(string $remoteId, array $remoteAttributes, User $user, ?CalendarRange $associatedCalendarRange = null): void
|
||||
{
|
||||
// TODO: Implement removeCalendar() method.
|
||||
}
|
||||
|
||||
public function removeCalendarRange(string $remoteId, array $remoteAttributes, User $user): void
|
||||
{
|
||||
// TODO: Implement removeCalendarRange() method.
|
||||
}
|
||||
|
||||
public function syncCalendar(Calendar $calendar, string $action, ?CalendarRange $previousCalendarRange, ?User $previousMainUser, ?array $oldInvites, ?array $newInvites): void
|
||||
{
|
||||
if (!$calendar->hasRemoteId()) {
|
||||
$calItemId = ($this->createEvent)($calendar);
|
||||
$this->logger->info(self::LOG_PREFIX.'Calendar synced with Zimbra', ['calendar_id' => $calendar->getId(), 'action' => $action, 'calItemId' => $calItemId]);
|
||||
|
||||
$calendar->setRemoteId($calItemId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Update of calendar: to be implemented');
|
||||
}
|
||||
|
||||
public function syncCalendarRange(CalendarRange $calendarRange): void
|
||||
{
|
||||
if (!$calendarRange->hasRemoteId()) {
|
||||
$calItemId = ($this->createEvent)($calendarRange);
|
||||
$this->logger->info(self::LOG_PREFIX.'Calendar range created with Zimbra', ['calendar_range_id' => $calendarRange->getId(), 'calItemId' => $calItemId]);
|
||||
|
||||
$calendarRange->setRemoteId($calItemId);
|
||||
} else {
|
||||
($this->updateEvent)($calendarRange);
|
||||
$this->logger->info(self::LOG_PREFIX.'Calendar range updated against zimbra', ['old_cal_remote_id' => $calendarRange->getRemoteId(), 'calendar_range_id' => $calendarRange->getId()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function syncInvite(Invite $invite): void
|
||||
{
|
||||
// TODO: Implement syncInvite() method.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\ZimbraBundle\Exception\CalendarWithoutMainUserException;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Zimbra\Mail\Struct\InvitationInfo;
|
||||
use Zimbra\Mail\Struct\InviteComponent;
|
||||
use Zimbra\Mail\Struct\MimePartInfo;
|
||||
use Zimbra\Mail\Struct\Msg;
|
||||
|
||||
/**
|
||||
* Creates a new calendar event in Zimbra.
|
||||
*
|
||||
* This class handles the creation of new calendar events in the Zimbra system.
|
||||
* It uses the Zimbra SOAP API to create events and returns a serialized ID that
|
||||
* can be used as remoteId for Calendar and CalendarRange.
|
||||
*/
|
||||
final readonly class CreateEvent
|
||||
{
|
||||
public function __construct(
|
||||
private SoapClientBuilder $soapClientBuilder,
|
||||
private CreateZimbraComponent $createEvent,
|
||||
private TranslatorInterface $translator,
|
||||
private ZimbraIdSerializer $zimbraIdSerializer,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Creates a new calendar event in Zimbra.
|
||||
*
|
||||
* @param Calendar|CalendarRange $calendar The calendar event to create
|
||||
*
|
||||
* @return string The serialized Zimbra ID for the created event
|
||||
*
|
||||
* @throws CalendarWithoutMainUserException When the calendar has no associated user email
|
||||
*/
|
||||
public function __invoke(Calendar|CalendarRange $calendar): string
|
||||
{
|
||||
if ($calendar instanceof Calendar) {
|
||||
$organizerEmail = $calendar->getMainUser()->getEmail();
|
||||
$organizerLang = $calendar->getMainUser()->getLocale();
|
||||
} else {
|
||||
$organizerEmail = $calendar->getUser()->getEmail();
|
||||
$organizerLang = $calendar->getUser()->getLocale();
|
||||
}
|
||||
|
||||
if (null === $organizerEmail) {
|
||||
throw new CalendarWithoutMainUserException();
|
||||
}
|
||||
|
||||
$api = $this->soapClientBuilder->getApiForAccount($organizerEmail);
|
||||
|
||||
$comp = $this->createEvent->createZimbraInviteComponentFromCalendar($calendar);
|
||||
|
||||
$inv = new InvitationInfo();
|
||||
$inv->setInviteComponent($comp);
|
||||
|
||||
$mp = new MimePartInfo();
|
||||
$mp->addMimePart(new MimePartInfo('text/plain', $this->translator->trans('zimbra.event_created_by_chill', locale: $organizerLang)));
|
||||
|
||||
$msg = new Msg();
|
||||
$msg->setSubject($this->translator->trans('zimbra.event_created_trough_soap', locale: $organizerLang))
|
||||
->setFolderId('10')
|
||||
->setInvite($inv)
|
||||
->setMimePart($mp);
|
||||
|
||||
$response = $api->createAppointment($msg, echo: true);
|
||||
|
||||
$echo = $response->getEcho();
|
||||
$invite = $echo->getInvite();
|
||||
$MPInviteInfo = $invite->getInvite();
|
||||
/** @var InviteComponent $firstInvite */
|
||||
$firstInvite = $MPInviteInfo->getInviteComponents()[0];
|
||||
|
||||
$id = $this->zimbraIdSerializer->serializeId(
|
||||
$response->getCalItemId(),
|
||||
$response->getCalInvId(),
|
||||
$firstInvite->getUid(),
|
||||
);
|
||||
|
||||
var_dump($response);
|
||||
var_dump($id);
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Templating\Entity\AddressRender;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Zimbra\Common\Enum\FreeBusyStatus;
|
||||
use Zimbra\Common\Enum\InviteClass;
|
||||
use Zimbra\Common\Enum\InviteStatus;
|
||||
use Zimbra\Common\Enum\Transparency;
|
||||
use Zimbra\Mail\Struct\InviteComponent;
|
||||
|
||||
/**
|
||||
* Class responsible for creating Zimbra invite components based on calendar data.
|
||||
*/
|
||||
final readonly class CreateZimbraComponent
|
||||
{
|
||||
public function __construct(
|
||||
private PersonRenderInterface $personRender,
|
||||
private AddressRender $addressRender,
|
||||
private DateConverter $dateConverter,
|
||||
private TranslatorInterface $translator,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Creates a Zimbra invite component from the provided calendar object.
|
||||
*
|
||||
* The method initializes a new InviteComponent object, sets its properties
|
||||
* including name, free/busy status, status, classification, transparency,
|
||||
* all-day and draft status, as well as start and end times. If the calendar
|
||||
* contains a location, it also sets the location for the invite component.
|
||||
*
|
||||
* @param Calendar|CalendarRange $calendar a calendar object containing event data
|
||||
*
|
||||
* @return InviteComponent the configured Zimbra invite component
|
||||
*/
|
||||
public function createZimbraInviteComponentFromCalendar(Calendar|CalendarRange $calendar): InviteComponent
|
||||
{
|
||||
if ($calendar instanceof Calendar) {
|
||||
$subject = '[Chill] '.
|
||||
implode(
|
||||
', ',
|
||||
$calendar->getPersons()->map(fn (Person $p) => $this->personRender->renderString($p, []))->toArray()
|
||||
);
|
||||
|
||||
} else {
|
||||
$subject = $this->translator->trans('remote_calendar.calendar_range_title');
|
||||
}
|
||||
|
||||
$comp = new InviteComponent();
|
||||
$comp->setName($subject)
|
||||
->setFreeBusy(FreeBusyStatus::BUSY)
|
||||
->setStatus(InviteStatus::CONFIRMED)
|
||||
->setCalClass(InviteClass::PUB)
|
||||
->setTransparency(Transparency::OPAQUE)
|
||||
->setIsAllDay(false)
|
||||
->setIsDraft(false)
|
||||
->setDtStart($this->dateConverter->phpToZimbraDateTime($calendar->getStartDate()))
|
||||
->setDtEnd($this->dateConverter->phpToZimbraDateTime($calendar->getEndDate()));
|
||||
|
||||
if ($calendar->hasLocation()) {
|
||||
$comp
|
||||
->setLocation($this->createLocationString($calendar->getLocation()));
|
||||
}
|
||||
|
||||
return $comp;
|
||||
}
|
||||
|
||||
private function createLocationString(Location $location): string
|
||||
{
|
||||
$str = '';
|
||||
|
||||
if ('' !== ((string) $location->getName())) {
|
||||
$str .= $location->getName();
|
||||
$str .= ', ';
|
||||
}
|
||||
|
||||
if ($location->hasAddress()) {
|
||||
if ('' !== $str) {
|
||||
$str .= ', ';
|
||||
}
|
||||
|
||||
$str .= $this->addressRender->renderString($location->getAddress(), []);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector;
|
||||
|
||||
use Zimbra\Mail\Struct\DtTimeInfo;
|
||||
|
||||
/**
|
||||
* Class DateConverter.
|
||||
*
|
||||
* Provides methods for converting PHP DateTime objects
|
||||
* into specific date-time formats or representations.
|
||||
*/
|
||||
final readonly class DateConverter
|
||||
{
|
||||
public const FORMAT_DATE_TIME = 'Ymd\THis';
|
||||
|
||||
/**
|
||||
* Converts a PHP DateTimeInterface object into a Zimbra-specific DtTimeInfo object.
|
||||
*
|
||||
* @param \DateTimeInterface $date the date to be converted
|
||||
*
|
||||
* @return DtTimeInfo the converted DtTimeInfo object
|
||||
*/
|
||||
public function phpToZimbraDateTime(\DateTimeInterface $date): DtTimeInfo
|
||||
{
|
||||
return new DtTimeInfo($date->format(self::FORMAT_DATE_TIME), $date->getTimezone()->getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\HttpClient\Psr18Client;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Zimbra\Common\Enum\AccountBy;
|
||||
use Zimbra\Common\Soap\ClientFactory;
|
||||
use Zimbra\Common\Struct\Header\AccountInfo;
|
||||
use Zimbra\Mail\MailApi;
|
||||
|
||||
final readonly class SoapClientBuilder
|
||||
{
|
||||
private string $username;
|
||||
|
||||
private string $password;
|
||||
|
||||
private string $url;
|
||||
|
||||
public function __construct(private ParameterBagInterface $parameterBag, private HttpClientInterface $client)
|
||||
{
|
||||
$dsn = $this->parameterBag->get('chill_calendar.remote_calendar_dsn');
|
||||
$url = parse_url($dsn);
|
||||
|
||||
$this->username = urldecode($url['user']);
|
||||
$this->password = urldecode($url['pass']);
|
||||
if ('zimbra+http' === $url['scheme']) {
|
||||
$scheme = 'http://';
|
||||
$port = $url['port'] ?? 80;
|
||||
} elseif ('zimbra+https' === $url['scheme']) {
|
||||
$scheme = 'https://';
|
||||
$port = $url['port'] ?? 443;
|
||||
} else {
|
||||
throw new \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Unsupported remote calendar scheme: '.$url['scheme']);
|
||||
}
|
||||
|
||||
$this->url = $scheme.$url['host'].':'.$port;
|
||||
}
|
||||
|
||||
private function buildApi(): MailApi
|
||||
{
|
||||
$baseClient = $this->client->withOptions([
|
||||
'base_uri' => $location = $this->url.'/service/soap',
|
||||
'verify_host' => false,
|
||||
'verify_peer' => false,
|
||||
]);
|
||||
$psr18Client = new Psr18Client($baseClient);
|
||||
$api = new MailApi();
|
||||
$client = ClientFactory::create($location, $psr18Client);
|
||||
$api->setClient($client);
|
||||
|
||||
return $api;
|
||||
}
|
||||
|
||||
public function getApiForAccount(string $accountName): MailApi
|
||||
{
|
||||
$api = $this->buildApi();
|
||||
$response = $api->authByAccountName($this->username, $this->password);
|
||||
|
||||
$token = $response->getAuthToken();
|
||||
|
||||
$apiBy = $this->buildApi();
|
||||
$apiBy->setAuthToken($token);
|
||||
$apiBy->setTargetAccount(new AccountInfo(AccountBy::NAME, $accountName));
|
||||
|
||||
return $apiBy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\ZimbraBundle\Exception\CalendarWithoutMainUserException;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Zimbra\Mail\Struct\InvitationInfo;
|
||||
use Zimbra\Mail\Struct\MimePartInfo;
|
||||
use Zimbra\Mail\Struct\Msg;
|
||||
|
||||
/**
|
||||
* Updates an existing calendar event in Zimbra.
|
||||
*
|
||||
* This class handles the modification of existing calendar events in the Zimbra system.
|
||||
* It uses the Zimbra SOAP API to update event details while maintaining the original
|
||||
* event's metadata like IDs and sequences.
|
||||
*/
|
||||
final readonly class UpdateEvent
|
||||
{
|
||||
public function __construct(
|
||||
private SoapClientBuilder $soapClientBuilder,
|
||||
private CreateZimbraComponent $createZimbraComponent,
|
||||
private TranslatorInterface $translator,
|
||||
private ZimbraIdSerializer $zimbraIdSerializer,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Updates an existing calendar event in Zimbra.
|
||||
*
|
||||
* @param Calendar|CalendarRange $calendar The calendar event to update
|
||||
*
|
||||
* @throws CalendarWithoutMainUserException When the calendar has no associated user email
|
||||
*/
|
||||
public function __invoke(Calendar|CalendarRange $calendar): void
|
||||
{
|
||||
if ($calendar instanceof Calendar) {
|
||||
$organizerEmail = $calendar->getMainUser()->getEmail();
|
||||
$organizerLang = $calendar->getMainUser()->getLocale();
|
||||
} else {
|
||||
$organizerEmail = $calendar->getUser()->getEmail();
|
||||
$organizerLang = $calendar->getUser()->getLocale();
|
||||
}
|
||||
|
||||
if (null === $organizerEmail) {
|
||||
throw new CalendarWithoutMainUserException();
|
||||
}
|
||||
|
||||
$api = $this->soapClientBuilder->getApiForAccount($organizerEmail);
|
||||
|
||||
['calItemId' => $calItemId, 'calInvId' => $calInvId, 'inviteComponentCommonUid' => $inviteComponentCommonUid]
|
||||
= $this->zimbraIdSerializer->deSerializeId($calendar->getRemoteId());
|
||||
|
||||
$existing = $api->getAppointment(sync: true, includeContent: true, includeInvites: true, id: $calItemId);
|
||||
$appt = $existing->getApptItem();
|
||||
|
||||
$comp = $this->createZimbraComponent->createZimbraInviteComponentFromCalendar($calendar);
|
||||
$comp->setUid($inviteComponentCommonUid);
|
||||
|
||||
$inv = new InvitationInfo();
|
||||
$inv->setInviteComponent($comp)
|
||||
->setUid($calInvId);
|
||||
|
||||
$mp = new MimePartInfo();
|
||||
$mp->addMimePart(new MimePartInfo('text/plain', $this->translator->trans('zimbra.event_created_by_chill', locale: $organizerLang)));
|
||||
|
||||
$msg = new Msg();
|
||||
$msg->setSubject($this->translator->trans('zimbra.event_created_trough_soap', locale: $organizerLang))
|
||||
->setFolderId('10')
|
||||
->setInvite($inv)
|
||||
->setMimePart($mp)
|
||||
;
|
||||
|
||||
$response = $api->modifyAppointment(
|
||||
id: $calInvId,
|
||||
componentNum: 0,
|
||||
modifiedSequence: $appt->getModifiedSequence(),
|
||||
revision: $appt->getRevision(),
|
||||
msg: $msg,
|
||||
echo: true
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector;
|
||||
|
||||
use Chill\ZimbraBundle\Exception\ZimbraCalendarIdNotDeserializedException;
|
||||
|
||||
/**
|
||||
* Serializes and deserializes Zimbra calendar event IDs.
|
||||
*
|
||||
* This class handles the conversion between Zimbra's individual ID components
|
||||
* and a single serialized string format, allowing for consistent storage and retrieval
|
||||
* of Zimbra calendar event identifiers.
|
||||
*/
|
||||
final readonly class ZimbraIdSerializer
|
||||
{
|
||||
/**
|
||||
* Serializes individual Zimbra calendar ID components into a single string.
|
||||
*
|
||||
* @param string $calItemId The calendar item ID from Zimbra
|
||||
* @param string $calInvId The calendar invitation ID from Zimbra
|
||||
* @param string $inviteComponentCommonUid The common UID for the invite component
|
||||
*
|
||||
* @return string The serialized ID in format "calItemId|calInvId|inviteComponentCommonUid|v0"
|
||||
*/
|
||||
public function serializeId(string $calItemId, string $calInvId, string $inviteComponentCommonUid): string
|
||||
{
|
||||
return sprintf(
|
||||
'%s|%s|%s|v0',
|
||||
$calItemId,
|
||||
$calInvId,
|
||||
$inviteComponentCommonUid,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a Zimbra calendar ID string into its component parts.
|
||||
*
|
||||
* @param string $remoteId The serialized ID, as stored in the remoteId's Calendar or CalendarRange
|
||||
*
|
||||
* @return array{calItemId: string, calInvId: string, inviteComponentCommonUid: string} Associative array containing the ID components
|
||||
*
|
||||
* @throws ZimbraCalendarIdNotDeserializedException If the remote ID format is invalid or incompatible
|
||||
*/
|
||||
public function deSerializeId(string $remoteId): array
|
||||
{
|
||||
if (!str_ends_with($remoteId, 'v0')) {
|
||||
throw new ZimbraCalendarIdNotDeserializedException();
|
||||
}
|
||||
|
||||
$exploded = explode('|', $remoteId);
|
||||
|
||||
return [
|
||||
'calItemId' => $exploded[0],
|
||||
'calInvId' => $exploded[1],
|
||||
'inviteComponentCommonUid' => $exploded[2],
|
||||
];
|
||||
}
|
||||
}
|
||||
16
packages/ChillZimbraBundle/src/ChillZimbraBundle.php
Normal file
16
packages/ChillZimbraBundle/src/ChillZimbraBundle.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class ChillZimbraBundle extends Bundle {}
|
||||
178
packages/ChillZimbraBundle/src/Command/TestCommand.php
Normal file
178
packages/ChillZimbraBundle/src/Command/TestCommand.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpClient\Psr18Client;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Zimbra\Common\Enum\AccountBy;
|
||||
use Zimbra\Common\Enum\FreeBusyStatus;
|
||||
use Zimbra\Common\Enum\InviteClass;
|
||||
use Zimbra\Common\Enum\InviteStatus;
|
||||
use Zimbra\Common\Enum\ItemType;
|
||||
use Zimbra\Common\Enum\Transparency;
|
||||
use Zimbra\Common\Soap\ClientFactory;
|
||||
use Zimbra\Common\Struct\Header\AccountInfo;
|
||||
use Zimbra\Mail\MailApi;
|
||||
use Zimbra\Mail\Struct\DtTimeInfo;
|
||||
use Zimbra\Mail\Struct\Folder;
|
||||
use Zimbra\Mail\Struct\GetFolderSpec;
|
||||
use Zimbra\Mail\Struct\InvitationInfo;
|
||||
use Zimbra\Mail\Struct\InviteComponent;
|
||||
use Zimbra\Mail\Struct\MimePartInfo;
|
||||
use Zimbra\Mail\Struct\Msg;
|
||||
|
||||
class TestCommand extends Command
|
||||
{
|
||||
public function __construct(private HttpClientInterface $client)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'chill:zimbra:test';
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$this->getAppointments($this->createApiForJulien());
|
||||
// $this->createAppointment($this->createApiForJulien());
|
||||
|
||||
// $api = $this->createApiForJulienDelegated();
|
||||
// $this->createAppointment($api);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
public function createApiForJulienDelegated(): MailApi
|
||||
{
|
||||
$baseClient = $this->client->withOptions([
|
||||
'base_uri' => $location = 'https://zimbra.cldev.ours/service/soap',
|
||||
'verify_host' => false,
|
||||
'verify_peer' => false,
|
||||
]);
|
||||
$psr18Client = new Psr18Client($baseClient);
|
||||
$api = new MailApi();
|
||||
$client = ClientFactory::create($location, $psr18Client);
|
||||
$api->setClient($client);
|
||||
$response = $api->authByAccountName('chill@zimbra.cldev.ours', 'password');
|
||||
|
||||
$token = $response->getAuthToken();
|
||||
|
||||
var_dump($token);
|
||||
|
||||
$apiBy = new MailApi();
|
||||
$apiBy->setClient($client);
|
||||
$apiBy->setAuthToken($token);
|
||||
$apiBy->setTargetAccount(new AccountInfo(AccountBy::NAME, 'julien@zimbra.cldev.ours'));
|
||||
|
||||
return $apiBy;
|
||||
}
|
||||
|
||||
private function createApiForJulien(): MailApi
|
||||
{
|
||||
$baseClient = $this->client->withOptions([
|
||||
'base_uri' => $location = 'https://zimbra.cldev.ours/service/soap',
|
||||
'verify_host' => false,
|
||||
'verify_peer' => false,
|
||||
]);
|
||||
$psr18Client = new Psr18Client($baseClient);
|
||||
$api = new MailApi();
|
||||
$client = ClientFactory::create($location, $psr18Client);
|
||||
$api->setClient($client);
|
||||
$api->authByAccountName('julien@zimbra.cldev.ours', 'Password;1234');
|
||||
|
||||
return $api;
|
||||
}
|
||||
|
||||
private function updateAppointment(MailApi $api): void
|
||||
{
|
||||
$appointment = $api->getAppointment(id: '69ec3b5e-9f83-4467-a151-a99bc64cfb38:376');
|
||||
|
||||
}
|
||||
|
||||
private function createAppointment(MailApi $api): void
|
||||
{
|
||||
$date = new \DateTimeImmutable('2025-12-03T18:00:00Z');
|
||||
$comp = new InviteComponent();
|
||||
$comp->setName('Test Appointment by chill')
|
||||
->setLocation('Test Location')
|
||||
->setFreeBusy(FreeBusyStatus::BUSY)
|
||||
->setStatus(InviteStatus::CONFIRMED)
|
||||
->setCalClass(InviteClass::PUB)
|
||||
->setTransparency(Transparency::OPAQUE)
|
||||
->setIsAllDay(false)
|
||||
->setIsDraft(false)
|
||||
->setDtStart(new DtTimeInfo($date->format('Ymd\THis'), 'Europe/Brussels'))
|
||||
->setDtEnd(new DtTimeInfo($date->add(new \DateInterval('PT1H'))->format('Ymd\THis'), 'Europe/Brussels'));
|
||||
|
||||
$inv = new InvitationInfo();
|
||||
$inv->setInviteComponent($comp);
|
||||
|
||||
$mp = new MimePartInfo();
|
||||
$mp->addMimePart(new MimePartInfo('text/plain', 'Appointment create via soap'));
|
||||
|
||||
$msg = new Msg();
|
||||
$msg->setSubject('Réunion créée via soap')
|
||||
->setFolderId('10')
|
||||
->setInvite($inv)
|
||||
->setMimePart($mp);
|
||||
|
||||
$response = $api->createAppointment($msg, echo: true);
|
||||
var_dump($response->getEcho());
|
||||
}
|
||||
|
||||
private function getAppointments(MailApi $api): void
|
||||
{
|
||||
|
||||
// $folders = $api->getFolder(new GetFolderSpec(folderId: 10));
|
||||
$foldersResponse = $api->getFolder(viewConstraint: ItemType::APPOINTMENT->value);
|
||||
$calendarFolders = [];
|
||||
|
||||
foreach ($foldersResponse->getFolder()->getSubfolders() as $folder) {
|
||||
if ($folder instanceof Folder) {
|
||||
var_dump($folder->getView()?->value);
|
||||
if ($folder->getView()?->value === ItemType::APPOINTMENT->value) {
|
||||
var_dump('found a calendar');
|
||||
$calendarFolders[] = $folder;
|
||||
}
|
||||
} else {
|
||||
var_dump('not a calendar:'.$folder->getView());
|
||||
}
|
||||
}
|
||||
|
||||
$since = new \DateTimeImmutable('2025-11-28');
|
||||
$until = new \DateTimeImmutable('2025-11-29');
|
||||
|
||||
$allAppointments = [];
|
||||
|
||||
foreach ($calendarFolders as $calendarFolder) {
|
||||
$appointmentIdsInRange = $api
|
||||
->getAppointmentIdsInRange($since->getTimestamp() * 1000, $until->getTimestamp() * 1000, $calendarFolder->getId())
|
||||
->getAppointmentData()
|
||||
;
|
||||
$allAppointments = [...$allAppointments, ...$appointmentIdsInRange];
|
||||
}
|
||||
|
||||
var_dump($allAppointments);
|
||||
|
||||
foreach ($allAppointments as $appointment) {
|
||||
var_dump($appointment->getId());
|
||||
$fetched = $api->getAppointment(id: $appointment->getId());
|
||||
var_dump($fetched);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
|
||||
class ChillZimbraExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
||||
$loader->load('services.yaml');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Exception;
|
||||
|
||||
class CalendarWithoutMainUserException extends \RuntimeException {}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ZimbraBundle\Exception;
|
||||
|
||||
class ZimbraCalendarIdNotDeserializedException extends \RuntimeException {}
|
||||
11
packages/ChillZimbraBundle/src/config/services.yaml
Normal file
11
packages/ChillZimbraBundle/src/config/services.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
services:
|
||||
_defaults:
|
||||
autoconfigure: true
|
||||
autowire: true
|
||||
|
||||
Chill\ZimbraBundle\Command\:
|
||||
resource: '../Command'
|
||||
tags: ['console.command']
|
||||
|
||||
Chill\ZimbraBundle\Calendar\:
|
||||
resource: '../Calendar'
|
||||
@@ -0,0 +1,3 @@
|
||||
zimbra:
|
||||
event_created_by_chill: Événement créé par Chill
|
||||
event_created_trough_soap: Événement créé via l'API SOAP
|
||||
@@ -3,6 +3,7 @@ parameters:
|
||||
paths:
|
||||
- src/
|
||||
- utils/
|
||||
- packages/
|
||||
tmpDir: var/cache/phpstan
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
excludePaths:
|
||||
|
||||
@@ -47,6 +47,8 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
|
||||
} else {
|
||||
$container->setParameter('chill_calendar.short_messages', null);
|
||||
}
|
||||
|
||||
$container->setParameter('chill_calendar.remote_calendar_dsn', $config['remote_calendar_dsn']);
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
|
||||
@@ -32,9 +32,10 @@ class Configuration implements ConfigurationInterface
|
||||
->canBeDisabled()
|
||||
->children()->end()
|
||||
->end() // end for short_messages
|
||||
->scalarNode('remote_calendar_dsn')->defaultValue('null://null')->cannotBeEmpty()->end()
|
||||
->arrayNode('remote_calendars_sync')->canBeEnabled()
|
||||
->children()
|
||||
->arrayNode('microsoft_graph')->canBeEnabled()
|
||||
->arrayNode('microsoft_graph')->canBeEnabled()->setDeprecated('chill-project/chill-bundles', '4.7.0', 'The child node %node% at path %path% is deprecated: use remote_calendar_dsn instead, with a "msgraph://default" value')
|
||||
->children()
|
||||
->end() // end of machine_access_token
|
||||
->end() // end of microsoft_graph children
|
||||
|
||||
@@ -107,6 +107,11 @@ class CalendarRange implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasLocation(): bool
|
||||
{
|
||||
return null !== $this->location;
|
||||
}
|
||||
|
||||
public function setLocation(?Location $location): self
|
||||
{
|
||||
$this->location = $location;
|
||||
|
||||
@@ -35,25 +35,46 @@ use TheNetworg\OAuth2\Client\Provider\Azure;
|
||||
|
||||
class RemoteCalendarCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
private const ZIMBRA_CONNECTOR = 'Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector';
|
||||
|
||||
private const MS_GRAPH_SERVICES_TO_REMOVE = [
|
||||
MapAndSubscribeUserCalendarCommand::class,
|
||||
AzureGrantAdminConsentAndAcquireToken::class,
|
||||
RemoteCalendarConnectAzureController::class,
|
||||
MachineTokenStorage::class,
|
||||
MachineHttpClient::class,
|
||||
MSGraphRemoteCalendarConnector::class,
|
||||
MSUserAbsenceReaderInterface::class,
|
||||
MSUserAbsenceSync::class,
|
||||
];
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$config = $container->getParameter('chill_calendar');
|
||||
$config = $container->getParameter('chill_calendar.remote_calendar_dsn');
|
||||
if (true === $container->getParameter('chill_calendar')['remote_calendars_sync']['microsoft_graph']['enabled']) {
|
||||
$dsn = 'msgraph://default';
|
||||
} else {
|
||||
$dsn = $config;
|
||||
}
|
||||
|
||||
if (true === $config['remote_calendars_sync']['microsoft_graph']['enabled']) {
|
||||
$scheme = parse_url($dsn, PHP_URL_SCHEME);
|
||||
|
||||
if ('msgraph' === $scheme) {
|
||||
$connector = MSGraphRemoteCalendarConnector::class;
|
||||
|
||||
$container->setAlias(HttpClientInterface::class.' $machineHttpClient', MachineHttpClient::class);
|
||||
} else {
|
||||
} elseif ('zimbra+http' === $scheme || 'zimbra+https' === $scheme) {
|
||||
$connector = self::ZIMBRA_CONNECTOR;
|
||||
foreach (self::MS_GRAPH_SERVICES_TO_REMOVE as $serviceId) {
|
||||
$container->removeDefinition($serviceId);
|
||||
}
|
||||
} elseif ('null' === $scheme) {
|
||||
$connector = NullRemoteCalendarConnector::class;
|
||||
// remove services which cannot be loaded
|
||||
$container->removeDefinition(MapAndSubscribeUserCalendarCommand::class);
|
||||
$container->removeDefinition(AzureGrantAdminConsentAndAcquireToken::class);
|
||||
$container->removeDefinition(RemoteCalendarConnectAzureController::class);
|
||||
$container->removeDefinition(MachineTokenStorage::class);
|
||||
$container->removeDefinition(MachineHttpClient::class);
|
||||
$container->removeDefinition(MSGraphRemoteCalendarConnector::class);
|
||||
$container->removeDefinition(MSUserAbsenceReaderInterface::class);
|
||||
$container->removeDefinition(MSUserAbsenceSync::class);
|
||||
foreach (self::MS_GRAPH_SERVICES_TO_REMOVE as $serviceId) {
|
||||
$container->removeDefinition($serviceId);
|
||||
}
|
||||
} else {
|
||||
throw new \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Unsupported remote calendar scheme: '.$scheme);
|
||||
}
|
||||
|
||||
if (!$container->hasAlias(Azure::class) && $container->hasDefinition('knpu.oauth2.client.azure')) {
|
||||
@@ -62,7 +83,9 @@ class RemoteCalendarCompilerPass implements CompilerPassInterface
|
||||
|
||||
foreach ([
|
||||
NullRemoteCalendarConnector::class,
|
||||
MSGraphRemoteCalendarConnector::class, ] as $serviceId) {
|
||||
MSGraphRemoteCalendarConnector::class,
|
||||
self::ZIMBRA_CONNECTOR,
|
||||
] as $serviceId) {
|
||||
if ($connector === $serviceId) {
|
||||
$container->getDefinition($serviceId)
|
||||
->setDecoratedService(RemoteCalendarConnectorInterface::class);
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
"champs-libres/wopi-bundle": {
|
||||
"version": "dev-master"
|
||||
},
|
||||
"chill-project/chill-zimbra-bundle": {
|
||||
"version": "dev-472-zimbra-connector"
|
||||
},
|
||||
"doctrine/annotations": {
|
||||
"version": "1.14",
|
||||
"recipe": {
|
||||
|
||||
Reference in New Issue
Block a user