mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
use a PickPersonDynamic type in event bundle
This commit is contained in:
parent
f11f7498d7
commit
930a76cc66
@ -18,9 +18,9 @@ use Chill\EventBundle\Form\Type\PickEventType;
|
|||||||
use Chill\EventBundle\Security\Authorization\EventVoter;
|
use Chill\EventBundle\Security\Authorization\EventVoter;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Form\Type\PickPersonType;
|
use Chill\PersonBundle\Form\Type\PickPersonDynamicType;
|
||||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
||||||
@ -42,49 +42,18 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
/**
|
/**
|
||||||
* Class EventController.
|
* Class EventController.
|
||||||
*/
|
*/
|
||||||
class EventController extends AbstractController
|
final class EventController extends AbstractController
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var AuthorizationHelper
|
|
||||||
*/
|
|
||||||
protected $authorizationHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EventDispatcherInterface
|
|
||||||
*/
|
|
||||||
protected $eventDispatcher;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var FormFactoryInterface
|
|
||||||
*/
|
|
||||||
protected $formFactoryInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var PaginatorFactory
|
|
||||||
*/
|
|
||||||
protected $paginator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var TranslatorInterface
|
|
||||||
*/
|
|
||||||
protected $translator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EventController constructor.
|
* EventController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EventDispatcherInterface $eventDispatcher,
|
private readonly EventDispatcherInterface $eventDispatcher,
|
||||||
AuthorizationHelper $authorizationHelper,
|
private readonly AuthorizationHelperInterface $authorizationHelper,
|
||||||
FormFactoryInterface $formFactoryInterface,
|
private readonly FormFactoryInterface $formFactoryInterface,
|
||||||
TranslatorInterface $translator,
|
private readonly TranslatorInterface $translator,
|
||||||
PaginatorFactory $paginator
|
private readonly PaginatorFactory $paginator
|
||||||
) {
|
) {}
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
|
||||||
$this->formFactoryInterface = $formFactoryInterface;
|
|
||||||
$this->translator = $translator;
|
|
||||||
$this->paginator = $paginator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/event/{event_id}/delete", name="chill_event__event_delete", requirements={"event_id"="\d+"}, methods={"GET", "DELETE"})
|
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/event/{event_id}/delete", name="chill_event__event_delete", requirements={"event_id"="\d+"}, methods={"GET", "DELETE"})
|
||||||
@ -181,7 +150,7 @@ class EventController extends AbstractController
|
|||||||
|
|
||||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||||
|
|
||||||
$reachablesCircles = $this->authorizationHelper->getReachableCircles(
|
$reachablesCircles = $this->authorizationHelper->getReachableScopes(
|
||||||
$this->getUser(),
|
$this->getUser(),
|
||||||
EventVoter::SEE,
|
EventVoter::SEE,
|
||||||
$person->getCenter()
|
$person->getCenter()
|
||||||
@ -323,7 +292,7 @@ class EventController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(
|
$this->denyAccessUnlessGranted(
|
||||||
'CHILL_EVENT_SEE_DETAILS',
|
EventVoter::SEE_DETAILS,
|
||||||
$event,
|
$event,
|
||||||
'You are not allowed to see details on this event'
|
'You are not allowed to see details on this event'
|
||||||
);
|
);
|
||||||
@ -430,11 +399,9 @@ class EventController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function createAddParticipationByPersonForm(Event $event)
|
protected function createAddParticipationByPersonForm(Event $event)
|
||||||
{
|
{
|
||||||
/** @var \Symfony\Component\Form\FormBuilderInterface $builder */
|
$builder = $this->formFactoryInterface
|
||||||
$builder = $this
|
|
||||||
->get('form.factory')
|
|
||||||
->createNamedBuilder(
|
->createNamedBuilder(
|
||||||
null,
|
'',
|
||||||
FormType::class,
|
FormType::class,
|
||||||
null,
|
null,
|
||||||
[
|
[
|
||||||
@ -444,10 +411,7 @@ class EventController extends AbstractController
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$builder->add('person_id', PickPersonType::class, [
|
$builder->add('person_id', PickPersonDynamicType::class, ['as_id' => true, 'multiple' => false]);
|
||||||
'role' => 'CHILL_EVENT_CREATE',
|
|
||||||
'centers' => $event->getCenter(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$builder->add('event_id', HiddenType::class, [
|
$builder->add('event_id', HiddenType::class, [
|
||||||
'data' => $event->getId(),
|
'data' => $event->getId(),
|
||||||
@ -469,7 +433,7 @@ class EventController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function createExportByFormatForm()
|
protected function createExportByFormatForm()
|
||||||
{
|
{
|
||||||
$builder = $this->createFormBuilder()
|
$builder = $this->createFormBuilder(['format' => 'xlsx'])
|
||||||
->add('format', ChoiceType::class, [
|
->add('format', ChoiceType::class, [
|
||||||
'choices' => [
|
'choices' => [
|
||||||
'xlsx' => 'xlsx',
|
'xlsx' => 'xlsx',
|
||||||
|
@ -14,7 +14,10 @@ namespace Chill\EventBundle\Controller;
|
|||||||
use Chill\EventBundle\Entity\Event;
|
use Chill\EventBundle\Entity\Event;
|
||||||
use Chill\EventBundle\Entity\Participation;
|
use Chill\EventBundle\Entity\Participation;
|
||||||
use Chill\EventBundle\Form\ParticipationType;
|
use Chill\EventBundle\Form\ParticipationType;
|
||||||
|
use Chill\EventBundle\Repository\EventRepository;
|
||||||
use Chill\EventBundle\Security\Authorization\ParticipationVoter;
|
use Chill\EventBundle\Security\Authorization\ParticipationVoter;
|
||||||
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@ -28,14 +31,17 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
/**
|
/**
|
||||||
* Class ParticipationController.
|
* Class ParticipationController.
|
||||||
*/
|
*/
|
||||||
class ParticipationController extends AbstractController
|
final class ParticipationController extends AbstractController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* ParticipationController constructor.
|
* ParticipationController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(private readonly LoggerInterface $logger, private readonly TranslatorInterface $translator)
|
public function __construct(
|
||||||
{
|
private readonly LoggerInterface $logger,
|
||||||
}
|
private readonly TranslatorInterface $translator,
|
||||||
|
private readonly EventRepository $eventRepository,
|
||||||
|
private readonly PersonRepository $personRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/create", name="chill_event_participation_create")
|
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/create", name="chill_event_participation_create")
|
||||||
@ -321,7 +327,7 @@ class ParticipationController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function editMultipleAction($event_id): Response|\Symfony\Component\HttpFoundation\RedirectResponse
|
public function editMultipleAction($event_id): Response|\Symfony\Component\HttpFoundation\RedirectResponse
|
||||||
{
|
{
|
||||||
$event = $this->getDoctrine()->getRepository(Event::class)
|
$event = $this->getDoctrine()->getRepository(\Chill\EventBundle\Entity\Event::class)
|
||||||
->find($event_id);
|
->find($event_id);
|
||||||
|
|
||||||
if (null === $event) {
|
if (null === $event) {
|
||||||
@ -539,7 +545,7 @@ class ParticipationController extends AbstractController
|
|||||||
* If the request is multiple, the $participation object is cloned.
|
* If the request is multiple, the $participation object is cloned.
|
||||||
* Limitations: the $participation should not be persisted.
|
* Limitations: the $participation should not be persisted.
|
||||||
*
|
*
|
||||||
* @return Participation|Participation[] return one single participation if $multiple == false
|
* @return Participation|list<Participation> return one single participation if $multiple == false
|
||||||
*
|
*
|
||||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
|
||||||
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
|
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
|
||||||
@ -556,30 +562,25 @@ class ParticipationController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$event_id = $request->query->getInt('event_id', 0); // sf4 check:
|
$event_id = $request->query->getInt('event_id', 0); // sf4 check:
|
||||||
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
|
||||||
|
|
||||||
if (null !== $event_id) {
|
$event = $this->eventRepository->find($event_id);
|
||||||
$event = $em->getRepository(Event::class)
|
|
||||||
->find($event_id);
|
|
||||||
|
|
||||||
if (null === $event) {
|
if (null === $event) {
|
||||||
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
|
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
|
||||||
}
|
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(
|
|
||||||
'CHILL_EVENT_SEE',
|
|
||||||
$event,
|
|
||||||
'The user is not allowed to see the event'
|
|
||||||
);
|
|
||||||
|
|
||||||
$participation->setEvent($event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->denyAccessUnlessGranted(
|
||||||
|
'CHILL_EVENT_SEE',
|
||||||
|
$event,
|
||||||
|
'The user is not allowed to see the event'
|
||||||
|
);
|
||||||
|
|
||||||
|
$participation->setEvent($event);
|
||||||
|
|
||||||
// this script should be able to handle multiple, so we translate
|
// this script should be able to handle multiple, so we translate
|
||||||
// single person_id in an array
|
// single person_id in an array
|
||||||
$persons_ids = $request->query->has('person_id') ?
|
$persons_ids = $request->query->has('person_id') ?
|
||||||
[$request->query->getInt('person_id', 0)] // sf4 check:
|
[$request->query->get('person_id', 0)]
|
||||||
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
|
||||||
: explode(',', (string) $request->query->get('persons_ids'));
|
: explode(',', (string) $request->query->get('persons_ids'));
|
||||||
$participations = [];
|
$participations = [];
|
||||||
|
|
||||||
@ -588,15 +589,14 @@ class ParticipationController extends AbstractController
|
|||||||
$participation = \count($persons_ids) > 1 ? clone $participation : $participation;
|
$participation = \count($persons_ids) > 1 ? clone $participation : $participation;
|
||||||
|
|
||||||
if (null !== $person_id) {
|
if (null !== $person_id) {
|
||||||
$person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)
|
$person = $this->personRepository->find($person_id);
|
||||||
->find($person_id);
|
|
||||||
|
|
||||||
if (null === $person) {
|
if (null === $person) {
|
||||||
throw $this->createNotFoundException('The person with id '.$person_id.' is not found');
|
throw $this->createNotFoundException('The person with id '.$person_id.' is not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(
|
$this->denyAccessUnlessGranted(
|
||||||
'CHILL_PERSON_SEE',
|
PersonVoter::SEE,
|
||||||
$person,
|
$person,
|
||||||
'The user is not allowed to see the person'
|
'The user is not allowed to see the person'
|
||||||
);
|
);
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\EventBundle\DependencyInjection;
|
namespace Chill\EventBundle\DependencyInjection;
|
||||||
|
|
||||||
use Chill\EventBundle\Security\Authorization\EventVoter;
|
use Chill\EventBundle\Security\Authorization\EventVoter;
|
||||||
|
use Chill\EventBundle\Security\Authorization\ParticipationVoter;
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||||
@ -33,7 +34,6 @@ class ChillEventExtension extends Extension implements PrependExtensionInterface
|
|||||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
||||||
$loader->load('services.yaml');
|
$loader->load('services.yaml');
|
||||||
$loader->load('services/authorization.yaml');
|
$loader->load('services/authorization.yaml');
|
||||||
$loader->load('services/controller.yaml');
|
|
||||||
$loader->load('services/fixtures.yaml');
|
$loader->load('services/fixtures.yaml');
|
||||||
$loader->load('services/forms.yaml');
|
$loader->load('services/forms.yaml');
|
||||||
$loader->load('services/menu.yaml');
|
$loader->load('services/menu.yaml');
|
||||||
@ -61,6 +61,8 @@ class ChillEventExtension extends Extension implements PrependExtensionInterface
|
|||||||
EventVoter::SEE_DETAILS => [EventVoter::SEE],
|
EventVoter::SEE_DETAILS => [EventVoter::SEE],
|
||||||
EventVoter::UPDATE => [EventVoter::SEE_DETAILS],
|
EventVoter::UPDATE => [EventVoter::SEE_DETAILS],
|
||||||
EventVoter::CREATE => [EventVoter::SEE_DETAILS],
|
EventVoter::CREATE => [EventVoter::SEE_DETAILS],
|
||||||
|
ParticipationVoter::SEE_DETAILS => [ParticipationVoter::SEE],
|
||||||
|
ParticipationVoter::UPDATE => [ParticipationVoter::SEE_DETAILS],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,16 @@
|
|||||||
|
|
||||||
{% import '@ChillPerson/Person/macro.html.twig' as person_macro %}
|
{% import '@ChillPerson/Person/macro.html.twig' as person_macro %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{{ parent() }}
|
||||||
|
{{ encore_entry_script_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
{{ parent() }}
|
||||||
|
{{ encore_entry_link_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block event_content -%}
|
{% block event_content -%}
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<h1>{{ 'Details of an event'|trans }}</h1>
|
<h1>{{ 'Details of an event'|trans }}</h1>
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
services:
|
|
||||||
|
|
||||||
Chill\EventBundle\Controller\EventController:
|
|
||||||
arguments:
|
|
||||||
$eventDispatcher: '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface'
|
|
||||||
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
|
||||||
$formFactoryInterface: '@Symfony\Component\Form\FormFactoryInterface'
|
|
||||||
$translator: '@Symfony\Contracts\Translation\TranslatorInterface'
|
|
||||||
$paginator: '@chill_main.paginator_factory'
|
|
||||||
public: true
|
|
||||||
tags: ['controller.service_arguments']
|
|
||||||
|
|
||||||
Chill\EventBundle\Controller\ParticipationController:
|
|
||||||
arguments:
|
|
||||||
$logger: '@Psr\Log\LoggerInterface'
|
|
||||||
tags: ['controller.service_arguments']
|
|
Loading…
x
Reference in New Issue
Block a user