From 69553fb1b34f9973cf30db37d43f310e8a8d6a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 29 Oct 2024 17:34:52 +0100 Subject: [PATCH] feat: keep rejected applications visible, enable deletion for admins --- .../Admin/Application/DeleteController.php | 28 ++++++++++++------- src/Repository/ApplicationRepository.php | 6 +--- src/Security/Voter/ApplicationVoter.php | 4 +-- .../admin/application/modal_delete.html.twig | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Controller/Admin/Application/DeleteController.php b/src/Controller/Admin/Application/DeleteController.php index 4113d32..77725a4 100644 --- a/src/Controller/Admin/Application/DeleteController.php +++ b/src/Controller/Admin/Application/DeleteController.php @@ -4,8 +4,10 @@ namespace App\Controller\Admin\Application; use App\Entity\Application; use App\Event\ApplicationDeletedEvent; +use App\Htmx\HxRedirectResponse; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; @@ -22,20 +24,26 @@ class DeleteController extends AbstractController #[Route('/admin/application/delete/{uuid}', name: 'app_admin_application_delete')] #[IsGranted('ROLE_ADMINISTRATIVE')] #[IsGranted('DELETE', subject: 'application')] - public function index(Application $application): Response + public function index(Application $application, Request $request): Response { - $this->entityManager->remove($application); - $this->entityManager->flush(); + if (true === $request->isMethod(Request::METHOD_POST)) { + $this->entityManager->remove($application); + $this->entityManager->flush(); - $this->eventDispatcher->dispatch( - new ApplicationDeletedEvent($application), - ApplicationDeletedEvent::NAME - ); + $this->eventDispatcher->dispatch( + new ApplicationDeletedEvent($application), + ApplicationDeletedEvent::NAME + ); - $this->addFlash('success', 'Die Bewerbung wurde gelöscht'); + $this->addFlash('success', 'Die Bewerbung wurde gelöscht'); - return $this->redirectToRoute('app_administrative_assignment_detail', [ - 'uuid' => $application->getAssignment()->getUuid(), + return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_detail', [ + 'uuid' => $application->getAssignment()->getUuid(), + ])); + } + + return $this->render('admin/application/modal_delete.html.twig', [ + 'application' => $application, ]); } } diff --git a/src/Repository/ApplicationRepository.php b/src/Repository/ApplicationRepository.php index 47a5d1c..7286619 100644 --- a/src/Repository/ApplicationRepository.php +++ b/src/Repository/ApplicationRepository.php @@ -83,12 +83,8 @@ class ApplicationRepository extends ServiceEntityRepository ->select('application', 'teamer', 'feedback') ->innerJoin('application.teamer', 'teamer') ->leftJoin('teamer.feedback', 'feedback') - ->where($qb->expr()->andX( - $qb->expr()->eq('application.assignment', ':assignment'), - $qb->expr()->neq('application.status', ':status') - )) + ->where($qb->expr()->eq('application.assignment', ':assignment')) ->setParameter('assignment', $assignment) - ->setParameter('status', Application::STATUS_REJECTED) ->getQuery() ->getResult() ; diff --git a/src/Security/Voter/ApplicationVoter.php b/src/Security/Voter/ApplicationVoter.php index a0f5e86..f86cf78 100644 --- a/src/Security/Voter/ApplicationVoter.php +++ b/src/Security/Voter/ApplicationVoter.php @@ -44,8 +44,8 @@ class ApplicationVoter extends Voter if ($this->security->isGranted('ROLE_ADMINISTRATIVE') && in_array($attribute, $adminAttributes)) { $assignment = $application->getAssignment(); return match ($attribute) { - static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $status, - static::DELETE => Application::STATUS_REJECTED === $status, + static::STATUS, static::DELETE => true, + static::VIEW => Application::STATUS_REJECTED !== $status, static::DISPOSE => Application::STATUS_REJECTED !== $status && $assignment->getAvailableDispositions() > $assignment->getDispositions()->count(), default => false, diff --git a/templates/admin/application/modal_delete.html.twig b/templates/admin/application/modal_delete.html.twig index 7d8da40..dddf15c 100644 --- a/templates/admin/application/modal_delete.html.twig +++ b/templates/admin/application/modal_delete.html.twig @@ -2,6 +2,6 @@ {% block content %}
- Möchtest du die Bewerbung von {{ application.teamer }} wirklich löschen? + Möchtest du die Bewerbung von {{ application.teamer }} wirklich löschen?
{% endblock %} \ No newline at end of file