From 55bd904df3e1a068729cff0148449bd44468e936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 10 Jan 2025 16:55:22 +0100 Subject: [PATCH] feat: provide feedback as admin user --- .../Feedback/ProvideController.php | 20 +++++++++++++------ src/Security/Voter/DispositionVoter.php | 12 +++++++---- templates/admin/index.html.twig | 2 +- .../feedback/provide.html.twig | 2 +- templates/administrative/layout.html.twig | 4 ++++ .../house_manager/feedback/index.html.twig | 2 +- templates/house_manager/index.html.twig | 4 ++-- templates/house_manager/layout.html.twig | 9 --------- templates/manager/index.html.twig | 2 +- templates/manager/layout.html.twig | 9 --------- 10 files changed, 32 insertions(+), 34 deletions(-) rename src/Controller/{HouseManager => Administrative}/Feedback/ProvideController.php (74%) rename templates/{house_manager => administrative}/feedback/provide.html.twig (98%) delete mode 100644 templates/house_manager/layout.html.twig delete mode 100644 templates/manager/layout.html.twig diff --git a/src/Controller/HouseManager/Feedback/ProvideController.php b/src/Controller/Administrative/Feedback/ProvideController.php similarity index 74% rename from src/Controller/HouseManager/Feedback/ProvideController.php rename to src/Controller/Administrative/Feedback/ProvideController.php index 591c92e..afbba83 100644 --- a/src/Controller/HouseManager/Feedback/ProvideController.php +++ b/src/Controller/Administrative/Feedback/ProvideController.php @@ -1,7 +1,8 @@ handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - // Feedbacks without comments are published immediately - if (empty($feedback->getComment())) { + // Feedbacks without comments or provided by admins are published immediately + if ($this->isGranted('ROLE_ADMINISTRATIVE') || empty($feedback->getComment())) { $feedback->setStatus(Feedback::STATUS_PUBLISHED); } @@ -67,10 +70,15 @@ class ProvideController extends AbstractController $this->addFlash('success', 'Das Feedback wurde entgegengenommen'); - return $this->redirectToRoute('app_house_manager_feedback_index'); + $defaultReturnUrlRoute = $this->isGranted('ROLE_HOUSE_MANAGER') ? + 'app_house_manager_feedback_index' : $user->getDefaultRoute(); + + $returnUrl = $this->getReturnUrl($request, $defaultReturnUrlRoute); + + return $this->redirect($returnUrl); } - return $this->render('house_manager/feedback/provide.html.twig', [ + return $this->render('administrative/feedback/provide.html.twig', [ 'form' => $form, 'disposition' => $disposition, ]); diff --git a/src/Security/Voter/DispositionVoter.php b/src/Security/Voter/DispositionVoter.php index e1a9c7b..9d55788 100644 --- a/src/Security/Voter/DispositionVoter.php +++ b/src/Security/Voter/DispositionVoter.php @@ -43,9 +43,10 @@ class DispositionVoter extends Voter $disposition = $subject; return match ($attribute) { - static::VIEW, static::EDIT, static::CONTRACT, static::INVOICE => $this->assertAdministrativeAccess() || $this->assertTeamerAccess($disposition), + static::VIEW, static::EDIT, static::CONTRACT, static::INVOICE => $this->assertAdministrativeAccess() + || $this->assertTeamerAccess($token, $disposition), static::DELETE => $this->assertAdminAccess(), - static::FEEDBACK => $this->assertHouseManagerAccess($token, $disposition), + static::FEEDBACK => $this->assertAdminAccess() || $this->assertHouseManagerAccess($token, $disposition), default => false, }; } @@ -80,12 +81,15 @@ class DispositionVoter extends Voter return $isMatchingHotel && $isPast; } - private function assertTeamerAccess(Disposition $disposition): bool + private function assertTeamerAccess(TokenInterface $token, Disposition $disposition): bool { if (false === $this->security->isGranted('ROLE_TEAMER')) { return false; } - return $this->security->getUser()->getTeamer() === $disposition->getTeamer(); + /** @var User $user */ + $user = $token->getUser(); + + return $user->getTeamer() === $disposition->getTeamer(); } } diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig index d693332..d8ec903 100644 --- a/templates/admin/index.html.twig +++ b/templates/admin/index.html.twig @@ -166,7 +166,7 @@ {% for disposition in overdueFeedbacks %} {% set assignment = disposition.assignment %}
  • - {{ icon('feedback', 'w-4 h-4 shrink-0') }} {{ disposition.teamer }} diff --git a/templates/house_manager/feedback/provide.html.twig b/templates/administrative/feedback/provide.html.twig similarity index 98% rename from templates/house_manager/feedback/provide.html.twig rename to templates/administrative/feedback/provide.html.twig index a6273a2..63bd6c3 100644 --- a/templates/house_manager/feedback/provide.html.twig +++ b/templates/administrative/feedback/provide.html.twig @@ -1,4 +1,4 @@ -{% extends 'house_manager/layout.html.twig' %} +{% extends 'administrative/layout.html.twig' %} {% block title %}Feedback abgeben{% endblock %} diff --git a/templates/administrative/layout.html.twig b/templates/administrative/layout.html.twig index 59f774f..990b647 100644 --- a/templates/administrative/layout.html.twig +++ b/templates/administrative/layout.html.twig @@ -3,6 +3,8 @@ {% block main_menu %} {% if is_granted('ROLE_MANAGER') %} {{ knp_menu_render(knp_menu_get('manager_main')) }} + {% elseif is_granted('ROLE_HOUSE_MANAGER') %} + {{ knp_menu_render(knp_menu_get('house_manager_main')) }} {% elseif is_granted('ROLE_ADMIN') %} {{ knp_menu_render(knp_menu_get('admin_main')) }} {% endif %} @@ -11,6 +13,8 @@ {% block mobile_menu %} {% if is_granted('ROLE_MANAGER') %} {{ knp_menu_render(knp_menu_get('manager_main')) }} + {% elseif is_granted('ROLE_HOUSE_MANAGER') %} + {{ knp_menu_render(knp_menu_get('house_manager_main')) }} {% elseif is_granted('ROLE_ADMIN') %} {{ knp_menu_render(knp_menu_get('admin_main')) }} {% endif %} diff --git a/templates/house_manager/feedback/index.html.twig b/templates/house_manager/feedback/index.html.twig index ad14bfb..627590e 100644 --- a/templates/house_manager/feedback/index.html.twig +++ b/templates/house_manager/feedback/index.html.twig @@ -1,4 +1,4 @@ -{% extends 'house_manager/layout.html.twig' %} +{% extends 'administrative/layout.html.twig' %} {% block title %}Ausstehendes Feedback{% endblock %} diff --git a/templates/house_manager/index.html.twig b/templates/house_manager/index.html.twig index 3e866e9..2e9739e 100644 --- a/templates/house_manager/index.html.twig +++ b/templates/house_manager/index.html.twig @@ -1,4 +1,4 @@ -{% extends 'house_manager/layout.html.twig' %} +{% extends 'administrative/layout.html.twig' %} {% macro dispositionData(disposition) %} {% set assignment = disposition.assignment %} @@ -49,7 +49,7 @@ {% for disposition in pendingFeedbacks %} {% set assignment = disposition.assignment %}
  • - {{ icon('feedback', 'w-4 h-4 shrink-0') }} {{ _self.dispositionData(disposition) }} diff --git a/templates/house_manager/layout.html.twig b/templates/house_manager/layout.html.twig deleted file mode 100644 index 23b1533..0000000 --- a/templates/house_manager/layout.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'layout.html.twig' %} - -{% block main_menu %} - {{ knp_menu_render(knp_menu_get('house_manager_main')) }} -{% endblock %} - -{% block mobile_menu %} - {{ knp_menu_render(knp_menu_get('house_manager_main')) }} -{% endblock %} diff --git a/templates/manager/index.html.twig b/templates/manager/index.html.twig index da768d2..fea1e71 100644 --- a/templates/manager/index.html.twig +++ b/templates/manager/index.html.twig @@ -1,4 +1,4 @@ -{% extends 'manager/layout.html.twig' %} +{% extends 'administrative/layout.html.twig' %} {% block content %}
    diff --git a/templates/manager/layout.html.twig b/templates/manager/layout.html.twig deleted file mode 100644 index 039e670..0000000 --- a/templates/manager/layout.html.twig +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'layout.html.twig' %} - -{% block main_menu %} - {{ knp_menu_render(knp_menu_get('manager_main')) }} -{% endblock %} - -{% block mobile_menu %} - {{ knp_menu_render(knp_menu_get('manager_main')) }} -{% endblock %}