From f77031630f9d1f58bed8741b577ab845682c26de Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 16 May 2022 13:52:55 +0200 Subject: [PATCH] [main] allow hide change user password menu --- CHANGELOG.md | 1 + .../ChillMainExtension.php | 5 ++++ .../DependencyInjection/Configuration.php | 3 +++ .../Routing/MenuBuilder/UserMenuBuilder.php | 25 ++++++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b20e4422b..f86c1b0bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [main] allow hide change user password menu (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/577) * [main] filter user jobs by active jobs (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/577) * [main] add civility to User (entity, migration and form type) (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/577) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 0611b9848..2c25d35f3 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -129,6 +129,11 @@ class ChillMainExtension extends Extension implements $config['access_global_history'] ); + $container->setParameter( + 'chill_main.access_user_change_password', + $config['access_user_change_password'] + ); + $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 7ced6aac6..2fa6df80a 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -116,6 +116,9 @@ class Configuration implements ConfigurationInterface ->booleanNode('access_global_history') ->defaultTrue() ->end() + ->booleanNode('access_user_change_password') + ->defaultTrue() + ->end() ->arrayNode('redis') ->children() ->scalarNode('host') diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php index b2fd5180e..df3ba5121 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\User; use Chill\MainBundle\Notification\Counter\NotificationByUserCounter; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Chill\MainBundle\Workflow\Counter\WorkflowByUserCounter; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; @@ -28,16 +29,20 @@ class UserMenuBuilder implements LocalMenuBuilderInterface private WorkflowByUserCounter $workflowByUserCounter; + protected ParameterBagInterface $parameterBag; + public function __construct( NotificationByUserCounter $notificationByUserCounter, WorkflowByUserCounter $workflowByUserCounter, Security $security, - TranslatorInterface $translator + TranslatorInterface $translator, + ParameterBagInterface $parameterBag ) { $this->notificationByUserCounter = $notificationByUserCounter; $this->workflowByUserCounter = $workflowByUserCounter; $this->security = $security; $this->translator = $translator; + $this->parameterBag = $parameterBag; } public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters) @@ -85,14 +90,16 @@ class UserMenuBuilder implements LocalMenuBuilderInterface 'order' => 700, ]); - $menu - ->addChild( - 'Change password', - ['route' => 'change_my_password'] - ) - ->setExtras([ - 'order' => 99999999998, - ]); + if ($this->parameterBag->get('chill_main.access_user_change_password')) { + $menu + ->addChild( + 'Change password', + ['route' => 'change_my_password'] + ) + ->setExtras([ + 'order' => 99999999998, + ]); + } } $menu