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 <[email protected]>
  • Loading branch information
OskarStark and DamienHarper authored Dec 20, 2023
1 parent 7ce0d36 commit a03c399
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci-4.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
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@v2
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@v2
with:
ref: 5.x
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
22 changes: 12 additions & 10 deletions src/Controller/ViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
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;

public function __construct(\Twig\Environment $environment)
public function __construct(Environment $environment)
{
$this->environment = $environment;
}
Expand Down Expand Up @@ -53,7 +55,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 @@ -66,7 +68,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 @@ -85,7 +87,7 @@ public function showEntityHistoryAction(Request $request, Reader $reader, string
$entity = UrlHelper::paramToNamespace($entity);

if (!$reader->getProvider()->isAuditable($entity)) {
throw $this->createNotFoundException();
throw new NotFoundHttpException('Not Found');
}

try {
Expand All @@ -95,18 +97,18 @@ public function showEntityHistoryAction(Request $request, Reader $reader, string
'page_size' => Reader::PAGE_SIZE,
]), $page, Reader::PAGE_SIZE);
} catch (AccessDeniedException $e) {
throw $this->createAccessDeniedException();
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
Original file line number Diff line number Diff line change
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 a03c399

Please sign in to comment.