<?php
/**
* @author Thomas HERISSON (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\SuppliersOrdersBundle\EventSubscriber;
use App\Services\Configuration;
use Bluue\SuppliersOrdersBundle\Event\ConfigurationAccessSupplierOrderEditEvent;
use Bluue\SuppliersBundle\Security\SuppliersVoter;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AccessEditDocumentValidatedSubscriber implements EventSubscriberInterface
{
/**
* @var Configuration
*/
protected Configuration $configuration;
/**
* @var Security
*/
protected Security $security;
/**
* @param Configuration $configuration
* @param Security $security
*/
public function __construct(Configuration $configuration, Security $security)
{
$this->configuration = $configuration;
$this->security = $security;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
ConfigurationAccessSupplierOrderEditEvent::NAME => 'supplierOrderEdit'
];
}
/**
* @param ConfigurationAccessSupplierOrderEditEvent $event
* @return void
*/
public function supplierOrderEdit(ConfigurationAccessSupplierOrderEditEvent $event): void
{
$supplierOrder = $event->getSupplierOrder();
if (
!$this->configuration->get('suppliers_orders_bundle__modify_orders_validated')
|| !$this->security->isGranted(SuppliersVoter::ACCESS, $supplierOrder)
|| !$supplierOrder->getFilterReceiptNotes(false, true)->isEmpty()
) {
return;
}
$event->setAccess(true);
}
}