Skip to content

Commit

Permalink
Fix: ViewerController (#379)
Browse files Browse the repository at this point in the history
* Fix: `ViewerController`

* -

* -

* -

* Fixed remaining calls to AbstractController methods.

* -

* -

* -

* -

* PHP-CS-Fixer

---------

Co-authored-by: Damien Harper <damien.harper@gmail.com>
  • Loading branch information
OskarStark and DamienHarper committed Dec 20, 2023
1 parent a9684c9 commit 7c226bb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci-4.x.yml
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/ci-5.x.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/Controller/ViewerController.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
]);
Expand All @@ -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,
]);
Expand All @@ -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 {
Expand All @@ -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));
}
}
2 changes: 0 additions & 2 deletions src/Resources/config/services.yaml
Expand Up @@ -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:
Expand Down

0 comments on commit 7c226bb

Please sign in to comment.