diff --git a/.env b/.env index 2418586..0106286 100644 --- a/.env +++ b/.env @@ -1,6 +1,7 @@ APP_ENV=prod DEFAULT_LOCALE=en APP_SECRET=e80d9c53871bdaa0a1ff5357c695ba6d +TZ=America/New_York ###> symfony/lock ### # Choose one of the stores below # postgresql+advisory://db_user:db_password@localhost/db_name diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 7a139ee..5501d82 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -2,7 +2,7 @@ twig: default_path: '%kernel.project_dir%/templates' form_themes: ['form_layout.html.twig'] date: - timezone: Europe/Paris + timezone: '%env(TZ)%' when@test: twig: diff --git a/package.json b/package.json index 3c5c6ef..0f0a0d9 100644 --- a/package.json +++ b/package.json @@ -1,3 +1,3 @@ { - "version": "0.1.2" + "version": "0.1.3" } diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index e688c6b..da70ea4 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -70,23 +70,34 @@ class AdminController extends AbstractController //-- users #[Route('/user', name: 'user_list')] + #[Route('/user/admin', name: 'user_list_admin')] + #[Route('/user/desactivated', name: 'user_list_desactivated')] public function user(PaginatorInterface $paginator, Request $request, UserRepository $UserRepository): Response { $searchForm = $this->createForm(SearchBarType::class); $searchForm->handleRequest($request); + $req = $UserRepository->getAll() + ->search( + ( + $searchForm->isSubmitted() + && $searchForm->isValid() + && $searchForm->getData()['subject'] !== null + ) ? $searchForm->getData()['subject'] : null, + true + ); + + if ($request->attributes->get('_route') == 'admin_user_list_admin') { + $req->onlyRole('ADMIN'); + } + + if ($request->attributes->get('_route') == 'admin_user_list_desactivated') { + $req->onlyDesactivated(); + } + $pagination = $paginator->paginate( - $UserRepository->getAll() - ->search( - ( - $searchForm->isSubmitted() - && $searchForm->isValid() - && $searchForm->getData()['subject'] !== null - ) ? $searchForm->getData()['subject'] : null, - true - ) - ->getResult(), + $req->getResult(), $request->query->getInt('page', 1) ); @@ -94,6 +105,8 @@ class AdminController extends AbstractController 'controller_name' => 'AdminController', 'searchForm' => $searchForm->createView(), 'pagination' => $pagination, + 'admin' => ($request->attributes->get('_route') == 'admin_user_list_admin'), + 'desactivated' => ($request->attributes->get('_route') == 'admin_user_list_desactivated') ]); } diff --git a/src/Controller/DocumentController.php b/src/Controller/DocumentController.php index 61d4937..9579662 100644 --- a/src/Controller/DocumentController.php +++ b/src/Controller/DocumentController.php @@ -3,7 +3,6 @@ namespace App\Controller; use App\Entity\User; -use App\Form\TestType; use App\Entity\Comment; use App\Entity\Document; use App\Entity\Directory; diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index f89c9bc..2612173 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -18,7 +18,12 @@ class GroupController extends AbstractController #[Route('/', name: 'index')] public function index(Request $request, TemplateRepository $TemplateRepository): Response { - $group = $this->getUser()->getMainGroup(); + + /** + * @var User $currentUser + */ + $currentUser = $this->getUser(); + $group = $currentUser->getMainGroup(); if (!$this->IsGranted('administrate', $group)) { throw new AccessDeniedHttpException('granted_not_allowed_administrate_group'); } @@ -49,7 +54,7 @@ class GroupController extends AbstractController 'controller_name' => 'GroupController', 'formMOTD' => $form->createView(), 'group' => $group, - 'templates' => $TemplateRepository->listForUser($this->getUser())->getResult() + 'templates' => $TemplateRepository->listForUser($currentUser)->getResult() ]); } @@ -57,16 +62,16 @@ class GroupController extends AbstractController public function fire(User $User, Request $Request): Response { - $group = $this->getUser()->getMainGroup(); - if (!$this->IsGranted('fire', $group)) { - throw new AccessDeniedHttpException('granted_not_allowed_fire_employee'); - } - - /** * @var User $currentUser */ $currentUser = $this->getUser(); + + $group = $currentUser->getMainGroup(); + if (!$this->IsGranted('fire', $group)) { + throw new AccessDeniedHttpException('granted_not_allowed_fire_employee'); + } + if ( $User->getMainRank()->getPower() >= $currentUser->getMainRank()->getPower() && !$currentUser->getAdminMode() @@ -101,14 +106,19 @@ class GroupController extends AbstractController #[Route('/employee/{id}', name: 'employee')] public function employee(User $Employee, Request $Request): Response { - $group = $this->getUser()->getMainGroup(); + /** + * @var User $currentUser + */ + $currentUser = $this->getUser(); + + $group = $currentUser->getMainGroup(); if (!$this->IsGranted('administrate', $group)) { throw new AccessDeniedHttpException('granted_not_allowed_administrate_group'); } //check if employee belong to user group - if ($Employee->getMainGroup() != $this->getUser()->getMainGroup()) { + if ($Employee->getMainGroup() != $currentUser->getMainGroup()) { throw new AccessDeniedHttpException('granted_not_allowed_administrate_other_group_employee'); } diff --git a/src/Entity/Group.php b/src/Entity/Group.php index 8f33cab..23e6827 100644 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -231,6 +231,16 @@ class Group return $this->users; } + /** + * @return Collection|User[] + */ + public function getUsersActive(): Collection + { + return $this->users->filter(function (User $user) { + return !$user->getIsDesactivated(); + }); + } + public function addUser(User $user): self { if (!$this->users->contains($user)) { diff --git a/src/Form/BraceletType.php b/src/Form/BraceletType.php index 362a61f..dfae653 100644 --- a/src/Form/BraceletType.php +++ b/src/Form/BraceletType.php @@ -3,6 +3,8 @@ namespace App\Form; use App\Entity\Bracelet; +use App\Form\DocumentType; +use App\Form\Type\DateTimeVisionType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -12,7 +14,7 @@ class BraceletType extends DocumentType { parent::buildForm($builder, $options); $builder - ->add('removingDate', null, ['label' => 'form_label_removing_date']) + ->add('removingDate', DateTimeVisionType::class, ['label' => 'form_label_removing_date']) ; } diff --git a/src/Form/JailType.php b/src/Form/JailType.php index 07d8e4b..7fea41c 100644 --- a/src/Form/JailType.php +++ b/src/Form/JailType.php @@ -5,6 +5,7 @@ namespace App\Form; use App\Entity\Jail; use App\Form\DocumentType; use App\Form\Type\ContentType; +use App\Form\Type\DateTimeVisionType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -16,8 +17,16 @@ class JailType extends DocumentType parent::buildForm($builder, $options); $builder - ->add('arrestedAt', null, ['label' => 'form_label_arrested_at', 'help' => 'form_help_arrested_at']) - ->add('jailedAt', null, ['label' => 'form_label_jailed_at', 'help' => 'form_help_jailed_at']) + ->add( + 'arrestedAt', + DateTimeVisionType::class, + ['label' => 'form_label_arrested_at', 'help' => 'form_help_arrested_at'] + ) + ->add( + 'jailedAt', + DateTimeVisionType::class, + ['label' => 'form_label_jailed_at', 'help' => 'form_help_jailed_at'] + ) ->add('lawyer', CheckboxType::class, ['label' => 'form_label_asked_for_lawyer', 'required' => false]) ->add('medic', CheckboxType::class, ['label' => 'form_label_asked_for_medic', 'required' => false]) ->add('content', ContentType::class) diff --git a/src/Form/LicenceWithdrawalType.php b/src/Form/LicenceWithdrawalType.php index b730baa..a4a7594 100644 --- a/src/Form/LicenceWithdrawalType.php +++ b/src/Form/LicenceWithdrawalType.php @@ -5,6 +5,7 @@ namespace App\Form; use App\Form\DocumentType; use App\Form\Type\VehicleType; use App\Entity\LicenceWithdrawal; +use App\Form\Type\DateTimeVisionType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -18,7 +19,7 @@ class LicenceWithdrawalType extends DocumentType $builder ->add('type', VehicleType::class) - ->add('until', null, ['label' => 'form_label_until', 'help' => 'form_help_until']) + ->add('until', DateTimeVisionType::class, ['label' => 'form_label_until', 'help' => 'form_help_until']) ; } diff --git a/src/Form/TestType.php b/src/Form/TestType.php deleted file mode 100644 index e51431a..0000000 --- a/src/Form/TestType.php +++ /dev/null @@ -1,58 +0,0 @@ -TokenStorage = $TokenStorage; - } - - public function buildForm(FormBuilderInterface $builder, array $options): void - { - /** - * @var User $user - */ - $User = $this->TokenStorage->getToken()->getUser(); - - $builder - ->add('title', null, [ - 'label' => 'form_label_title', - 'priority' => 999 - ]); - - $builder - ->add( - 'allowShare', - null, - [ - 'priority' => -900, - 'label' => 'form_label_allowShare' - ] - ) - ->add('submit', SubmitType::class, [ - 'label' => 'form_button_submit', - 'priority' => -900, - 'attr' => ['class' => 'btn-primary'], - ]) - ; - } - - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'data_class' => Document::class, - ]); - } -} diff --git a/src/Form/Type/DateTimeVisionType.php b/src/Form/Type/DateTimeVisionType.php new file mode 100644 index 0000000..6aa4566 --- /dev/null +++ b/src/Form/Type/DateTimeVisionType.php @@ -0,0 +1,23 @@ +setDefaults([ + 'view_timezone' => array_key_exists('TZ', $_ENV) ? $_ENV['TZ'] : false + ]); + } + + public function getParent(): string + { + return DateTimeType::class; + } +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index b3f3889..ed95b08 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -79,6 +79,25 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader return $this; } + public function onlyRole(string $role) + { + $this->qb->andWhere('u.roles LIKE :role') + ->setParameter('role', '%ROLE_' . strtoupper($role) . '%'); + return $this; + } + + public function onlyActive() + { + $this->qb->andWhere('u.isDesactivated = 0'); + return $this; + } + + public function onlyDesactivated() + { + $this->qb->andWhere('u.isDesactivated = 1'); + return $this; + } + public function search(?string $search, bool $adminmode = false) { if (null === $search) { diff --git a/src/Security/Voter/Tools/VoterInterface.php b/src/Security/Voter/Tools/VoterInterface.php index d410e90..68b057a 100644 --- a/src/Security/Voter/Tools/VoterInterface.php +++ b/src/Security/Voter/Tools/VoterInterface.php @@ -3,20 +3,17 @@ namespace App\Security\Voter\Tools; use App\Entity\User; -use Psr\Log\LoggerInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; abstract class VoterInterface extends Voter { - private LoggerInterface $logger; public User $user; public array $userpermissions; public ?string $permissionsPrefix; - public function __construct(LoggerInterface $logger) + public function __construct() { - $this->logger = $logger; $this->setPermissionsPrefix(null); } diff --git a/templates/_cells/directoryCard.html.twig b/templates/_cells/directoryCard.html.twig index 65a7234..d18188b 100644 --- a/templates/_cells/directoryCard.html.twig +++ b/templates/_cells/directoryCard.html.twig @@ -1,5 +1,5 @@
{% trans %}title_directory_dead{% endtrans %}
{% endif %} {% if directory.wanted %}{% trans %}title_directory_wanted{% endtrans %}
{% endif %} @@ -25,29 +25,29 @@ {% if directory.idCardImageSize != 0 %} {% endif %} - {% if app.user.hasPermission('general_legal_view') %} + {% if app.user and app.user.hasPermission('general_legal_view') %} {% if directory.carLicenceImageSize != 0 %} - + {% endif %} {% if directory.motorcycleLicenceImageSize != 0 %} - + {% endif %} {% if directory.truckLicenceImageSize != 0 %} - + {% endif %} {% if directory.boatLicenceImageSize != 0 %} - + {% endif %} {% endif %}