mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge remote-tracking branch 'origin/master' into issue718_workflow_suggest_users
This commit is contained in:
commit
8d3888068d
@ -257,12 +257,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
||||
/**
|
||||
* Add a social issue.
|
||||
*
|
||||
* Note: the social issue consistency (the fact that only yougest social issues
|
||||
* Note: the social issue consistency (the fact that only youngest social issues
|
||||
* are kept) is processed by an entity listener:
|
||||
*
|
||||
* @see{\Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener}
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addSocialIssue(SocialIssue $socialIssue): self
|
||||
{
|
||||
@ -270,6 +268,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
||||
$this->socialIssues[] = $socialIssue;
|
||||
}
|
||||
|
||||
if ($this->getAccompanyingPeriod() !== null) {
|
||||
$this->getAccompanyingPeriod()->addSocialIssue($socialIssue);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -550,6 +552,10 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
||||
{
|
||||
$this->accompanyingPeriod = $accompanyingPeriod;
|
||||
|
||||
foreach ($this->getSocialIssues() as $issue) {
|
||||
$this->accompanyingPeriod->addSocialIssue($issue);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ class ActivityContext implements
|
||||
$options = $template->getOptions();
|
||||
|
||||
$data = [];
|
||||
$data = array_merge($data, $this->baseContextData->getData());
|
||||
$data = array_merge($data, $this->baseContextData->getData($contextGenerationData['creator'] ?? null));
|
||||
$data['activity'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => Activity::class, 'groups' => 'docgen:read']);
|
||||
|
||||
$data['course'] = $this->normalizer->normalize($entity->getAccompanyingPeriod(), 'docgen', ['docgen:expects' => AccompanyingPeriod::class, 'groups' => 'docgen:read']);
|
||||
|
@ -22,6 +22,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
use LogicException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use function array_key_exists;
|
||||
|
||||
@ -74,9 +75,18 @@ class MapCalendarToUser
|
||||
|
||||
public function getDefaultUserCalendar(string $idOrUserPrincipalName): ?array
|
||||
{
|
||||
$value = $this->machineHttpClient->request('GET', "users/{$idOrUserPrincipalName}/calendars", [
|
||||
'query' => ['$filter' => 'isDefaultCalendar eq true'],
|
||||
])->toArray()['value'];
|
||||
try {
|
||||
$value = $this->machineHttpClient->request('GET', "users/{$idOrUserPrincipalName}/calendars", [
|
||||
'query' => ['$filter' => 'isDefaultCalendar eq true'],
|
||||
])->toArray()['value'];
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->logger->error('[MapCalendarToUser] Error while listing calendars for a user', [
|
||||
'http_status_code' => $e->getResponse()->getStatusCode(),
|
||||
'id_user' => $idOrUserPrincipalName,
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value[0] ?? null;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
@ -64,6 +65,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
|
||||
private OnBehalfOfUserHttpClient $userHttpClient;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
CalendarRepository $calendarRepository,
|
||||
CalendarRangeRepository $calendarRangeRepository,
|
||||
@ -74,7 +77,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
OnBehalfOfUserHttpClient $userHttpClient,
|
||||
RemoteEventConverter $remoteEventConverter,
|
||||
TranslatorInterface $translator,
|
||||
UrlGeneratorInterface $urlGenerator
|
||||
UrlGeneratorInterface $urlGenerator,
|
||||
Security $security
|
||||
) {
|
||||
$this->calendarRepository = $calendarRepository;
|
||||
$this->calendarRangeRepository = $calendarRangeRepository;
|
||||
@ -86,6 +90,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
$this->translator = $translator;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->userHttpClient = $userHttpClient;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function countEventsForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate): int
|
||||
@ -133,6 +138,24 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ final class CalendarContext implements CalendarContextInterface
|
||||
$options = $this->getOptions($template);
|
||||
|
||||
$data = array_merge(
|
||||
$this->baseContextData->getData(),
|
||||
$this->baseContextData->getData($contextGenerationData['creator'] ?? null),
|
||||
[
|
||||
'calendar' => $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => Calendar::class, 'groups' => ['docgen:read']]),
|
||||
]
|
||||
|
@ -205,7 +205,7 @@ final class CalendarContextTest extends TestCase
|
||||
?NormalizerInterface $normalizer = null
|
||||
): CalendarContext {
|
||||
$baseContext = $this->prophesize(BaseContextData::class);
|
||||
$baseContext->getData()->willReturn(['base_context' => 'data']);
|
||||
$baseContext->getData(null)->willReturn(['base_context' => 'data']);
|
||||
|
||||
$personRender = $this->prophesize(PersonRender::class);
|
||||
$personRender->renderString(Argument::type(Person::class), [])->willReturn('person name');
|
||||
|
@ -21,18 +21,14 @@ class BaseContextData
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security, NormalizerInterface $normalizer)
|
||||
public function __construct(NormalizerInterface $normalizer)
|
||||
{
|
||||
$this->security = $security;
|
||||
$this->normalizer = $normalizer;
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
public function getData(?User $user = null): array
|
||||
{
|
||||
$data = [];
|
||||
$user = $this->security->getUser();
|
||||
|
||||
$data['creator'] = $this->normalizer->normalize(
|
||||
$user instanceof User ? $user : null,
|
||||
|
@ -9,6 +9,7 @@ use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface;
|
||||
use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
@ -55,7 +56,8 @@ class Generator implements GeneratorInterface
|
||||
array $contextGenerationDataNormalized,
|
||||
?StoredObject $destinationStoredObject = null,
|
||||
bool $isTest = false,
|
||||
?File $testFile = null
|
||||
?File $testFile = null,
|
||||
?User $creator = null
|
||||
): ?string {
|
||||
if ($destinationStoredObject instanceof StoredObject && StoredObject::STATUS_PENDING !== $destinationStoredObject->getStatus()) {
|
||||
$this->logger->info(self::LOG_PREFIX.'Aborting generation of an already generated document');
|
||||
@ -80,6 +82,7 @@ class Generator implements GeneratorInterface
|
||||
|
||||
$contextGenerationDataNormalized = array_merge(
|
||||
$contextGenerationDataNormalized,
|
||||
['creator' => $creator],
|
||||
$context instanceof DocGeneratorContextWithPublicFormInterface ?
|
||||
$context->contextGenerationDataDenormalize($template, $entity, $contextGenerationDataNormalized)
|
||||
: []
|
||||
|
@ -4,6 +4,7 @@ namespace Chill\DocGeneratorBundle\Service\Generator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
interface GeneratorInterface
|
||||
@ -22,6 +23,7 @@ interface GeneratorInterface
|
||||
array $contextGenerationDataNormalized,
|
||||
?StoredObject $destinationStoredObject = null,
|
||||
bool $isTest = false,
|
||||
?File $testFile = null
|
||||
?File $testFile = null,
|
||||
?User $creator = null
|
||||
): ?string;
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\DocGeneratorBundle\Service\Generator\Generator;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
@ -23,18 +25,28 @@ class RequestGenerationHandler implements MessageHandlerInterface
|
||||
|
||||
private Generator $generator;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private UserRepositoryInterface $userRepository;
|
||||
|
||||
public const AUTHORIZED_TRIALS = 5;
|
||||
|
||||
private const LOG_PREFIX = '[docgen message handler] ';
|
||||
|
||||
public function __construct(
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
EntityManagerInterface $entityManager,
|
||||
Generator $generator,
|
||||
StoredObjectRepository $storedObjectRepository
|
||||
LoggerInterface $logger,
|
||||
StoredObjectRepository $storedObjectRepository,
|
||||
UserRepositoryInterface $userRepository
|
||||
) {
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->generator = $generator;
|
||||
$this->logger = $logger;
|
||||
$this->storedObjectRepository = $storedObjectRepository;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function __invoke(RequestGenerationMessage $message)
|
||||
@ -51,6 +63,8 @@ class RequestGenerationHandler implements MessageHandlerInterface
|
||||
throw new UnrecoverableMessageHandlingException('maximum number of retry reached');
|
||||
}
|
||||
|
||||
$creator = $this->userRepository->find($message->getCreatorId());
|
||||
|
||||
$destinationStoredObject->addGenerationTrial();
|
||||
$this->entityManager->createQuery('UPDATE '.StoredObject::class.' s SET s.generationTrialsCounter = s.generationTrialsCounter + 1 WHERE s.id = :id')
|
||||
->setParameter('id', $destinationStoredObject->getId())
|
||||
@ -60,7 +74,16 @@ class RequestGenerationHandler implements MessageHandlerInterface
|
||||
$template,
|
||||
$message->getEntityId(),
|
||||
$message->getContextGenerationData(),
|
||||
$destinationStoredObject
|
||||
$destinationStoredObject,
|
||||
false,
|
||||
null,
|
||||
$creator
|
||||
);
|
||||
|
||||
$this->logger->info(self::LOG_PREFIX.'Request generation finished', [
|
||||
'template_id' => $message->getTemplateId(),
|
||||
'destination_stored_object' => $message->getDestinationStoredObjectId(),
|
||||
'duration_int' => (new \DateTimeImmutable('now'))->getTimestamp() - $message->getCreatedAt()->getTimestamp(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ class RequestGenerationMessage
|
||||
|
||||
private array $contextGenerationData;
|
||||
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
public function __construct(
|
||||
User $creator,
|
||||
DocGeneratorTemplate $template,
|
||||
@ -30,6 +32,7 @@ class RequestGenerationMessage
|
||||
$this->entityId = $entityId;
|
||||
$this->destinationStoredObjectId = $destinationStoredObject->getId();
|
||||
$this->contextGenerationData = $contextGenerationData;
|
||||
$this->createdAt = new \DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
public function getCreatorId(): int
|
||||
@ -56,4 +59,9 @@ class RequestGenerationMessage
|
||||
{
|
||||
return $this->contextGenerationData;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
}
|
||||
|
@ -76,8 +76,17 @@ class SimilarPersonMatcher
|
||||
|
||||
$qb->select('p')
|
||||
->from(Person::class, 'p')
|
||||
->join('p.centerHistory', 'center_history')
|
||||
->where('SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) >= :precision')
|
||||
->andWhere($qb->expr()->in('p.center', ':centers'));
|
||||
->andWhere($qb->expr()->in('center_history.center', ':centers'))
|
||||
->andWhere($qb->expr()->andX(
|
||||
$qb->expr()->lte('center_history.startDate', 'CURRENT_DATE()'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('center_history.endDate'),
|
||||
$qb->expr()->gt('center_history.endDate', 'CURRENT_DATE()')
|
||||
)
|
||||
))
|
||||
;
|
||||
|
||||
$qb
|
||||
->setParameter('fullName', $this->personRender->renderString($person, []))
|
||||
@ -117,7 +126,6 @@ class SimilarPersonMatcher
|
||||
$qb->setParameter('fullName', $this->personRender->renderString($person, []));
|
||||
}
|
||||
|
||||
dump($qb->getQuery());
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ class AccompanyingPeriodContext implements
|
||||
$options = $template->getOptions();
|
||||
|
||||
$data = [];
|
||||
$data = array_merge($data, $this->baseContextData->getData());
|
||||
$data = array_merge($data, $this->baseContextData->getData($contextGenerationData['creator'] ?? null));
|
||||
$data['course'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => AccompanyingPeriod::class, 'groups' => 'docgen:read']);
|
||||
|
||||
foreach (['mainPerson', 'person1', 'person2'] as $k) {
|
||||
|
@ -165,7 +165,7 @@ final class PersonContext implements PersonContextInterface
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data = array_merge($data, $this->baseContextData->getData());
|
||||
$data = array_merge($data, $this->baseContextData->getData($contextGenerationData['creator'] ?? null));
|
||||
$data['person'] = $this->normalizer->normalize($entity, 'docgen', [
|
||||
'docgen:expects' => Person::class,
|
||||
'groups' => ['docgen:read'],
|
||||
|
@ -54,7 +54,7 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
|
||||
$activities = $this->activityRepository->findBy(['accompanyingPeriod' => $period]);
|
||||
|
||||
foreach ($activities as $activity) {
|
||||
$socialIssues = $activity->getSocialIssues()->toArray();
|
||||
$socialIssues = array_merge($socialIssues, $activity->getSocialIssues()->toArray());
|
||||
}
|
||||
|
||||
foreach ($period->getWorks() as $work) {
|
||||
@ -64,7 +64,7 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
|
||||
$socialIssuesByKey = [];
|
||||
|
||||
foreach ($socialIssues as $si) {
|
||||
$socialIssuesByKey[$si->getId()] = $si;
|
||||
$socialIssuesByKey[spl_object_hash($si)] = $si;
|
||||
}
|
||||
|
||||
$periodIssuesWithAncestors = [];
|
||||
@ -75,7 +75,7 @@ class AccompanyingPeriodValidityValidator extends ConstraintValidator
|
||||
$periodIssuesWithAncestors,
|
||||
array_map(
|
||||
static function (SocialIssue $si) {
|
||||
return $si->getId();
|
||||
return spl_object_hash($si);
|
||||
},
|
||||
$si->getAncestors(true)
|
||||
)
|
||||
|
@ -805,12 +805,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setProfession(string $profession): self
|
||||
public function setProfession(?string $profession): self
|
||||
{
|
||||
$this->profession = $profession;
|
||||
$this->profession = (string) $profession;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ class ThirdPartyType extends AbstractType
|
||||
->add('profession', TextType::class, [
|
||||
'label' => 'thirdparty.Profession',
|
||||
'required' => false,
|
||||
'empty_data' => '',
|
||||
])
|
||||
->add('contactDataAnonymous', CheckboxType::class, [
|
||||
'required' => false,
|
||||
|
@ -18,6 +18,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\Mime\Part\DataPart;
|
||||
@ -40,6 +41,8 @@ class Convert
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
private Security $security;
|
||||
|
||||
private StoredObjectManagerInterface $storedObjectManager;
|
||||
@ -49,12 +52,14 @@ class Convert
|
||||
*/
|
||||
public function __construct(
|
||||
HttpClientInterface $httpClient,
|
||||
RequestStack $requestStack,
|
||||
Security $security,
|
||||
StoredObjectManagerInterface $storedObjectManager,
|
||||
LoggerInterface $logger,
|
||||
ParameterBagInterface $parameters
|
||||
) {
|
||||
$this->httpClient = $httpClient;
|
||||
$this->requestStack = $requestStack;
|
||||
$this->security = $security;
|
||||
$this->storedObjectManager = $storedObjectManager;
|
||||
$this->logger = $logger;
|
||||
@ -68,6 +73,10 @@ class Convert
|
||||
}
|
||||
|
||||
$content = $this->storedObjectManager->read($storedObject);
|
||||
$query = [];
|
||||
if (null !== $request = $this->requestStack->getCurrentRequest()) {
|
||||
$query['lang'] = $request->getLocale();
|
||||
}
|
||||
|
||||
try {
|
||||
$url = sprintf('%s/cool/convert-to/pdf', $this->collaboraDomain);
|
||||
@ -76,6 +85,7 @@ class Convert
|
||||
]);
|
||||
$response = $this->httpClient->request('POST', $url, [
|
||||
'headers' => $form->getPreparedHeaders()->toArray(),
|
||||
'query' => $query,
|
||||
'body' => $form->bodyToString(),
|
||||
'timeout' => 10,
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user