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

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.     /**
  28.      * @return array
  29.      */
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             DataPoolUpdateItemEvent::class => 'denyAccessForRootAndUploadFolder',
  34.             DataPoolDeleteItemEvent::class => 'denyAccessForRootAndUploadFolder',
  35.             DataPoolSubfolderItemEvent::class => 'denyAccessForUploadFolderOnly',
  36.         ];
  37.     }
  38.     public function denyAccessForRootAndUploadFolder(DataPoolItemPermissionEvent $event)
  39.     {
  40.         $config $this->dataPoolConfigService->getDataPoolConfigById($event->getDataPoolId());
  41.         $this->denyAccessForRootFolder($config$event);
  42.         $this->denyAccessForUploadFolder($config$event);
  43.     }
  44.     public function denyAccessForUploadFolderOnly(DataPoolItemPermissionEvent $event)
  45.     {
  46.         $config $this->dataPoolConfigService->getDataPoolConfigById($event->getDataPoolId());
  47.         $this->denyAccessForUploadFolder($config$event);
  48.     }
  49.     protected function denyAccessForRootFolder(DataPoolConfigInterface $dataPoolConfigDataPoolItemPermissionEvent $event)
  50.     {
  51.         $workspaces $dataPoolConfig->getWorkspaces();
  52.         if (!empty($workspaces)) {
  53.             foreach ($workspaces as $workspace) {
  54.                 if ($workspace->getFullPath() === $event->getSubjectFullPath()) {
  55.                     $event->setAllowed(false);
  56.                     return;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     protected function denyAccessForUploadFolder(DataPoolConfigInterface $dataPoolConfigDataPoolItemPermissionEvent $event)
  62.     {
  63.         if (
  64.             !$dataPoolConfig instanceof AssetConfig ||
  65.             !$dataPoolConfig->getUploadFolder() ||
  66.             $dataPoolConfig->getUploadFolder()->getRealFullPath() !== $event->getSubjectFullPath()
  67.         ) {
  68.             return;
  69.         }
  70.         $event->setAllowed(false);
  71.     }
  72. }