From bdb07a3a053bd7dfc767184d0c3e67b15f5ef0f6 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 21 Mar 2022 12:10:03 +0100 Subject: [PATCH 1/2] options added to create person or parcours and to access global history --- .../ChillMainExtension.php | 5 +++ .../DependencyInjection/Configuration.php | 3 ++ .../MenuBuilder/SectionMenuBuilder.php | 34 +++++++++---------- .../ChillPersonExtension.php | 10 ++++++ .../DependencyInjection/Configuration.php | 6 ++++ .../Menu/SectionMenuBuilder.php | 32 ++++++++--------- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 09668f0e3..62a3d80d8 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -114,6 +114,11 @@ class ChillMainExtension extends Extension implements $config['available_countries'] ); + $container->setParameter( + 'chill_main.access_global_history', + $config['access_global_history'] + ); + $container->setParameter( 'chill_main.routing.resources', $config['routing']['resources'] diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index be8baf79a..7ced6aac6 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -113,6 +113,9 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->end() + ->booleanNode('access_global_history') + ->defaultTrue() + ->end() ->arrayNode('redis') ->children() ->scalarNode('host') diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php index 1a5ae9afe..03ae20a37 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php @@ -14,6 +14,7 @@ namespace Chill\MainBundle\Routing\MenuBuilder; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Chill\MainBundle\Security\Authorization\ChillExportVoter; use Knp\Menu\MenuItem; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -22,23 +23,20 @@ use Symfony\Contracts\Translation\TranslatorInterface; */ class SectionMenuBuilder implements LocalMenuBuilderInterface { - /** - * @var AuthorizationCheckerInterface - */ - protected $authorizationChecker; + protected AuthorizationCheckerInterface $authorizationChecker; - /** - * @var TranslatorInterface - */ - protected $translator; + protected TranslatorInterface $translator; + + protected ParameterBagInterface $parameterBag; /** * SectionMenuBuilder constructor. */ - public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator) + public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator, ParameterBagInterface $parameterBag) { $this->authorizationChecker = $authorizationChecker; $this->translator = $translator; + $this->parameterBag = $parameterBag; } /** @@ -54,14 +52,16 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface 'order' => 0, ]); - $menu->addChild($this->translator->trans('Global timeline'), [ - 'route' => 'chill_center_timeline', - ]) - ->setExtras( - [ - 'order' => 10, - ] - ); + if ($this->parameterBag->get('chill_main.access_global_history')) { + $menu->addChild($this->translator->trans('Global timeline'), [ + 'route' => 'chill_center_timeline', + ]) + ->setExtras( + [ + 'order' => 10, + ] + ); + } if ($this->authorizationChecker->isGranted(ChillExportVoter::EXPORT)) { $menu->addChild($this->translator->trans('Export Menu'), [ diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index 1f85e4ad0..6d2bf6d18 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -59,6 +59,16 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $config['allow_multiple_simultaneous_accompanying_periods'] ); + $container->setParameter( + 'chill_person.create_person_allowed', + $config['create_person_allowed'] + ); + + $container->setParameter( + 'chill_person.create_parcours_allowed', + $config['create_parcours_allowed'] + ); + // register all configuration in a unique parameter $container->setParameter('chill_person', $config); diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php index 8a0cab301..7b483a633 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php @@ -62,6 +62,12 @@ class Configuration implements ConfigurationInterface ->end() // children for 'validation', parent = validation ->end() //validation, parent = children of root ->end() // children of root, parent = root + ->booleanNode('create_person_allowed') + ->defaultTrue() + ->end() + ->booleanNode('create_parcours_allowed') + ->defaultTrue() + ->end() ->arrayNode('person_fields') ->canBeDisabled() ->children() diff --git a/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php index 04f989d84..75f3346ff 100644 --- a/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php @@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Menu; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Knp\Menu\MenuItem; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -22,23 +23,18 @@ use Symfony\Contracts\Translation\TranslatorInterface; */ class SectionMenuBuilder implements LocalMenuBuilderInterface { - /** - * @var AuthorizationCheckerInterface - */ - protected $authorizationChecker; + protected AuthorizationCheckerInterface $authorizationChecker; - /** - * @var TranslatorInterface - */ - protected $translator; + protected TranslatorInterface $translator; /** * SectionMenuBuilder constructor. */ - public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator) + public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator, ParameterBagInterface $parameterBag) { $this->authorizationChecker = $authorizationChecker; $this->translator = $translator; + $this->parameterBag = $parameterBag; } /** @@ -46,7 +42,7 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface */ public function buildMenu($menuId, MenuItem $menu, array $parameters) { - if ($this->authorizationChecker->isGranted(PersonVoter::CREATE)) { + if ($this->authorizationChecker->isGranted(PersonVoter::CREATE) && $this->parameterBag->get('chill_person.create_person_allowed')) { $menu->addChild($this->translator->trans('Add a person'), [ 'route' => 'chill_person_new', ]) @@ -56,13 +52,15 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface ]); } - $menu->addChild($this->translator->trans('Create an accompanying course'), [ - 'route' => 'chill_person_accompanying_course_new', - ]) - ->setExtras([ - 'order' => 11, - 'icons' => ['plus'], - ]); + if ($this->parameterBag->get('chill_person.create_parcours_allowed')) { + $menu->addChild($this->translator->trans('Create an accompanying course'), [ + 'route' => 'chill_person_accompanying_course_new', + ]) + ->setExtras([ + 'order' => 11, + 'icons' => ['plus'], + ]); + } } public static function getMenuIds(): array From 9b97b03d4257d25528a660bc0a329b5f7ec923af Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 21 Mar 2022 12:16:49 +0100 Subject: [PATCH 2/2] csfixes --- .../ChillMainBundle/Command/LoadPostalCodesCommand.php | 5 +++-- .../Routing/MenuBuilder/SectionMenuBuilder.php | 4 ++-- .../Serializer/Normalizer/PhonenumberNormalizer.php | 9 ++++----- .../Menu/AccompanyingCourseMenuBuilder.php | 2 +- ...anyingPeriodWorkEvaluationDocumentWorkflowHandler.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php b/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php index 5d577a0b4..bc4616b7b 100644 --- a/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php +++ b/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php @@ -26,6 +26,7 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Validator\Validator\ValidatorInterface; use function count; +use function strlen; class LoadPostalCodesCommand extends Command { @@ -118,11 +119,11 @@ class LoadPostalCodesCommand extends Command private function addPostalCode($row, OutputInterface $output) { - if($row[2] == 'FR' && strlen($row[0]) == 4) { + if ('FR' === $row[2] && strlen($row[0]) === 4) { // CP in FRANCE are on 5 digit // For CP starting with a zero, the starting zero can be remove if stored as number in a csv // add a zero if CP from FR and on 4 digit - $row[0] = '0'.$row[0]; + $row[0] = '0' . $row[0]; } if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php index 03ae20a37..10acf2d6c 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php @@ -25,10 +25,10 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface { protected AuthorizationCheckerInterface $authorizationChecker; - protected TranslatorInterface $translator; - protected ParameterBagInterface $parameterBag; + protected TranslatorInterface $translator; + /** * SectionMenuBuilder constructor. */ diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php index 677199ad4..7eb323754 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php @@ -18,7 +18,6 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; class PhonenumberNormalizer implements ContextAwareNormalizerInterface, DenormalizerInterface { @@ -54,7 +53,7 @@ class PhonenumberNormalizer implements ContextAwareNormalizerInterface, Denormal public function normalize($object, ?string $format = null, array $context = []): string { - if ($format === 'docgen' && null === $object) { + if ('docgen' === $format && null === $object) { return ''; } @@ -68,13 +67,13 @@ class PhonenumberNormalizer implements ContextAwareNormalizerInterface, Denormal public function supportsNormalization($data, ?string $format = null, array $context = []): bool { - if ($data instanceof PhoneNumber && $format === 'json') { + if ($data instanceof PhoneNumber && 'json' === $format) { return true; } - if ($format === 'docgen' && ( + if ('docgen' === $format && ( $data instanceof PhoneNumber || PhoneNumber::class === ($context['docgen:expects'] ?? null) - )) { + )) { return true; } diff --git a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php index 8f1ecb0d1..929fb2ae0 100644 --- a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php @@ -75,7 +75,7 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface 'accompanying_period_id' => $period->getId(), ], ]) ->setExtras(['order' => 30]); - */ + */ $menu->addChild($this->translator->trans('Accompanying Course Comment'), [ 'route' => 'chill_person_accompanying_period_comment_list', diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index d7a196a6c..d7ce1ed4b 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -62,7 +62,7 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW 'workflow.Doc for evaluation (n°%eval%)', ['%eval%' => $entityWorkflow->getRelatedEntityId()] ) . ' (' . $this->translatableStringHelper->localize($doc->getAccompanyingPeriodWorkEvaluation() - ->getEvaluation()->getTitle()).') '.$doc->getTitle(); + ->getEvaluation()->getTitle()) . ') ' . $doc->getTitle(); } public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?AccompanyingPeriodWorkEvaluationDocument