vendor/bluue/suppliers-orders-bundle/src/EventSubscriber/AccessEditDocumentValidatedSubscriber.php line 55

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\SuppliersOrdersBundle\EventSubscriber;
  9. use App\Services\Configuration;
  10. use Bluue\SuppliersOrdersBundle\Event\ConfigurationAccessSupplierOrderEditEvent;
  11. use Bluue\SuppliersBundle\Security\SuppliersVoter;
  12. use Symfony\Component\Security\Core\Security;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class AccessEditDocumentValidatedSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var Configuration
  18.      */
  19.     protected Configuration $configuration;
  20.     /**
  21.      * @var Security
  22.      */
  23.     protected Security $security;
  24.     /**
  25.      * @param Configuration $configuration
  26.      * @param Security $security
  27.      */
  28.     public function __construct(Configuration $configurationSecurity $security)
  29.     {
  30.         $this->configuration $configuration;
  31.         $this->security $security;
  32.     }
  33.     /**
  34.      * @return array
  35.      */
  36.     public static function getSubscribedEvents(): array
  37.     {
  38.         return [
  39.             ConfigurationAccessSupplierOrderEditEvent::NAME => 'supplierOrderEdit'
  40.         ];
  41.     }
  42.     /**
  43.      * @param ConfigurationAccessSupplierOrderEditEvent $event
  44.      * @return void
  45.      */
  46.     public function supplierOrderEdit(ConfigurationAccessSupplierOrderEditEvent $event): void
  47.     {
  48.         $supplierOrder $event->getSupplierOrder();
  49.         if (
  50.             !$this->configuration->get('suppliers_orders_bundle__modify_orders_validated')
  51.             || !$this->security->isGranted(SuppliersVoter::ACCESS$supplierOrder)
  52.             || !$supplierOrder->getFilterReceiptNotes(falsetrue)->isEmpty()
  53.         ) {
  54.             return;
  55.         }
  56.         $event->setAccess(true);
  57.     }
  58. }