From 380c55698cd4bfca3387e7272f67f5dbca7db3f5 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 16 May 2022 11:28:37 +0200 Subject: [PATCH 01/12] main: add civility to User --- CHANGELOG.md | 2 + src/Bundle/ChillMainBundle/Entity/User.php | 17 ++++++++ src/Bundle/ChillMainBundle/Form/UserType.php | 6 +++ .../Resources/views/User/index.html.twig | 5 +++ .../migrations/Version20220513151853.php | 16 +++++--- .../migrations/Version20220516085659.php | 40 +++++++++++++++++++ 6 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20220516085659.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 077cc0242..5f85ec8c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to ## Unreleased +* [main] add civility to User (entity, migration and form type) (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/577) + * [admin] refactorisation of the admin section: reorganisation of the menu, translations, form types, new entities (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/592) * [admin] add admin section for languages and countries (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/596) * [activity] activity admin: translations + remove label field for comment on admin activity type (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/587) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index ad4888d58..80848e2cf 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -47,6 +47,11 @@ class User implements AdvancedUserInterface */ private array $attributes = []; + /** + * @ORM\ManyToOne(targetEntity=Civility::class) + */ + private ?Civility $civility = null; + /** * @ORM\ManyToOne(targetEntity=Location::class) */ @@ -184,6 +189,11 @@ class User implements AdvancedUserInterface return $this->attributes; } + public function getCivility(): ?Civility + { + return $this->civility; + } + public function getCurrentLocation(): ?Location { return $this->currentLocation; @@ -363,6 +373,13 @@ class User implements AdvancedUserInterface return $this; } + public function setCivility(?Civility $civility): User + { + $this->civility = $civility; + + return $this; + } + public function setCurrentLocation(?Location $currentLocation): User { $this->currentLocation = $currentLocation; diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index 6662d0bab..9ba25b37f 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\UserJob; +use Chill\MainBundle\Form\Type\PickCivilityType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -47,6 +48,11 @@ class UserType extends AbstractType 'required' => true, ]) ->add('label', TextType::class) + ->add('civility', PickCivilityType::class, [ + 'required' => false, + 'label' => 'Civility', + 'placeholder' => 'choose civility', + ]) ->add('mainCenter', EntityType::class, [ 'label' => 'Main center', 'required' => false, diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig index bab54d56e..1d254abb9 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig @@ -11,6 +11,11 @@
+ {% if entity.civility is not null %} + {% if entity.civility.name|length > 0 %} + {{ entity.civility.name|first }} + {% endif %} + {% endif %} {{ entity.label }} {% if entity.isEnabled %} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php b/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php index 31319ce1b..ec99ce2ba 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20220513151853.php @@ -1,5 +1,12 @@ addSql('update users set attributes = \'[]\'::json where attributes IS NULL'); } - - public function down(Schema $schema): void - { - - } } diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220516085659.php b/src/Bundle/ChillMainBundle/migrations/Version20220516085659.php new file mode 100644 index 000000000..8e4d7347b --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220516085659.php @@ -0,0 +1,40 @@ +addSql('ALTER TABLE users DROP CONSTRAINT FK_1483A5E923D6A298'); + $this->addSql('DROP INDEX IDX_1483A5E923D6A298'); + $this->addSql('ALTER TABLE users DROP civility_id'); + } + + public function getDescription(): string + { + return 'Add civility to User'; + } + + public function up(Schema $schema): void + { + $this->addSql('ALTER TABLE users ADD civility_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E923D6A298 FOREIGN KEY (civility_id) REFERENCES chill_main_civility (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_1483A5E923D6A298 ON users (civility_id)'); + } +} From 8eef073988cd3442223fa71c50cc7ad6184f2f98 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 16 May 2022 11:49:36 +0200 Subject: [PATCH 02/12] [main] filter user jobs by active jobs --- CHANGELOG.md | 1 + src/Bundle/ChillMainBundle/Form/UserType.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f85ec8c9..b20e4422b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [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) * [admin] refactorisation of the admin section: reorganisation of the menu, translations, form types, new entities (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/592) diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index 9ba25b37f..c2567df4c 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -82,6 +82,11 @@ class UserType extends AbstractType 'choice_label' => function (UserJob $c) { return $this->translatableStringHelper->localize($c->getLabel()); }, + 'query_builder' => static function (EntityRepository $er) { + $qb = $er->createQueryBuilder('uj'); + $qb->where('uj.active = TRUE'); + return $qb; + }, ]) ->add('mainLocation', EntityType::class, [ 'label' => 'Main location', From f77031630f9d1f58bed8741b577ab845682c26de Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 16 May 2022 13:52:55 +0200 Subject: [PATCH 03/12] [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 From cecfa1a18a01babb12531240037d998f4078a892 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 16 May 2022 14:07:34 +0200 Subject: [PATCH 04/12] main: allow creation of user without password --- .../ChillMainBundle/Controller/UserController.php | 9 +++++++-- src/Bundle/ChillMainBundle/Form/UserType.php | 12 +++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index 068bd9f73..b344a0b2e 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -23,6 +23,7 @@ use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Templating\Listing\FilterOrderHelper; use Psr\Log\LoggerInterface; use RuntimeException; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; @@ -45,16 +46,20 @@ class UserController extends CRUDController private ValidatorInterface $validator; + protected ParameterBagInterface $parameterBag; + public function __construct( LoggerInterface $chillLogger, ValidatorInterface $validator, UserPasswordEncoderInterface $passwordEncoder, - UserRepository $userRepository + UserRepository $userRepository, + ParameterBagInterface $parameterBag ) { $this->logger = $chillLogger; $this->userRepository = $userRepository; $this->validator = $validator; $this->passwordEncoder = $passwordEncoder; + $this->parameterBag = $parameterBag; } /** @@ -307,7 +312,7 @@ class UserController extends CRUDController protected function onPrePersist(string $action, $entity, FormInterface $form, Request $request) { // for "new", encode the password - if ('new' === $action) { + if ('new' === $action && $this->parameterBag->get('chill_main.access_user_change_password')) { $entity->setPassword($this->passwordEncoder ->encodePassword($entity, $form['plainPassword']->getData())); } diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index c2567df4c..72047ce61 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -19,6 +19,7 @@ use Chill\MainBundle\Form\Type\PickCivilityType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\EmailType; @@ -35,9 +36,14 @@ class UserType extends AbstractType { private TranslatableStringHelper $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper) - { + protected ParameterBagInterface $parameterBag; + + public function __construct( + TranslatableStringHelper $translatableStringHelper, + ParameterBagInterface $parameterBag + ) { $this->translatableStringHelper = $translatableStringHelper; + $this->parameterBag = $parameterBag; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -105,7 +111,7 @@ class UserType extends AbstractType }, ]); - if ($options['is_creation']) { + if ($options['is_creation'] && $this->parameterBag->get('chill_main.access_user_change_password')) { $builder->add('plainPassword', RepeatedType::class, [ 'mapped' => false, 'type' => PasswordType::class, From a4210dd2c7ff97ed560014120e50ad1fe329bcfb Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 18 May 2022 09:30:47 +0200 Subject: [PATCH 05/12] [main] allow hide permissions group list menu --- CHANGELOG.md | 1 + .../Controller/UserController.php | 4 ++-- .../DependencyInjection/ChillMainExtension.php | 5 +++++ .../DependencyInjection/Configuration.php | 3 +++ src/Bundle/ChillMainBundle/Form/UserType.php | 5 +++-- .../MenuBuilder/AdminUserMenuBuilder.php | 18 +++++++++++++----- .../Routing/MenuBuilder/UserMenuBuilder.php | 4 ++-- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f86c1b0bc..509682ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [main] allow hide permissions group list menu (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/577) * [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/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index b344a0b2e..164c2a534 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -38,6 +38,8 @@ class UserController extends CRUDController { public const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter'; + protected ParameterBagInterface $parameterBag; + private LoggerInterface $logger; private UserPasswordEncoderInterface $passwordEncoder; @@ -46,8 +48,6 @@ class UserController extends CRUDController private ValidatorInterface $validator; - protected ParameterBagInterface $parameterBag; - public function __construct( LoggerInterface $chillLogger, ValidatorInterface $validator, diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 2c25d35f3..929bffe14 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -134,6 +134,11 @@ class ChillMainExtension extends Extension implements $config['access_user_change_password'] ); + $container->setParameter( + 'chill_main.access_permissions_group_list', + $config['access_permissions_group_list'] + ); + $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 2fa6df80a..a9b3ffec0 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -119,6 +119,9 @@ class Configuration implements ConfigurationInterface ->booleanNode('access_user_change_password') ->defaultTrue() ->end() + ->booleanNode('access_permissions_group_list') + ->defaultTrue() + ->end() ->arrayNode('redis') ->children() ->scalarNode('host') diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index 72047ce61..9e7da7a89 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -34,10 +34,10 @@ use Symfony\Component\Validator\Constraints\Regex; class UserType extends AbstractType { - private TranslatableStringHelper $translatableStringHelper; - protected ParameterBagInterface $parameterBag; + private TranslatableStringHelper $translatableStringHelper; + public function __construct( TranslatableStringHelper $translatableStringHelper, ParameterBagInterface $parameterBag @@ -91,6 +91,7 @@ class UserType extends AbstractType 'query_builder' => static function (EntityRepository $er) { $qb = $er->createQueryBuilder('uj'); $qb->where('uj.active = TRUE'); + return $qb; }, ]) diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/AdminUserMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/AdminUserMenuBuilder.php index 7b3399503..b885e1641 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/AdminUserMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/AdminUserMenuBuilder.php @@ -13,6 +13,7 @@ namespace Chill\MainBundle\Routing\MenuBuilder; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Knp\Menu\MenuItem; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; class AdminUserMenuBuilder implements LocalMenuBuilderInterface @@ -22,9 +23,14 @@ class AdminUserMenuBuilder implements LocalMenuBuilderInterface */ protected $authorizationChecker; - public function __construct(AuthorizationCheckerInterface $authorizationChecker) - { + protected ParameterBagInterface $parameterBag; + + public function __construct( + AuthorizationCheckerInterface $authorizationChecker, + ParameterBagInterface $parameterBag + ) { $this->authorizationChecker = $authorizationChecker; + $this->parameterBag = $parameterBag; } public function buildMenu($menuId, MenuItem $menu, array $parameters) @@ -51,9 +57,11 @@ class AdminUserMenuBuilder implements LocalMenuBuilderInterface 'route' => 'admin_scope', ])->setExtras(['order' => 1020]); - $menu->addChild('Permissions group list', [ - 'route' => 'admin_permissionsgroup', - ])->setExtras(['order' => 1030]); + if ($this->parameterBag->get('chill_main.access_permissions_group_list')) { + $menu->addChild('Permissions group list', [ + 'route' => 'admin_permissionsgroup', + ])->setExtras(['order' => 1030]); + } $menu->addChild('crud.admin_user.index.title', [ 'route' => 'chill_crud_admin_user_index', diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php index df3ba5121..6b6f9cceb 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php @@ -21,6 +21,8 @@ use Symfony\Contracts\Translation\TranslatorInterface; class UserMenuBuilder implements LocalMenuBuilderInterface { + protected ParameterBagInterface $parameterBag; + private NotificationByUserCounter $notificationByUserCounter; private Security $security; @@ -29,8 +31,6 @@ class UserMenuBuilder implements LocalMenuBuilderInterface private WorkflowByUserCounter $workflowByUserCounter; - protected ParameterBagInterface $parameterBag; - public function __construct( NotificationByUserCounter $notificationByUserCounter, WorkflowByUserCounter $workflowByUserCounter, From da2c88c026f56ba69165b3d8055dc803419f704e Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 25 May 2022 10:12:07 +0200 Subject: [PATCH 06/12] [admin] show/hide the user permissions group depending on config --- .../Controller/UserController.php | 69 +++++++++++++++ .../Resources/views/User/edit.html.twig | 88 ++++++++++--------- 2 files changed, 114 insertions(+), 43 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index 164c2a534..64a40cdda 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -109,6 +109,7 @@ class UserController extends CRUDController return $this->render('@ChillMain/User/edit.html.twig', [ 'entity' => $user, + 'access_permissions_group_list' => $this->parameterBag->get('chill_main.access_permissions_group_list'), 'edit_form' => $this->createEditForm($user)->createView(), 'add_groupcenter_form' => $this->createAddLinkGroupCenterForm($user, $request)->createView(), 'delete_groupcenter_form' => array_map( @@ -158,6 +159,74 @@ class UserController extends CRUDController return $this->redirect($this->generateUrl('chill_crud_admin_user_edit', ['id' => $uid])); } + + public function edit(Request $request, $id): Response + { + $action = 'edit'; + $entity = $this->getEntity($action, $id, $request); + + if (null === $entity) { + throw $this->createNotFoundException( + sprintf( + 'The %s with id %s is not found', + $this->getCrudName(), + $id + ) + ); + } + + $response = $this->checkACL($action, $entity); + + if ($response instanceof Response) { + return $response; + } + + $response = $this->onPostCheckACL($action, $request, $entity); + + if ($response instanceof Response) { + return $response; + } + + $form = $this->createFormFor($action, $entity); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->onFormValid($action, $entity, $form, $request); + $em = $this->getDoctrine()->getManager(); + + $this->onPreFlush($action, $entity, $form, $request); + $em->flush(); + $this->onPostFlush($action, $entity, $form, $request); + + $this->addFlash('success', $this->generateFormSuccessMessage($action, $entity)); + + $result = $this->onBeforeRedirectAfterSubmission($action, $entity, $form, $request); + + if ($result instanceof Response) { + return $result; + } + + return $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_index'); + } + + if ($form->isSubmitted()) { + $this->addFlash('error', $this->generateFormErrorMessage($action, $form)); + } + + $defaultTemplateParameters = [ + 'form' => $form->createView(), + 'entity' => $entity, + 'crud_name' => $this->getCrudName(), + 'access_permissions_group_list' => $this->parameterBag->get('chill_main.access_permissions_group_list'), + ]; + + return $this->render( + $this->getTemplateFor($action, $entity, $request), + $this->generateTemplateParameter($action, $entity, $request, $defaultTemplateParameters) + ); + } + /** * Displays a form to edit the user current location. * diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/edit.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/edit.html.twig index 0fa376b34..0ecbdef9f 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/edit.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/edit.html.twig @@ -3,54 +3,56 @@ {% block admin_content -%} {% embed '@ChillMain/CRUD/_edit_content.html.twig' %} {% block crud_content_after_form %} -

{{ 'Permissions granted'|trans }}

+ {% if access_permissions_group_list %} +

{{ 'Permissions granted'|trans }}

- {% if entity.groupcenters|length > 0 %} - - - - - - - - - - {% for groupcenter in entity.groupcenters %} + {% if entity.groupcenters|length > 0 %} +
{{ 'Permission group'|trans }}{{ 'Center'|trans }} 
+ - - - + + + - {% endfor %} - -
- - {{ groupcenter.permissionsgroup.name }} - - - - {{ groupcenter.center.name }} - - - {{ form_start(delete_groupcenter_form[groupcenter.id]) }} - {{ form_row(delete_groupcenter_form[groupcenter.id].submit, { 'attr': { 'class': 'btn btn-chill-red' } } ) }} - {{ form_rest(delete_groupcenter_form[groupcenter.id]) }} - {{ form_end(delete_groupcenter_form[groupcenter.id]) }} - {{ 'Permission group'|trans }}{{ 'Center'|trans }} 
- {% else %} -

{{ 'Any permissions granted to this user'|trans }}.

+ + + {% for groupcenter in entity.groupcenters %} + + + + {{ groupcenter.permissionsgroup.name }} + + + + + {{ groupcenter.center.name }} + + + + {{ form_start(delete_groupcenter_form[groupcenter.id]) }} + {{ form_row(delete_groupcenter_form[groupcenter.id].submit, { 'attr': { 'class': 'btn btn-chill-red' } } ) }} + {{ form_rest(delete_groupcenter_form[groupcenter.id]) }} + {{ form_end(delete_groupcenter_form[groupcenter.id]) }} + + + {% endfor %} + + + {% else %} +

{{ 'Any permissions granted to this user'|trans }}.

+ {% endif %} + +

{{ 'Grant new permissions'|trans }}

+ + {{ form_start(add_groupcenter_form) }} + {{ form_row(add_groupcenter_form.composed_groupcenter.center) }} + {{ form_row(add_groupcenter_form.composed_groupcenter.permissionsgroup) }} + {{ form_row(add_groupcenter_form.submit, { 'attr' : { 'class': 'btn btn-chill-green' } } ) }} + + {{ form_end(add_groupcenter_form) }} {% endif %} - -

{{ 'Grant new permissions'|trans }}

- - {{ form_start(add_groupcenter_form) }} - {{ form_row(add_groupcenter_form.composed_groupcenter.center) }} - {{ form_row(add_groupcenter_form.composed_groupcenter.permissionsgroup) }} - {{ form_row(add_groupcenter_form.submit, { 'attr' : { 'class': 'btn btn-chill-green' } } ) }} - - {{ form_end(add_groupcenter_form) }} - {% endblock %} + {% block content_form_actions_save_and_show %}{% endblock %} {% endembed %} {% endblock %} From d6f1aa53dc338d6ace2cdb55eac5f496c7153fe4 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 25 May 2022 10:34:24 +0200 Subject: [PATCH 07/12] [admin]: add select2 to Goal form type entity fields --- src/Bundle/ChillPersonBundle/Form/SocialWork/GoalType.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Form/SocialWork/GoalType.php b/src/Bundle/ChillPersonBundle/Form/SocialWork/GoalType.php index 45a43897d..5fc77b410 100644 --- a/src/Bundle/ChillPersonBundle/Form/SocialWork/GoalType.php +++ b/src/Bundle/ChillPersonBundle/Form/SocialWork/GoalType.php @@ -51,6 +51,7 @@ class GoalType extends AbstractType 'choice_label' => function (SocialAction $issue) { return $this->translatableStringHelper->localize($issue->getTitle()); }, + 'attr' => ['class' => 'select2 '], ]) ->add('results', EntityType::class, [ @@ -60,6 +61,7 @@ class GoalType extends AbstractType 'choice_label' => function (Result $r) { return $this->translatableStringHelper->localize($r->getTitle()); }, + 'attr' => ['class' => 'select2 '], ]) ->add('desactivationDate', ChillDateType::class, [ From 4402d52de76815bf2d00c87060f7a3939e84053b Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 25 May 2022 10:35:15 +0200 Subject: [PATCH 08/12] upd CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 509682ed1..8432912a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [admin]: add select2 to Goal form type entity fields (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/702) * [main] allow hide permissions group list menu (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/577) * [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) From 5ebaeeb4ba0540ae9e1b3eccfe33afec51149a09 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 25 May 2022 10:38:09 +0200 Subject: [PATCH 09/12] php cs fix --- src/Bundle/ChillMainBundle/Controller/UserController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index 64a40cdda..4eb22c5d3 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -159,7 +159,6 @@ class UserController extends CRUDController return $this->redirect($this->generateUrl('chill_crud_admin_user_edit', ['id' => $uid])); } - public function edit(Request $request, $id): Response { $action = 'edit'; From 7278a5f3faa730ee0d15b3069404197e31ff0a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 May 2022 16:24:55 +0200 Subject: [PATCH 10/12] fix strict typing and do not show link to edit password in user list --- phpstan-deprecations.neon | 5 ----- src/Bundle/ChillMainBundle/Controller/UserController.php | 5 +++++ src/Bundle/ChillMainBundle/Form/UserType.php | 1 + .../ChillMainBundle/Resources/views/User/index.html.twig | 4 ++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/phpstan-deprecations.neon b/phpstan-deprecations.neon index 2de8b8bc8..42981a551 100644 --- a/phpstan-deprecations.neon +++ b/phpstan-deprecations.neon @@ -471,11 +471,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Form/Type/UserPickerType.php - - - message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Form/UserType.php - - message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" count: 2 diff --git a/src/Bundle/ChillMainBundle/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index 4eb22c5d3..b6ded6653 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -344,6 +344,11 @@ class UserController extends CRUDController ), ] ); + } elseif ('index' === $action) { + return array_merge( + ['allow_change_password' => $this->parameterBag->get('chill_main.access_user_change_password')], + $defaultTemplateParameters + ); } // default behaviour diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index 9e7da7a89..34c49bc38 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -112,6 +112,7 @@ class UserType extends AbstractType }, ]); + // @phpstan-ignore-next-line if ($options['is_creation'] && $this->parameterBag->get('chill_main.access_user_change_password')) { $builder->add('plainPassword', RepeatedType::class, [ 'mapped' => false, diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig index 1d254abb9..ec93cf8a7 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig @@ -50,9 +50,13 @@
  • + + {% if allow_change_password is same as(true) %}
  • + {% endif %} + {% if is_granted('ROLE_ALLOWED_TO_SWITCH') %}
  • From 3c8b2207c4b021566aed12b27a7a0d59d7004118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 May 2022 16:34:14 +0200 Subject: [PATCH 11/12] add civility in user docgen normalizer --- .../Serializer/Normalizer/UserNormalizer.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php index 365433ef3..eba8fc7bc 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Serializer\Normalizer; use Chill\MainBundle\Entity\Center; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; @@ -60,9 +61,14 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware $context, ['docgen:expects' => Location::class, 'groups' => 'docgen:read'] ); + $civilityContext = array_merge( + $context, + ['docgen:expects' => Civility::class, 'groups' => 'docgen:read'] + ); if (null === $user && 'docgen' === $format) { return array_merge(self::NULL_USER, [ + 'civility' => $this->normalizer->normalize(null, $format, $civilityContext), 'user_job' => $this->normalizer->normalize(null, $format, $userJobContext), 'main_center' => $this->normalizer->normalize(null, $format, $centerContext), 'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext), @@ -84,6 +90,7 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware ]; if ('docgen' === $format) { + $data['civility'] = $this->normalizer->normalize($user->getCivility(), $format, $civilityContext); $data['current_location'] = $this->normalizer->normalize($user->getCurrentLocation(), $format, $locationContext); $data['main_location'] = $this->normalizer->normalize($user->getMainLocation(), $format, $locationContext); } From 9680f7c01e6b90af2af9cb1838dc739a40830506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 May 2022 16:34:30 +0200 Subject: [PATCH 12/12] remove deprecated notation for getting entity --- .../Service/DocGenerator/AccompanyingPeriodContext.php | 3 ++- .../ChillPersonBundle/Service/DocGenerator/PersonContext.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index dc6e9c912..d3400034b 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -17,6 +17,7 @@ use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Service\Context\BaseContextData; use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument; +use Chill\DocStoreBundle\Entity\DocumentCategory; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Repository\DocumentCategoryRepository; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; @@ -132,7 +133,7 @@ class AccompanyingPeriodContext implements ]) ->add('category', EntityType::class, [ 'placeholder' => 'Choose a document category', - 'class' => 'ChillDocStoreBundle:DocumentCategory', + 'class' => DocumentCategory::class, 'query_builder' => static function (EntityRepository $er) { return $er->createQueryBuilder('c') ->where('c.documentClass = :docClass') diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php index 1561f0735..231e674b2 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -15,6 +15,7 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface; use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Service\Context\BaseContextData; +use Chill\DocStoreBundle\Entity\DocumentCategory; use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Repository\DocumentCategoryRepository; @@ -92,7 +93,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface $builder ->add('category', EntityType::class, [ 'placeholder' => 'Choose a document category', - 'class' => 'ChillDocStoreBundle:DocumentCategory', + 'class' => DocumentCategory::class, 'query_builder' => static function (EntityRepository $er) { return $er->createQueryBuilder('c') ->where('c.documentClass = :docClass')