vendor/ibexa/admin-ui/src/lib/EventListener/ContentDownloadRouteReferenceListener.php line 41

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\AdminUi\EventListener;
  8. use Ibexa\AdminUi\Specification\SiteAccess\IsAdmin;
  9. use Ibexa\Core\MVC\Symfony\Event\RouteReferenceGenerationEvent;
  10. use Ibexa\Core\MVC\Symfony\MVCEvents;
  11. use Ibexa\Core\MVC\Symfony\SiteAccess;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. /**
  14.  * Ensures that download urls generated in ezplatform-admin-ui are in the scope of admin siteaccess.
  15.  *
  16.  * @internal for internal use by AdminUI
  17.  */
  18. final class ContentDownloadRouteReferenceListener implements EventSubscriberInterface
  19. {
  20.     public const CONTENT_DOWNLOAD_ROUTE_NAME 'ibexa.content.download';
  21.     /** @var array */
  22.     private $siteAccessGroups;
  23.     public function __construct(array $siteAccessGroups)
  24.     {
  25.         $this->siteAccessGroups $siteAccessGroups;
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             MVCEvents::ROUTE_REFERENCE_GENERATION => 'onRouteReferenceGeneration',
  31.         ];
  32.     }
  33.     public function onRouteReferenceGeneration(RouteReferenceGenerationEvent $event): void
  34.     {
  35.         $routeReference $event->getRouteReference();
  36.         if ($routeReference->getRoute() != self::CONTENT_DOWNLOAD_ROUTE_NAME) {
  37.             return;
  38.         }
  39.         /** @var \Ibexa\Core\MVC\Symfony\SiteAccess $siteaccess */
  40.         $siteaccess $event->getRequest()->attributes->get('siteaccess');
  41.         if ($this->isAdminSiteAccess($siteaccess)) {
  42.             $routeReference->set('siteaccess'$siteaccess->name);
  43.         }
  44.     }
  45.     private function isAdminSiteAccess(SiteAccess $siteAccess): bool
  46.     {
  47.         return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($siteAccess);
  48.     }
  49. }
  50. class_alias(ContentDownloadRouteReferenceListener::class, 'EzSystems\EzPlatformAdminUi\EventListener\ContentDownloadRouteReferenceListener');