msgraph: add metadata to users to connect with default calendar

This commit is contained in:
2022-05-06 10:13:32 +02:00
parent 5331f1becc
commit 9935af0497
9 changed files with 181 additions and 12 deletions

View File

@@ -40,13 +40,10 @@ class AzureGetMachineAccessTokenCommand extends Command
protected function configure()
{
$this
->addOption('tenant', 't', InputOption::VALUE_OPTIONAL, 'the tenant, usually the application name', 'common');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->azure->tenant = $input->getOption('tenant');
$this->azure->scope = ['https://graph.microsoft.com/.default'];
$authorizationUrl = explode('?', $this->azure->getAuthorizationUrl(['prompt' => 'consent']));
// replace the first part by the admin consent authorization url

View File

@@ -0,0 +1,50 @@
<?php
namespace Chill\CalendarBundle\Command;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MachineTokenStorage;
use Chill\CalendarBundle\Synchro\Connector\MSGraphRemoteCalendarConnector;
use Chill\MainBundle\Repository\UserRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MapUserCalendarCommand extends Command
{
private MSGraphRemoteCalendarConnector $remoteCalendarConnector;
private UserRepository $userRepository;
public function __construct(MSGraphRemoteCalendarConnector $remoteCalendarConnector)
{
parent::__construct('chill:calendar:map-user');
$this->remoteCalendarConnector = $remoteCalendarConnector;
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$limit = 2;
do {
$users = $this->userRepository->findByNotHavingAttribute('ms:graph', $limit);
foreach ($users as $user) {
$usersData = $this->remoteCalendarConnector->getUserByEmail($user->getEmailCanonical());
$defaultCalendar
$user->setAttributes(['ms:graph' => [
]]);
}
} while (count($users) === $limit);
return 0;
}
}