From 74be6460d4b9c7fc7549045249db6394c95720a6 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 17 Jul 2024 13:05:14 +0200 Subject: [PATCH] Fix delete request for all entities --- .../ChillActivityBundle/Controller/ActivityController.php | 5 ++--- .../Controller/AbstractElementController.php | 5 ++--- .../ChillCalendarBundle/Controller/CalendarController.php | 3 +-- .../ChillEventBundle/Controller/EventController.php | 7 +++---- .../ChillEventBundle/Controller/EventTypeController.php | 3 +-- .../Controller/ParticipationController.php | 5 ++--- src/Bundle/ChillEventBundle/Controller/RoleController.php | 2 +- .../Controller/AccompanyingCourseWorkController.php | 5 ++--- .../Controller/HouseholdCompositionController.php | 3 +-- .../Controller/PersonResourceController.php | 5 ++--- .../ChillTaskBundle/Controller/SingleTaskController.php | 8 +++----- 11 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 2248c54d3..cbfb93400 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -99,10 +99,10 @@ final class ActivityController extends AbstractController $form = $this->createDeleteForm($activity->getId(), $person, $accompanyingPeriod); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->logger->notice('An activity has been removed', [ 'by_user' => $this->getUser()->getUsername(), 'activity_id' => $activity->getId(), @@ -640,7 +640,6 @@ final class ActivityController extends AbstractController return $this->createFormBuilder() ->setAction($this->generateUrl('chill_activity_activity_delete', $params)) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); } diff --git a/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php b/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php index d293907f5..bb204c557 100644 --- a/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php +++ b/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php @@ -54,7 +54,7 @@ abstract class AbstractElementController extends AbstractController $indexPage = 'chill_budget_elements_household_index'; } - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -198,10 +198,9 @@ abstract class AbstractElementController extends AbstractController /** * Creates a form to delete a help request entity by id. */ - private function createDeleteForm(): Form + private function createDeleteForm(): \Symfony\Component\Form\FormInterface { return $this->createFormBuilder() - ->setMethod(Request::METHOD_DELETE) ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); } diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 328b8788f..e57d2743d 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -84,7 +84,7 @@ class CalendarController extends AbstractController $form = $this->createDeleteForm($entity); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { @@ -512,7 +512,6 @@ class CalendarController extends AbstractController { return $this->createFormBuilder() ->setAction($this->generateUrl('chill_calendar_calendar_delete', ['id' => $calendar->getId()])) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); } diff --git a/src/Bundle/ChillEventBundle/Controller/EventController.php b/src/Bundle/ChillEventBundle/Controller/EventController.php index 7a28e51f2..773593057 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventController.php @@ -61,7 +61,7 @@ final class EventController extends AbstractController private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} - #[\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', 'POST', 'DELETE'])] public function deleteAction($event_id, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|Response { $em = $this->managerRegistry->getManager(); @@ -78,10 +78,10 @@ final class EventController extends AbstractController $form = $this->createDeleteForm($event_id); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { foreach ($participations as $participation) { $em->remove($participation); } @@ -599,7 +599,6 @@ final class EventController extends AbstractController ->setAction($this->generateUrl('chill_event__event_delete', [ 'event_id' => $event_id, ])) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); } diff --git a/src/Bundle/ChillEventBundle/Controller/EventTypeController.php b/src/Bundle/ChillEventBundle/Controller/EventTypeController.php index 5706dbe19..f7b1b205c 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventTypeController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventTypeController.php @@ -201,7 +201,7 @@ class EventTypeController extends AbstractController /** * Creates a form to delete a EventType entity by id. * - * @return \Symfony\Component\Form\Form The form + * @return \Symfony\Component\Form\FormInterface The form */ private function createDeleteForm(mixed $id) { @@ -210,7 +210,6 @@ class EventTypeController extends AbstractController 'chill_eventtype_admin_delete', ['id' => $id] )) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); } diff --git a/src/Bundle/ChillEventBundle/Controller/ParticipationController.php b/src/Bundle/ChillEventBundle/Controller/ParticipationController.php index a8b72dfd4..59501acd7 100644 --- a/src/Bundle/ChillEventBundle/Controller/ParticipationController.php +++ b/src/Bundle/ChillEventBundle/Controller/ParticipationController.php @@ -259,10 +259,10 @@ final class ParticipationController extends AbstractController $form = $this->createDeleteForm($participation_id); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $em->remove($participation); $em->flush(); @@ -753,7 +753,6 @@ final class ParticipationController extends AbstractController ->setAction($this->generateUrl('chill_event_participation_delete', [ 'participation_id' => $participation_id, ])) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); } diff --git a/src/Bundle/ChillEventBundle/Controller/RoleController.php b/src/Bundle/ChillEventBundle/Controller/RoleController.php index 24e4f2121..1ff205dfc 100644 --- a/src/Bundle/ChillEventBundle/Controller/RoleController.php +++ b/src/Bundle/ChillEventBundle/Controller/RoleController.php @@ -201,7 +201,7 @@ class RoleController extends AbstractController /** * Creates a form to delete a Role entity by id. * - * @return \Symfony\Component\Form\Form The form + * @return \Symfony\Component\Form\FormInterface The form */ private function createDeleteForm(mixed $id) { diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php index e206a6538..0243d55b5 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php @@ -80,10 +80,10 @@ final class AccompanyingCourseWorkController extends AbstractController $form = $this->createDeleteForm($work->getId()); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->chillLogger->notice('An accompanying period work has been removed', [ 'by_user' => $this->getUser()->getUsername(), 'work_id' => $work->getId(), @@ -179,7 +179,6 @@ final class AccompanyingCourseWorkController extends AbstractController return $this->createFormBuilder() ->setAction($this->generateUrl('chill_person_accompanying_period_work_delete', $params)) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); } diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php index 0da3688f9..d9583c8d8 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdCompositionController.php @@ -63,11 +63,10 @@ class HouseholdCompositionController extends AbstractController 'composition_id' => $composition_id, 'household_id' => $household_id, ])) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php index 079830cf7..8332d468e 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php @@ -44,14 +44,13 @@ final class PersonResourceController extends AbstractController 'resource_id' => $resource_id, 'person_id' => $person_id, ])) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->em->remove($resource); $this->em->flush(); diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index 2c6234eb0..0c3b8a7ba 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -62,7 +62,7 @@ final class SingleTaskController extends AbstractController private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, ) {} - #[Route(path: '/{_locale}/task/single-task/{id}/delete', name: 'chill_task_single_task_delete')] + #[Route(path: '/{_locale}/task/single-task/{id}/delete', name: 'chill_task_single_task_delete', methods: ['GET', 'POST', 'DELETE'])] public function deleteAction(Request $request, mixed $id) { $course = null; @@ -110,10 +110,9 @@ final class SingleTaskController extends AbstractController $form = $this->createDeleteForm($id); - if (Request::METHOD_DELETE === $request->getMethod()) { + if (Request::METHOD_POST === $request->getMethod()) { $form->handleRequest($request); - - if ($form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->logger->notice('A task has been removed', [ 'by_user' => $this->getUser()->getUsername(), 'task_id' => $task->getId(), @@ -660,7 +659,6 @@ final class SingleTaskController extends AbstractController 'chill_task_single_task_delete', ['id' => $id] )) - ->setMethod('DELETE') ->add('submit', SubmitType::class, ['label' => 'Delete']) ->getForm(); }