Skip to content

Commit

Permalink
Aligned base controller definition
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Dec 29, 2024
1 parent b81afaf commit dc1849f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,6 @@ parameters:
count: 1
path: src/contracts/Component/Renderer/RendererInterface.php

-
message: "#^Method Ibexa\\\\Contracts\\\\AdminUi\\\\Controller\\\\Controller\\:\\:performAccessCheck\\(\\) has no return type specified\\.$#"
count: 1
path: src/contracts/Controller/Controller.php

-
message: "#^Method Ibexa\\\\Contracts\\\\AdminUi\\\\Form\\\\ActionDispatcher\\\\ActionDispatcherInterface\\:\\:dispatchFormAction\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
34 changes: 34 additions & 0 deletions src/bundle/EventSubscriber/PerformAccessCheckSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Bundle\AdminUi\EventSubscriber;

use Ibexa\Contracts\AdminUi\Controller\Controller;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;

/**
* Performs access check to backoffice controllers.
*/
final class PerformAccessCheckSubscriber implements EventSubscriberInterface
{
public function onControllerArgumentsEvent(ControllerArgumentsEvent $event): void
{
$controller = $event->getController();
if (is_array($controller) && $controller[0] instanceof Controller) {
$controller[0]->performAccessCheck();
}
}

public static function getSubscribedEvents(): array
{
return [
ControllerArgumentsEvent::class => 'onControllerArgumentsEvent',
];
}
}
6 changes: 2 additions & 4 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ services:
public: false

Ibexa\Contracts\AdminUi\Controller\Controller:
tags: ['controller.service_arguments']
calls:
- [setContainer, ["@service_container"]]
- [performAccessCheck, []]
tags:
- name: controller.service_arguments

Ibexa\Bundle\AdminUi\ParamConverter\:
resource: "../../ParamConverter/*"
Expand Down
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ services:
tags:
- { name: kernel.event_subscriber }

Ibexa\Bundle\AdminUi\EventSubscriber\PerformAccessCheckSubscriber:
tags:
- { name: kernel.event_subscriber }

Ibexa\AdminUi\EventListener\RequestListener:
arguments:
- '%ibexa.site_access.groups_by_site_access%'
Expand Down
9 changes: 2 additions & 7 deletions src/contracts/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\AdminUi\Controller;

Expand All @@ -13,17 +14,11 @@

abstract class Controller extends AbstractController
{
public function performAccessCheck()
public function performAccessCheck(): void
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location
* @param string $uriFragment
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function redirectToLocation(Location $location, string $uriFragment = ''): RedirectResponse
{
return $this->redirectToRoute('ibexa.content.view', [
Expand Down

0 comments on commit dc1849f

Please sign in to comment.