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

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