Merge branch 'master' into upgrade-sf5

This commit is contained in:
2024-02-12 21:50:34 +01:00
920 changed files with 6430 additions and 1914 deletions

View File

@@ -17,10 +17,11 @@ use Chill\EventBundle\Form\EventType;
use Chill\EventBundle\Form\Type\PickEventType;
use Chill\EventBundle\Security\Authorization\EventVoter;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\User;
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\Form\Type\PickPersonType;
use Chill\PersonBundle\Form\Type\PickPersonDynamicType;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Csv;
@@ -37,38 +38,15 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* 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.
*/
@@ -80,11 +58,6 @@ class EventController extends AbstractController
PaginatorFactory $paginator,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry
) {
$this->eventDispatcher = $eventDispatcher;
$this->authorizationHelper = $authorizationHelper;
$this->formFactoryInterface = $formFactoryInterface;
$this->translator = $translator;
$this->paginator = $paginator;
}
/**
@@ -182,7 +155,7 @@ class EventController extends AbstractController
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$reachablesCircles = $this->authorizationHelper->getReachableCircles(
$reachablesCircles = $this->authorizationHelper->getReachableScopes(
$this->getUser(),
EventVoter::SEE,
$person->getCenter()
@@ -234,6 +207,12 @@ class EventController extends AbstractController
*/
public function newAction(?Center $center, Request $request)
{
$user = $this->security->getUser();
if (!$user instanceof User) {
throw new AccessDeniedHttpException('not a regular user. Maybe an administrator ?');
}
if (null === $center) {
$center_id = $request->query->get('center_id');
$center = $this->managerRegistry->getRepository(Center::class)->find($center_id);
@@ -241,6 +220,7 @@ class EventController extends AbstractController
$entity = new Event();
$entity->setCenter($center);
$entity->setLocation($user->getCurrentLocation());
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
@@ -283,7 +263,7 @@ class EventController extends AbstractController
}
$form = $this->formFactoryInterface
->createNamedBuilder(null, FormType::class, null, [
->createNamedBuilder('', FormType::class, null, [
'csrf_protection' => false,
])
->setMethod('GET')
@@ -324,7 +304,7 @@ class EventController extends AbstractController
}
$this->denyAccessUnlessGranted(
'CHILL_EVENT_SEE_DETAILS',
EventVoter::SEE_DETAILS,
$event,
'You are not allowed to see details on this event'
);
@@ -368,7 +348,7 @@ class EventController extends AbstractController
$this->addFlash('success', $this->translator
->trans('The event was updated'));
return $this->redirectToRoute('chill_event__event_edit', ['event_id' => $event_id]);
return $this->redirectToRoute('chill_event__event_show', ['event_id' => $event_id]);
}
return $this->render('@ChillEvent/Event/edit.html.twig', [
@@ -386,7 +366,7 @@ class EventController extends AbstractController
{
/** @var \Symfony\Component\Form\FormBuilderInterface $builder */
$builder = $this
->get('form.factory')
->formFactoryInterface
->createNamedBuilder(
null,
FormType::class,
@@ -431,11 +411,9 @@ class EventController extends AbstractController
*/
protected function createAddParticipationByPersonForm(Event $event)
{
/** @var \Symfony\Component\Form\FormBuilderInterface $builder */
$builder = $this
->get('form.factory')
$builder = $this->formFactoryInterface
->createNamedBuilder(
null,
'',
FormType::class,
null,
[
@@ -445,23 +423,17 @@ class EventController extends AbstractController
]
);
$builder->add('person_id', PickPersonType::class, [
'role' => 'CHILL_EVENT_CREATE',
'centers' => $event->getCenter(),
$builder->add('person_id', PickPersonDynamicType::class, [
'as_id' => true,
'multiple' => false,
'submit_on_adding_new_entity' => true,
'label' => 'Add a participation',
]);
$builder->add('event_id', HiddenType::class, [
'data' => $event->getId(),
]);
$builder->add(
'submit',
SubmitType::class,
[
'label' => 'Add a participation',
]
);
return $builder->getForm();
}
@@ -470,7 +442,7 @@ class EventController extends AbstractController
*/
protected function createExportByFormatForm()
{
$builder = $this->createFormBuilder()
$builder = $this->createFormBuilder(['format' => 'xlsx'])
->add('format', ChoiceType::class, [
'choices' => [
'xlsx' => 'xlsx',