From 7c226bbf2cf1485266fcb737589db72dd755fd56 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 21 Dec 2023 00:41:54 +0100 Subject: [PATCH] Fix: `ViewerController` (#379) * Fix: `ViewerController` * - * - * - * Fixed remaining calls to AbstractController methods. * - * - * - * - * PHP-CS-Fixer --------- Co-authored-by: Damien Harper --- .github/workflows/ci-4.x.yml | 4 +--- .github/workflows/ci-5.x.yml | 12 +++--------- src/Controller/ViewerController.php | 22 +++++++++++----------- src/Resources/config/services.yaml | 2 -- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci-4.x.yml b/.github/workflows/ci-4.x.yml index 9291a789..de1d1ce9 100644 --- a/.github/workflows/ci-4.x.yml +++ b/.github/workflows/ci-4.x.yml @@ -29,9 +29,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 - with: - ref: 4.x + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/ci-5.x.yml b/.github/workflows/ci-5.x.yml index f22aaab8..6603bea2 100644 --- a/.github/workflows/ci-5.x.yml +++ b/.github/workflows/ci-5.x.yml @@ -18,9 +18,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 - with: - ref: 5.x + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -57,9 +55,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 - with: - ref: 5.x + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -130,9 +126,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 - with: - ref: 5.x + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/src/Controller/ViewerController.php b/src/Controller/ViewerController.php index c0ec8992..570bbaef 100644 --- a/src/Controller/ViewerController.php +++ b/src/Controller/ViewerController.php @@ -10,16 +10,17 @@ use DH\Auditor\Provider\Doctrine\Persistence\Schema\SchemaManager; use DH\Auditor\Provider\Doctrine\Service\AuditingService; use DH\AuditorBundle\Helper\UrlHelper; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Security\Core\Exception\AccessDeniedException as SymfonyAccessDeniedException; use Twig\Environment; /** * @see \DH\AuditorBundle\Tests\Controller\ViewerControllerTest */ -class ViewerController extends AbstractController +class ViewerController { private Environment $environment; @@ -52,7 +53,7 @@ static function ($entity) use ($reader, $scope) { ); } - return $this->render('@DHAuditor/Audit/audits.html.twig', [ + return $this->renderView('@DHAuditor/Audit/audits.html.twig', [ 'audited' => $audited, 'reader' => $reader, ]); @@ -63,7 +64,7 @@ public function showTransactionAction(Reader $reader, string $hash): Response { $audits = $reader->getAuditsByTransactionHash($hash); - return $this->render('@DHAuditor/Audit/transaction.html.twig', [ + return $this->renderView('@DHAuditor/Audit/transaction.html.twig', [ 'hash' => $hash, 'audits' => $audits, ]); @@ -75,11 +76,10 @@ public function showEntityHistoryAction(Request $request, Reader $reader, string \assert(\is_string($request->query->get('page', '1')) || \is_int($request->query->get('page', '1'))); $page = (int) $request->query->get('page', '1'); $page = $page < 1 ? 1 : $page; - $entity = UrlHelper::paramToNamespace($entity); if (!$reader->getProvider()->isAuditable($entity)) { - throw $this->createNotFoundException(); + throw new NotFoundHttpException('Not Found'); } try { @@ -88,19 +88,19 @@ public function showEntityHistoryAction(Request $request, Reader $reader, string 'page' => $page, 'page_size' => Reader::PAGE_SIZE, ]), $page, Reader::PAGE_SIZE); - } catch (AccessDeniedException) { - throw $this->createAccessDeniedException(); + } catch (AccessDeniedException $e) { + throw new SymfonyAccessDeniedException('Access Denied.'); } - return $this->render('@DHAuditor/Audit/entity_history.html.twig', [ + return $this->renderView('@DHAuditor/Audit/entity_history.html.twig', [ 'id' => $id, 'entity' => $entity, 'paginator' => $pager, ]); } - protected function renderView(string $view, array $parameters = []): string + protected function renderView(string $view, array $parameters = []): Response { - return $this->environment->render($view, $parameters); + return new Response($this->environment->render($view, $parameters)); } } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 4b130006..59aa34a7 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -67,8 +67,6 @@ services: # Bundle related services DH\AuditorBundle\Controller\ViewerController: arguments: ['@twig'] - calls: - - { method: setContainer, arguments: ['@service_container'] } tags: ['controller.service_arguments'] DH\AuditorBundle\User\UserProvider: