diff --git a/CHANGELOG.md b/CHANGELOG.md index de2a62a0c..eed759261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ 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) +* [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/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 068bd9f73..b6ded6653 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; @@ -37,6 +38,8 @@ class UserController extends CRUDController { public const FORM_GROUP_CENTER_COMPOSED = 'composed_groupcenter'; + protected ParameterBagInterface $parameterBag; + private LoggerInterface $logger; private UserPasswordEncoderInterface $passwordEncoder; @@ -49,12 +52,14 @@ class UserController extends CRUDController 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; } /** @@ -104,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( @@ -153,6 +159,73 @@ 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. * @@ -271,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 @@ -307,7 +385,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/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 0611b9848..929bffe14 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -129,6 +129,16 @@ 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.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 7ced6aac6..a9b3ffec0 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -116,6 +116,12 @@ class Configuration implements ConfigurationInterface ->booleanNode('access_global_history') ->defaultTrue() ->end() + ->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/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..34c49bc38 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -15,9 +15,11 @@ 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; +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; @@ -32,11 +34,16 @@ use Symfony\Component\Validator\Constraints\Regex; class UserType extends AbstractType { + protected ParameterBagInterface $parameterBag; + private TranslatableStringHelper $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper) - { + public function __construct( + TranslatableStringHelper $translatableStringHelper, + ParameterBagInterface $parameterBag + ) { $this->translatableStringHelper = $translatableStringHelper; + $this->parameterBag = $parameterBag; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -47,6 +54,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, @@ -76,6 +88,12 @@ 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', @@ -94,7 +112,8 @@ class UserType extends AbstractType }, ]); - if ($options['is_creation']) { + // @phpstan-ignore-next-line + if ($options['is_creation'] && $this->parameterBag->get('chill_main.access_user_change_password')) { $builder->add('plainPassword', RepeatedType::class, [ 'mapped' => false, 'type' => PasswordType::class, 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 %} -
{{ 'Permission group'|trans }} | -{{ 'Center'|trans }} | -- |
---|
- | - -- - {{ 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 }} | +
---|
{{ 'Any permissions granted to this user'|trans }}.
+ + + {% for groupcenter in entity.groupcenters %} +{{ 'Any permissions granted to this user'|trans }}.
+ {% endif %} + +