From 79e4fe0f33b8c7bced92e6dd6000ef19e1b0a231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 11 Oct 2023 15:43:33 +0200 Subject: [PATCH] WIP: Implement application handling --- .../Admin/Application/DeleteController.php | 38 ++++++ .../DisposeController.php} | 7 +- .../Admin/Application/RejectController.php | 39 +++++++ .../Admin/Assignment/DetailController.php | 11 +- src/Security/Voter/ApplicationVoter.php | 12 +- templates/admin/assignment/detail.html.twig | 109 +++++++++++++++--- templates/admin/assignment/index.html.twig | 6 +- 7 files changed, 193 insertions(+), 29 deletions(-) create mode 100644 src/Controller/Admin/Application/DeleteController.php rename src/Controller/Admin/{DIsposition/CreateController.php => Application/DisposeController.php} (83%) create mode 100644 src/Controller/Admin/Application/RejectController.php diff --git a/src/Controller/Admin/Application/DeleteController.php b/src/Controller/Admin/Application/DeleteController.php new file mode 100644 index 0000000..d1a711f --- /dev/null +++ b/src/Controller/Admin/Application/DeleteController.php @@ -0,0 +1,38 @@ +entityManager->remove($application); + $this->entityManager->flush(); + + $this->addFlash('success', 'Die Bewerbung wurde gelöscht'); + $this->logger->info('Delete application', [ + 'application' => $application->getUuid(), + ]); + + return $this->redirectToRoute('app_admin_assignment_detail', [ + 'uuid' => $application->getAssignment()->getUuid(), + ]); + } +} \ No newline at end of file diff --git a/src/Controller/Admin/DIsposition/CreateController.php b/src/Controller/Admin/Application/DisposeController.php similarity index 83% rename from src/Controller/Admin/DIsposition/CreateController.php rename to src/Controller/Admin/Application/DisposeController.php index db40aa0..f5d9c84 100644 --- a/src/Controller/Admin/DIsposition/CreateController.php +++ b/src/Controller/Admin/Application/DisposeController.php @@ -1,6 +1,6 @@ setStatus(Application::STATUS_REJECTED); + + $this->entityManager->flush(); + + $this->addFlash('success', 'Die Bewerbung wurde abgelehnt'); + $this->logger->info('Reject application', [ + 'application' => $application->getUuid(), + ]); + + return $this->redirectToRoute('app_admin_assignment_detail', [ + 'uuid' => $application->getAssignment()->getUuid(), + ]); + } +} \ No newline at end of file diff --git a/src/Controller/Admin/Assignment/DetailController.php b/src/Controller/Admin/Assignment/DetailController.php index 1612da6..2925fbd 100644 --- a/src/Controller/Admin/Assignment/DetailController.php +++ b/src/Controller/Admin/Assignment/DetailController.php @@ -2,27 +2,34 @@ namespace App\Controller\Admin\Assignment; +use App\Controller\Traits\ReturnUrlTrait; use App\Entity\Assignment; use App\Repository\ApplicationRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; class DetailController extends AbstractController { + use ReturnUrlTrait; + public function __construct(private readonly ApplicationRepository $applicationRepository) {} #[Route('/admin/assignment/detail/{uuid}', name: 'app_admin_assignment_detail')] #[IsGranted('ROLE_ADMINISTRATIVE')] - public function index(Assignment $assignment): Response + public function index(Assignment $assignment, Request $request): Response { - $applications = $this->applicationRepository->findBy(['assignment' => $assignment]); + $applications = $this->applicationRepository->findBy([ + 'assignment' => $assignment, + ]); return $this->render('admin/assignment/detail.html.twig', [ 'assignment' => $assignment, 'applications' => $applications, + 'returnUrl' => $this->getReturnUrl($request, 'app_admin_assignment_index'), ]); } } \ No newline at end of file diff --git a/src/Security/Voter/ApplicationVoter.php b/src/Security/Voter/ApplicationVoter.php index 2dc4866..204bcaa 100644 --- a/src/Security/Voter/ApplicationVoter.php +++ b/src/Security/Voter/ApplicationVoter.php @@ -11,6 +11,8 @@ class ApplicationVoter extends Voter { public const VIEW = 'VIEW'; public const DELETE = 'DELETE'; + public const DISPOSE = 'DISPOSE'; + public const REJECT = 'REJECT'; protected function supports(string $attribute, mixed $subject): bool { @@ -18,7 +20,7 @@ class ApplicationVoter extends Voter return false; } - return in_array($attribute, [static::VIEW, static::DELETE]); + return in_array($attribute, [static::VIEW, static::DELETE, static::DISPOSE, static::REJECT]); } protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool @@ -30,10 +32,14 @@ class ApplicationVoter extends Voter $application = $subject; if ($user->hasRole('ROLE_ADMINISTRATIVE')) { - return true; + return match ($attribute) { + static::VIEW, static::DELETE => true, + static::DISPOSE, static::REJECT => Application::STATUS_REJECTED !== $application->getStatus(), + default => false, + }; } - if ($user->hasRole('ROLE_TEAMER')) { + if (static::VIEW === $attribute && $user->hasRole('ROLE_TEAMER')) { return $user->getTeamer() === $application->getTeamer(); } diff --git a/templates/admin/assignment/detail.html.twig b/templates/admin/assignment/detail.html.twig index 9c673df..0892bb9 100644 --- a/templates/admin/assignment/detail.html.twig +++ b/templates/admin/assignment/detail.html.twig @@ -6,27 +6,100 @@

Einsatzübersicht

-
+
{% include '_partials/_assignment_info.html.twig' %}
-
- {% for application in applications %} - - {{ application.teamer }} - - {{ application.requests }} - - {% endfor %} +
+

+ Bewerbungen +

+
+
+ + + + + + + + + + + {% for application in applications %} + + + + + + + {% else %} + + + + {% endfor %} + +
+ Name + + Anmerkungen + + Status +
+ + {{ application.teamer }} + + + {{ application.requests|nl2br }} + + {{ ('label.application.status.' ~ application.status)|trans }} + +
+ {% if is_granted('DISPOSE', application) %} + + {% endif %} + {% if is_granted('REJECT', application) %} + + {% endif %} + {% if is_granted('DELETE', application) %} + + {% endif %} +
+
+
+ Bisher liegen keine Bewerbungen vor +
+
+
+
+ + zurück +
{% endblock %} \ No newline at end of file diff --git a/templates/admin/assignment/index.html.twig b/templates/admin/assignment/index.html.twig index 7fca49f..2680184 100644 --- a/templates/admin/assignment/index.html.twig +++ b/templates/admin/assignment/index.html.twig @@ -57,14 +57,14 @@ {{ assignment.pickupDate ? assignment.pickupDate|date('d.m.Y') : '' }} - {{ assignment.applications|length }} + {{ assignment.applications|length }}/{{ assignment.availableDispositions }}