Fix and Enhancements
This commit is contained in:
@@ -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')
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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'])
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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'])
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Document;
|
||||
use App\Entity\User;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
class TestType extends AbstractType
|
||||
{
|
||||
private TokenStorageInterface $TokenStorage;
|
||||
|
||||
public function __construct(TokenStorageInterface $TokenStorage)
|
||||
{
|
||||
$this->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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
23
src/Form/Type/DateTimeVisionType.php
Normal file
23
src/Form/Type/DateTimeVisionType.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
|
||||
class DateTimeVisionType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
|
||||
$resolver->setDefaults([
|
||||
'view_timezone' => array_key_exists('TZ', $_ENV) ? $_ENV['TZ'] : false
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return DateTimeType::class;
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user