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