vendor/pimcore/portal-engine/src/Service/Security/Voter/DataPoolItemPermissionVoter.php line 25

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\Service\Security\Voter;
  12. use Pimcore\Bundle\PortalEngineBundle\Enum\Permission;
  13. use Pimcore\Bundle\PortalEngineBundle\Service\DataPool\DataPoolConfigService;
  14. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\PortalConfigService;
  15. use Pimcore\Bundle\PortalEngineBundle\Service\Security\PermissionService;
  16. use Pimcore\Bundle\PortalEngineBundle\Service\Security\Traits\SecurityServiceAware;
  17. use Pimcore\Model\Asset;
  18. use Pimcore\Model\Element\ElementInterface;
  19. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  20. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  21. class DataPoolItemPermissionVoter extends Voter
  22. {
  23.     use SecurityServiceAware;
  24.     const PERMISSIONS = [
  25.         Permission::CREATE,
  26.         Permission::DELETE,
  27.         Permission::EDIT,
  28.         Permission::VIEW,
  29.         Permission::UPDATE,
  30.         Permission::DOWNLOAD,
  31.         Permission::SUBFOLDER,
  32.         Permission::VIEW_OWNED_ASSET_ONLY,
  33.     ];
  34.     /**
  35.      * @var PortalConfigService
  36.      */
  37.     protected $portalConfigService;
  38.     /**
  39.      * @var DataPoolConfigService
  40.      */
  41.     protected $dataPoolConfigService;
  42.     /**
  43.      * @var PermissionService
  44.      */
  45.     protected $permissionService;
  46.     /**
  47.      * @param PortalConfigService $portalConfigService
  48.      * @param DataPoolConfigService $dataPoolConfigService
  49.      * @param PermissionService $permissionService
  50.      */
  51.     public function __construct(PortalConfigService $portalConfigServiceDataPoolConfigService $dataPoolConfigServicePermissionService $permissionService)
  52.     {
  53.         $this->portalConfigService $portalConfigService;
  54.         $this->dataPoolConfigService $dataPoolConfigService;
  55.         $this->permissionService $permissionService;
  56.     }
  57.     protected function supports($attribute$subject)
  58.     {
  59.         return $this->portalConfigService->isPortalEngineSite()
  60.             && in_array($attributeself::PERMISSIONS)
  61.             && (is_string($subject) || $subject instanceof ElementInterface);
  62.     }
  63.     /**
  64.      * @param string $attribute
  65.      * @param mixed $subject
  66.      * @param TokenInterface $token
  67.      *
  68.      * @return bool
  69.      */
  70.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  71.     {
  72.         $dataPoolConfig $this->dataPoolConfigService->getCurrentDataPoolConfig();
  73.         if (empty($dataPoolConfig)) {
  74.             return false;
  75.         }
  76.         $fullPath $subject instanceof ElementInterface $subject->getRealFullPath() : $subject;
  77.         $respectWorkflowPermissions $subject instanceof Asset;
  78.         $respectUploadFolderPermissions $subject instanceof Asset;
  79.         return $this->permissionService->isPermissionAllowed(
  80.             $attribute,
  81.             $this->securityService->getPortalUser(),
  82.             $dataPoolConfig->getId(),
  83.             $fullPath,
  84.             false,
  85.             $respectWorkflowPermissions,
  86.             true,
  87.             $respectUploadFolderPermissions
  88.         );
  89.     }
  90. }