vendor/pimcore/portal-engine/src/EventSubscriber/DenyPermissionsForFolders.php line 42

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\EventSubscriber;
  12. use Pimcore\Bundle\PortalEngineBundle\Event\Permission\AbstractEvent\DataPoolItemPermissionEvent;
  13. use Pimcore\Bundle\PortalEngineBundle\Event\Permission\DataPoolDeleteItemEvent;
  14. use Pimcore\Bundle\PortalEngineBundle\Event\Permission\DataPoolSubfolderItemEvent;
  15. use Pimcore\Bundle\PortalEngineBundle\Event\Permission\DataPoolUpdateItemEvent;
  16. use Pimcore\Bundle\PortalEngineBundle\Model\Configuration\DataPool\AssetConfig;
  17. use Pimcore\Bundle\PortalEngineBundle\Model\Configuration\DataPool\DataPoolConfigInterface;
  18. use Pimcore\Bundle\PortalEngineBundle\Service\DataPool\DataPoolConfigService;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. class DenyPermissionsForFolders implements EventSubscriberInterface
  21. {
  22.     protected $dataPoolConfigService;
  23.     public function __construct(DataPoolConfigService $dataPoolConfigService)
  24.     {
  25.         $this->dataPoolConfigService $dataPoolConfigService;
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.             DataPoolUpdateItemEvent::class => 'denyAccessForRootAndUploadFolder',
  31.             DataPoolDeleteItemEvent::class => 'denyAccessForRootAndUploadFolder',
  32.             DataPoolSubfolderItemEvent::class => 'denyAccessForUploadFolderOnly',
  33.         ];
  34.     }
  35.     public function denyAccessForRootAndUploadFolder(DataPoolItemPermissionEvent $event)
  36.     {
  37.         $config $this->dataPoolConfigService->getDataPoolConfigById($event->getDataPoolId());
  38.         $this->denyAccessForRootFolder($config$event);
  39.         $this->denyAccessForUploadFolder($config$event);
  40.     }
  41.     public function denyAccessForUploadFolderOnly(DataPoolItemPermissionEvent $event)
  42.     {
  43.         $config $this->dataPoolConfigService->getDataPoolConfigById($event->getDataPoolId());
  44.         $this->denyAccessForUploadFolder($config$event);
  45.     }
  46.     protected function denyAccessForRootFolder(DataPoolConfigInterface $dataPoolConfigDataPoolItemPermissionEvent $event)
  47.     {
  48.         $workspaces $dataPoolConfig->getWorkspaces();
  49.         if (!empty($workspaces)) {
  50.             foreach ($workspaces as $workspace) {
  51.                 if ($workspace->getFullPath() === $event->getSubjectFullPath()) {
  52.                     $event->setAllowed(false);
  53.                     return;
  54.                 }
  55.             }
  56.         }
  57.     }
  58.     protected function denyAccessForUploadFolder(DataPoolConfigInterface $dataPoolConfigDataPoolItemPermissionEvent $event)
  59.     {
  60.         if (
  61.             !$dataPoolConfig instanceof AssetConfig ||
  62.             !$dataPoolConfig->getUploadFolder() ||
  63.             $dataPoolConfig->getUploadFolder()->getRealFullPath() !== $event->getSubjectFullPath()
  64.         ) {
  65.             return;
  66.         }
  67.         $event->setAllowed(false);
  68.     }
  69. }