src/Bidcoz/Bundle/CoreBundle/Security/Authorization/Voter/OrganizationPaymentPlanVoter.php line 15

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\CoreBundle\Security\Authorization\Voter;
  3. use Bidcoz\Bundle\CoreBundle\Entity\Organization;
  4. use Bidcoz\Bundle\CoreBundle\Services\PermissionManager;
  5. use RS\DiExtraBundle\Annotation as DI;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. /**
  9.  * @DI\Service
  10.  * @DI\Tag("security.voter")
  11.  */
  12. class OrganizationPaymentPlanVoter extends Voter
  13. {
  14.     protected $permissionManager;
  15.     /**
  16.      * @DI\InjectParams({
  17.      *      "permissionManager" = @DI\Inject("permission_manager"),
  18.      * })
  19.      */
  20.     public function __construct(PermissionManager $permissionManager)
  21.     {
  22.         $this->permissionManager $permissionManager;
  23.     }
  24.     protected function supports($attribute$subject)
  25.     {
  26.         $orgVoterAttributes = [
  27.             OrganizationVoter::VIEW,
  28.             OrganizationVoter::MANAGE,
  29.             OrganizationVoter::EMAIL,
  30.             OrganizationVoter::CONTACTS,
  31.             OrganizationVoter::ADMIN,
  32.         ];
  33.         return $subject instanceof Organization && !in_array($attribute$orgVoterAttributes);
  34.     }
  35.     /**
  36.      * @param string       $attribute
  37.      * @param Organization $organization
  38.      */
  39.     protected function voteOnAttribute($attribute$organizationTokenInterface $token): bool
  40.     {
  41.         $paymentPlan $organization->getPaymentModel();
  42.         if ($this->permissionManager->isAllowedByPaymentPlan($attribute$paymentPlan)) {
  43.             return true;
  44.         }
  45.         return false;
  46.     }
  47. }