fix: build form properly based on current user's role
This commit is contained in:
@@ -34,7 +34,6 @@ class AssignmentFilterController extends AbstractController
|
||||
'max_date' => $filterOptions['maxDate'],
|
||||
'job_profiles' => $filterOptions['jobProfiles'],
|
||||
'hotels' => $filterOptions['hotels'],
|
||||
'user' => $this->getUser(),
|
||||
];
|
||||
|
||||
$form = $this->createForm(AssignmentFilterType::class, $formData, $formOptions);
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Entity\JobProfile;
|
||||
use App\Entity\User;
|
||||
use App\Model\AssignmentFilterDto;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
@@ -16,6 +17,10 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AssignmentFilterType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
@@ -54,9 +59,7 @@ class AssignmentFilterType extends AbstractType
|
||||
])
|
||||
;
|
||||
|
||||
/** @var User $user */
|
||||
$user = $options['user'];
|
||||
if ($user->hasRole('ROLE_ADMINISTRATIVE')) {
|
||||
if ($this->security->isGranted('ROLE_ADMINISTRATIVE')) {
|
||||
$builder->add('status', ChoiceType::class, [
|
||||
'label' => 'Status',
|
||||
'required' => false,
|
||||
@@ -107,10 +110,8 @@ class AssignmentFilterType extends AbstractType
|
||||
'job_profiles' => [],
|
||||
'hotels' => [],
|
||||
])
|
||||
->setRequired(['user'])
|
||||
->setAllowedTypes('min_date', [\DateTimeImmutable::class, 'null'])
|
||||
->setAllowedTypes('max_date', [\DateTimeImmutable::class, 'null'])
|
||||
->setAllowedTypes('user', User::class)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
{{ form_start(filterForm, { 'attr': { 'hx-post': app.request.uri, 'hx-target': '#htmx-modal', 'hx-swap': 'outerHTML' } }) }}
|
||||
<div class="flex flex-col space-y-2 pb-4">
|
||||
{% if form.status is defined %}
|
||||
{% if filterForm.status is defined %}
|
||||
{{ form_row(filterForm.status) }}
|
||||
{% endif %}
|
||||
{{ form_row(filterForm.dateFrom) }}
|
||||
|
||||
Reference in New Issue
Block a user