src/Service/Access.php line 156

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Entity\Advertiser;
  4. use App\Entity\Agency;
  5. use App\Entity\Operation;
  6. use App\Entity\OperationFamily;
  7. use App\Entity\OperationOrder;
  8. use App\Entity\OperationOrderComment;
  9. use App\Entity\OperationOrderQuotaVersion;
  10. use App\Entity\OperationOrderStepVersion;
  11. use App\Entity\PolymorphicOperationOrder\OperationOrderAnimation;
  12. use App\Entity\PolymorphicOperationOrder\OperationOrderFurniture;
  13. use App\Entity\PolymorphicOperationOrder\OperationOrderRefrigeratorBin;
  14. use App\Entity\Quota;
  15. use App\Entity\Role;
  16. use App\Entity\User;
  17. use App\Rights\CustomSecurityLoader;
  18. use App\Service\User as UserService;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Symfony\Component\HttpFoundation\RedirectResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\RequestStack;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\HttpKernel\Exception\HttpException;
  25. use Symfony\Component\Routing\RouterInterface;
  26. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  27. use Symfony\Component\Yaml\Yaml;
  28. use Twig\Environment;
  29. use Twig\Error\LoaderError;
  30. use Twig\Error\RuntimeError;
  31. use Twig\Error\SyntaxError;
  32. class Access
  33. {
  34.     private Environment $twig;
  35.     private $adminListUrls;
  36.     private AdvertisingManagement $advertiserService;
  37.     private AdvertiserRightService $advertiserRightService;
  38.     private $anonListUrls;
  39.     private $authListUrls;
  40.     private AuthorizationCheckerInterface $authorizationChecker;
  41.     private EntityManagerInterface $entityManager;
  42.     private RouterInterface $routerService;
  43.     private UserService $userService;
  44.     private RequestStack $requestStack;
  45.     private ?Request $request null;
  46.     private CustomSecurityLoader $customSecurityLoader;
  47.     private string $staciSubDomain;
  48.     public function __construct(AdvertiserRightService $advertiserRightServiceUserService $userServiceAdvertisingManagement $advertiserEnvironment $twigAuthorizationCheckerInterface $authorizationCheckerEntityManagerInterface $entityManagerRouterInterface $routerRequestStack $requestStackCustomSecurityLoader $customSecurityLoaderstring $staciSubDomain)
  49.     {
  50.         $this->twig $twig;
  51.         $this->adminListUrls = [];
  52.         $this->advertiserService $advertiser;
  53.         $this->advertiserRightService $advertiserRightService;
  54.         $this->anonListUrls = [];
  55.         $this->authListUrls = [];
  56.         $this->authorizationChecker $authorizationChecker;
  57.         $this->customSecurityLoader $customSecurityLoader;
  58.         $this->entityManager $entityManager;
  59.         $this->parseSecurityYaml();
  60.         $this->requestStack $requestStack;
  61.         $this->request $requestStack->getCurrentRequest();
  62.         $this->routerService $router;
  63.         $this->userService $userService;
  64.         $this->staciSubDomain $staciSubDomain;
  65.     }
  66.     public function getAnonListUrls(): array
  67.     {
  68.         return $this->anonListUrls;
  69.     }
  70.     public function getAuthListUrls(): array
  71.     {
  72.         return $this->authListUrls;
  73.     }
  74.     public function getAdminListUrls(): array
  75.     {
  76.         return $this->adminListUrls;
  77.     }
  78.     public function check(string $actionobject|null $entity null): bool
  79.     {
  80.         $currentAdvertiser $advertiser $this->advertiserService->getCurrentAdvertiserByDomain();
  81.         $user $this->userService->getUser();
  82.         if ($user === null) {
  83.             $scheme $this->requestStack->getCurrentRequest() ? $this->requestStack->getCurrentRequest()->getScheme() : 'http';
  84.             $response = new RedirectResponse($scheme '://' $this->getDefaultUrl());
  85.             $response->send();
  86.         }
  87.         $haveToSwitchAdvertiser false;
  88.         if ($user instanceof User && $advertiser instanceof Advertiser) {
  89.             $isGood $this->userService->isUserAdvertiser($currentAdvertiser$user);
  90.             if (false === $isGood) {
  91.                 $userAdvertiser $user->getAdvertiser();
  92.                 if ($userAdvertiser instanceof Advertiser) {
  93.                     $haveToSwitchAdvertiser true;
  94.                 }
  95.             } elseif (
  96.                 $this->requestStack->getSession()->get('advertiser') === null
  97.                 || ($currentAdvertiser instanceof Advertiser && $this->requestStack->getSession()->get('advertiser') !== null && $currentAdvertiser->getId() !== $this->requestStack->getSession()->get('advertiser'))
  98.             ) {
  99.                 $this->writeRightInSession($user$advertisernull);
  100.             }
  101.         }
  102.         if (true === $haveToSwitchAdvertiser && isset($userAdvertiser) && $userAdvertiser instanceof Advertiser) {
  103.             $scheme $this->requestStack->getCurrentRequest() ? $this->requestStack->getCurrentRequest()->getScheme() : 'http';
  104.             $requestUri $this->requestStack->getMainRequest()->server->get('REQUEST_URI');
  105.             $requestUriCleaned preg_replace('/\?.*/''', (string) $requestUri);
  106.             $redirectUrl $scheme '://' $userAdvertiser->getSubdomain() . $this->requestStack->getMainRequest()->server->get('COOKIE_DOMAIN') . $requestUriCleaned;
  107.             $response = new RedirectResponse($redirectUrl);
  108.             $response->send();
  109.         }
  110.         if ($entity !== null) {
  111.             if (
  112.                 (method_exists($entity'getAdvertiser') && $entity->getAdvertiser() !== null && $entity->getAdvertiser() !== $currentAdvertiser)
  113.                 || ($entity instanceof OperationOrder && $entity->getOperation()->getAdvertiser() !== $currentAdvertiser)
  114.                 || ($entity instanceof Quota && $entity->getOperation()->getAdvertiser() !== $currentAdvertiser)
  115.                 || ($entity instanceof OperationOrder && $user->getIsAgency() === true && $this->agencyCanManageOrder($entity$user) === false)
  116.                 || ($entity instanceof Operation && $user->getIsAgency() === true && $this->agencyCanManageOperation($entity$user) === false)
  117.             ) {
  118.                 throw new HttpException(403'access denied');
  119.             }
  120.         }
  121.         $this->requestStack->getSession()->set('fixRaceCondition'true);
  122.         $isGranted $this->authorizationChecker->isGranted($action$entity);
  123.         if (false === $isGranted || $this->userService->userHaveRole($user$advertiser) === false) {
  124.             throw new HttpException(403'access denied');
  125.         }
  126.         return $isGranted;
  127.     }
  128.     public function checkUrl(string $path): bool|string
  129.     {
  130.         $route $path;
  131.         $rightValue false;
  132.         try {
  133.             $route $this->routerService->match($path)['_route'];
  134.         } catch (\Exception) {
  135.         }
  136.         foreach ($this->anonListUrls as $url) {
  137.             if (preg_match('!' $url '!', (string) $route)) {
  138.                 return true;
  139.             }
  140.         }
  141.         if (true === $this->requestStack->getSession()->get('advertiserAdmin') || true === $this->userService->isAdmin(null)) {
  142.             return true;
  143.         }
  144.         foreach ($this->adminListUrls as $url) {
  145.             if (preg_match('!' $url '!', (string) $route)) {
  146.                 return false;
  147.             }
  148.         }
  149.         if (true === $this->requestStack->getSession()->get('canAccessAdvertiser')) {
  150.             $advertiser $this->advertiserService->getCurrentAdvertiser();
  151.             $defaultAdvertiser $this->advertiserService->getDefaultAdvertiser();
  152.             if (!($advertiser instanceof Advertiser)) {
  153.                 return false;
  154.             }
  155.             if ($route === 'index' && $advertiser !== $defaultAdvertiser) {
  156.                 return true;
  157.             }
  158.             $user $this->userService->getUser();
  159.             if (!($user instanceof User)) {
  160.                 return false;
  161.             }
  162.             $rightName null;
  163.             $userRole $user->getRole();
  164.             if ($userRole instanceof Role) {
  165.                 $rightName 'p_' $userRole->getId() . '_' $route '_view';
  166.                 $rightValue $this->requestStack->getSession()->get($rightName);
  167.             }
  168.             if (true === $rightValue || '1' === $rightValue) {
  169.                 if ('p_operation_quota_view' === $rightName && str_ends_with($path'/edit/quota')) {
  170.                     if (null !== $user->getCategories()) {
  171.                         $rightValue false;
  172.                         $explodedPath explode('/'$path);
  173.                         $operation $this->entityManager->getRepository(Operation::class)->findOneBy([
  174.                             'id' => $explodedPath[2],
  175.                         ]);
  176.                         if (null !== $operation && !empty($operation->getCategories()->toArray())) {
  177.                             foreach ($user->getCategories() as $category) {
  178.                                 if (\in_array($category$operation->getCategories()->toArray(), true)) {
  179.                                     $rightValue true;
  180.                                     break;
  181.                                 }
  182.                             }
  183.                         } else {
  184.                             $rightValue true;
  185.                         }
  186.                     }
  187.                     if (null !== $user->getBusinessUnits() && !empty($user->getBusinessUnits()->toArray())) {
  188.                         $rightValue false;
  189.                         $explodedPath explode('/'$path);
  190.                         $operation $this->entityManager->getRepository(Operation::class)->findOneBy([
  191.                             'id' => $explodedPath[2],
  192.                         ]);
  193.                         if (null !== $operation && !empty($operation->getBusinessUnits()->toArray())) {
  194.                             foreach ($user->getBusinessUnits()->toArray() as $buKey => $businessUnit) {
  195.                                 if (\in_array($businessUnit$operation->getBusinessUnits()->toArray(), true)) {
  196.                                     $rightValue true;
  197.                                 }
  198.                             }
  199.                         } else {
  200.                             $rightValue true;
  201.                         }
  202.                     }
  203.                 }
  204.             } else {
  205.                 $rightValue false;
  206.             }
  207.         }
  208.         return $rightValue;
  209.     }
  210.     /**
  211.      * @param User|string|array|null $user
  212.      * @param object|string          $entity
  213.      */
  214.     public function checkEntityRight(mixed $userstring $actionmixed $entity): mixed
  215.     {
  216.         if (!\is_object($user)) {
  217.             $user $this->userService->getUser();
  218.         }
  219.         if ('delete' === $action && $entity instanceof Advertiser) {
  220.             if ($this->advertiserService->isDefaultAdvertiser($entity)) {
  221.                 return false;
  222.             }
  223.         }
  224.         if ('delete' === $action && $entity instanceof Role) {
  225.             if (
  226.                 ($entity->getIsAgency() === true && $this->userService->isAdmin($user) !== true)
  227.                 || ($entity->getIsAdmin() === true && $this->userService->isAdmin($user) !== true)
  228.             ) {
  229.                 return false;
  230.             }
  231.         }
  232.         $acces $isAdmin false;
  233.         if (\is_object($entity)) {
  234.             $entityName basename(str_replace('\\''/'$entity::class));
  235.         } elseif (\is_array($entity) && \array_key_exists('entityName'$entity) && \array_key_exists('id'$entity)) {
  236.             $entityName $entity['entityName'];
  237.             $className 'App\Entity\\' $entityName;
  238.             /** @var class-string $className */
  239.             $entity $this->entityManager->getRepository($className)->findOneBy(['id' => $entity['id']]);
  240.         } else {
  241.             $entityName $entity;
  242.         }
  243.         $entityName strtolower($entityName);
  244.         $entityName str_replace('_'''$entityName);
  245.         if (\in_array($entityName, ['operationorderrefrigeratorbin''operationorderanimation''operationorderfurniture'], true)) {
  246.             $entityName 'operationorder';
  247.         }
  248.         if (\in_array($entityName, ['operationrefrigeratorbin''operationanimation''operationfurniture'], true)) {
  249.             $entityName 'operation';
  250.         }
  251.         if (true === $this->requestStack->getSession()->get('advertiserAdmin')) {
  252.             return true;
  253.         }
  254.         $advertiser $this->advertiserService->getCurrentAdvertiser();
  255.         if ('create' !== $action && $user instanceof User && !$this->canAccessEntityInstance($advertiser$entity$user)) {
  256.             return false;
  257.         }
  258.         $rightName '';
  259.         if (true === $this->requestStack->getSession()->get('canAccessAdvertiser')) {
  260.             $rightValue null;
  261.             $userRole $user->getRole();
  262.             if ($userRole instanceof Role) {
  263.                 $rightName 'e_' $userRole->getId() . '_' $entityName '_' $action;
  264.                 $rightValue $this->requestStack->getSession()->get($rightName);
  265.             }
  266.             if (null !== $rightValue) {
  267.                 if ('operationorder' === $entityName) {
  268.                     if ($entity instanceof OperationOrder) {
  269.                         $operationOrderStep $entity->getStep();
  270.                         if (\in_array($action, ['delete''edit'], true) && \in_array($operationOrderStep, ['abandonned''canceled''finished''finishedProblem'], true)) {
  271.                             return false;
  272.                         }
  273.                     }
  274.                 }
  275.                 return $rightValue;
  276.             }
  277.             $advertiser $this->advertiserService->getCurrentAdvertiser();
  278.             if (!$advertiser instanceof Advertiser) {
  279.                 return false;
  280.             }
  281.             $writed $this->writeRightInSession($user$advertiser$rightName);
  282.             if (true === $writed) {
  283.                 $rightValue $this->requestStack->getSession()->get($rightName);
  284.                 if (null !== $rightValue) {
  285.                     return $rightValue;
  286.                 }
  287.                 return false;
  288.             }
  289.         }
  290.         return $acces;
  291.     }
  292.     public function getDefaultUrl(): string
  293.     {
  294.         $user $this->userService->getUser();
  295.         $path '';
  296.         if (!$user instanceof User) {
  297.             $requestUri $this->requestStack->getMainRequest()->server->get('REQUEST_URI');
  298.             $requestUriCleaned preg_replace('/\?.*/''', (string) $requestUri);
  299.             if (\in_array('user_resetpassword'$this->routerService->match($requestUriCleaned), true)) {
  300.                 $path '';
  301.             } else {
  302.                 $path '/login';
  303.                 $this->setRgoto($requestUri);
  304.             }
  305.             $domain $this->advertiserService->getSubdomain();
  306.         } else {
  307.             $userAdvertiser $user->getAdvertiser();
  308.             if ($userAdvertiser->getStatus() === false) {
  309.                 $path '/logout';
  310.                 $domain $this->advertiserService->getSubdomain();
  311.             } else {
  312.                 $domain $userAdvertiser->getSubdomain();
  313.             }
  314.         }
  315.         if ($this->advertiserService->getSubdomain() !== $this->staciSubDomain && $domain === $this->staciSubDomain) {
  316.             return preg_replace('!' $this->advertiserService->getSubdomain() . '.!''', (string) $this->request->server->get('HTTP_HOST')) . $path;
  317.         }
  318.         if ($this->advertiserService->getSubdomain() === $this->staciSubDomain && $domain !== $this->staciSubDomain) {
  319.             return $domain '.' $this->request->server->get('HTTP_HOST') . $path;
  320.         }
  321.         return preg_replace('!' $this->advertiserService->getSubdomain() . '!', (string) $domain, (string) $this->request->server->get('HTTP_HOST')) . $path;
  322.     }
  323.     /**
  324.      * @param User|string|null       $user
  325.      * @param Advertiser|string|null $advertiser
  326.      *
  327.      * @return bool|mixed|string
  328.      */
  329.     public function getFunctionalityRight($user$advertiserstring $functionalityName)
  330.     {
  331.         $result false;
  332.         if (!$user instanceof User) {
  333.             $user $this->userService->getUser();
  334.         }
  335.         if (!$advertiser instanceof Advertiser) {
  336.             $advertiser $this->advertiserService->getCurrentAdvertiser();
  337.         }
  338.         if (!$user instanceof User || !$advertiser instanceof Advertiser) {
  339.             return $result;
  340.         }
  341.         $userRoleID '';
  342.         if (false === $this->userService->isAdmin($user)) {
  343.             $role $user->getRole();
  344.             if ($role instanceof Role) {
  345.                 $userRoleID $role->getId();
  346.             }
  347.         } else {
  348.             return true;
  349.         }
  350.         $rightName 'f_' $userRoleID '_' $functionalityName '_do';
  351.         $rightValue $this->requestStack->getSession()->get($rightName);
  352.         if (null !== $rightValue) {
  353.             $result $rightValue;
  354.         } else {
  355.             $writed $this->writeRightInSession($user$advertiser$rightName);
  356.             if (true === $writed) {
  357.                 $result $this->requestStack->getSession()->get($rightName);
  358.             }
  359.         }
  360.         return $result;
  361.     }
  362.     public function userCanUseApiAgencyOrder(OperationOrder $operationOrderUser $user): bool
  363.     {
  364.         $result false;
  365.         if (true === $user->getIsAgency()) {
  366.             if ($operationOrder->getAgency()->getId() === $user->getAgency()->getId()) {
  367.                 $result true;
  368.             }
  369.         }
  370.         return $result;
  371.     }
  372.     public function agencyCanManageOrder(OperationOrder $operationOrder, ?User $user): bool
  373.     {
  374.         $result false;
  375.         if (!$user instanceof User) {
  376.             $user $this->userService->getUser();
  377.         }
  378.         if (true === $user->getIsAgency() && $operationOrder->getAgency() === $user->getAgency()) {
  379.             $result true;
  380.         }
  381.         return $result;
  382.     }
  383.     public function agencyCanManageOrderAction(OperationOrder $operationOrderUser $userstring $workflowName): bool
  384.     {
  385.         $result false;
  386.         if ($this->agencyCanManageOrder($operationOrder$user) === true) {
  387.             $agency $user->getAgency();
  388.             if ($agency instanceof Agency) {
  389.                 $placesList $this->getAgencyPlaceListAction($user->getAdvertiser(), $agency$workflowName);
  390.                 if (\in_array($operationOrder->getStep(), $placesListtrue)) {
  391.                     $result true;
  392.                 }
  393.             }
  394.         }
  395.         return $result;
  396.     }
  397.     public function agencyCanManageOperation(Operation $operation, ?User $user): bool
  398.     {
  399.         $result false;
  400.         if (!$user instanceof User) {
  401.             $user $this->userService->getUser();
  402.         }
  403.         if (true === $user->getIsAgency() && $operation->getAgencies()->contains($user->getAgency())) {
  404.             $result true;
  405.         }
  406.         return $result;
  407.     }
  408.     public function canModerateOrder(OperationOrder $operationOrder, ?User $user): bool
  409.     {
  410.         $result false;
  411.         if (!$user instanceof User) {
  412.             $user $this->userService->getUser();
  413.         }
  414.         $advertiser $operationOrder->getOperation()->getAdvertiser();
  415.         $rightToModerate $this->getFunctionalityRight($user$advertiser'canModerateOrder');
  416.         if (
  417.             $user->getAdvertiser() === $advertiser
  418.             && ($rightToModerate === true || $rightToModerate === 'yes')
  419.             && \in_array($operationOrder->getStep(), ['toModerate''updateToModerate'], true)
  420.         ) {
  421.             $result true;
  422.         }
  423.         return $result;
  424.     }
  425.     public function render(string $path, array $parametersint $status 200Advertiser $advertiser null): Response
  426.     {
  427.         if ($advertiser === null) {
  428.             $advertiser $this->advertiserService->getCurrentAdvertiser();
  429.         }
  430.         try {
  431.             return new Response($this->twig->render(preg_replace('!\\.!''-' $advertiser->getId() . '.'$path1), $parameters), $status);
  432.         } catch (LoaderError|RuntimeError|SyntaxError $e) {
  433.             return new Response($this->twig->render($path$parameters), $status);
  434.         }
  435.     }
  436.     public function writeRightInSession(User $userAdvertiser $advertiserstring $rightName null): bool
  437.     {
  438.         $writed false;
  439.         $this->requestStack->getSession()->set('advertiserAdmin'false);
  440.         $this->requestStack->getSession()->set('canAccessAdvertiser'false);
  441.         if (null !== $rightName && !empty($rightName)) {
  442.             $this->requestStack->getSession()->set($rightNamefalse);
  443.         }
  444.         $this->requestStack->getSession()->set('advertiser'$advertiser->getId());
  445.         $this->requestStack->getSession()->set('user'$user->getId());
  446.         $operationFamily $this->getUserOperationFamily($advertiser$user);
  447.         if ($operationFamily instanceof OperationFamily) {
  448.             $this->requestStack->getSession()->set('operationFamily'$operationFamily);
  449.         }
  450.         if ($this->userService->isAdvertiserAdmin()) {
  451.             $this->requestStack->getSession()->set('advertiserAdmin'true);
  452.             $this->requestStack->getSession()->set('canAccessAdvertiser'true);
  453.             $writed true;
  454.         } else {
  455.             $role $user->getRole();
  456.             if ($role instanceof Role) {
  457.                 $this->requestStack->getSession()->set('canAccessAdvertiser'true);
  458.                 if (null === $rightName) {
  459.                     $rights $this->advertiserRightService->getRightsByRole($role);
  460.                     foreach ($rights as $rightName => $rightValue) {
  461.                         $this->requestStack->getSession()->set($rightName$rightValue);
  462.                         $writed true;
  463.                     }
  464.                 } else {
  465.                     $rightValue $this->advertiserRightService->getRightByName($rightName);
  466.                     if (!empty($rightValue)) {
  467.                         $this->requestStack->getSession()->set($rightName$rightValue);
  468.                         $writed true;
  469.                     }
  470.                 }
  471.             }
  472.         }
  473.         return $writed;
  474.     }
  475.     public function canMakeOrderComment(OperationOrder $operationOrder): bool
  476.     {
  477.         $result false;
  478.         if ('finished' === $operationOrder->getStep()) {
  479.             $actualTime = new \DateTime();
  480.             if ($operationOrder instanceof OperationOrderAnimation) {
  481.                 $magActionDates $operationOrder->getMagActionDates();
  482.                 if (null !== $magActionDates && !empty($magActionDates->toArray())) {
  483.                     $result true;
  484.                     foreach ($magActionDates->toArray() as $key => $date) {
  485.                         if ($date->getDate()->modify('+10 day') < $actualTime) {
  486.                             $result false;
  487.                         }
  488.                     }
  489.                 }
  490.             } elseif ($operationOrder instanceof OperationOrderRefrigeratorBin || $operationOrder instanceof OperationOrderFurniture) {
  491.                 $recoveryDate $operationOrder->getRecoveryDate();
  492.                 if ($recoveryDate !== null && $recoveryDate->modify('+10 day') > $actualTime) {
  493.                     $result true;
  494.                 }
  495.             }
  496.         }
  497.         return $result;
  498.     }
  499.     public function getRouteFromPath(string $path): string
  500.     {
  501.         $route '';
  502.         try {
  503.             $route $this->routerService->match($path)['_route'];
  504.         } catch (\Exception) {
  505.             // return false;
  506.         }
  507.         return $route;
  508.     }
  509.     public function getMainRequest(): null|Request
  510.     {
  511.         return $this->requestStack->getMainRequest();
  512.     }
  513.     /**
  514.      * @param Advertiser       $advertiser
  515.      * @param object|string    $entity
  516.      * @param \App\Entity\User $user
  517.      */
  518.     public function canAccessEntityInstance($advertiser$entity$user): bool
  519.     {
  520.         if (\is_object($entity)) {
  521.             $entityName basename(str_replace('\\''/'$entity::class));
  522.         } else {
  523.             $entityName $entity;
  524.         }
  525.         $entityName strtolower($entityName);
  526.         $entityName str_replace('_'''$entityName);
  527.         $speEntity = ['operationorder''operationorderComment''operationorderquotaversion''operationorderspeaker''operationoroperationorderStepversionder''quota''user'];
  528.         $acces true;
  529.         if (\in_array($entityName$speEntitytrue)) {
  530.             if (
  531.                 ($entity instanceof OperationOrder && $entity->getOperation()->getAdvertiser() !== $advertiser)
  532.                 || ($entity instanceof OperationOrderComment && $entity->getOperationOrder()->getOperation()->getAdvertiser() !== $advertiser)
  533.                 || ($entity instanceof OperationOrderQuotaVersion && $entity->getOperationOrder()->getOperation()->getAdvertiser() !== $advertiser)
  534.                 || ($entity instanceof OperationOrderStepVersion && $entity->getOperationOrder()->getOperation()->getAdvertiser() !== $advertiser)
  535.                 || ($entity instanceof Quota && $entity->getOperation()->getAdvertiser() !== $advertiser)
  536.                 || ($entity instanceof User && !$this->userService->isUserAdvertiser($advertiser$user))
  537.             ) {
  538.                 $acces false;
  539.             }
  540.         } elseif (\is_object($entity) && method_exists($entity'getAdvertiser') && $entity->getAdvertiser() !== $advertiser) {
  541.             $acces false;
  542.         }
  543.         return $acces;
  544.     }
  545.     public function getAgencyPlaceDatas(Advertiser $advertiser nullAgency $agencystring $workflowName): mixed
  546.     {
  547.         if (null === $advertiser) {
  548.             $advertiser $this->advertiserService->getCurrentAdvertiser();
  549.         }
  550.         $advertiserRef $advertiser->getRef();
  551.         $file sprintf('%s/config/advertisersConfig/' $advertiserRef '/' $workflowName '_agency.yaml'__DIR__ '/../..');
  552.         if (!file_exists($file)) {
  553.             $file sprintf('%s/config/advertisersConfig/default/' $workflowName '_agency.yaml'__DIR__ '/../..');
  554.         }
  555.         return Yaml::parseFile($file);
  556.     }
  557.     public function getAgencyPlaceListShow(Advertiser $advertiserAgency $agencystring $workflowName): array
  558.     {
  559.         $placeList = [];
  560.         $placesDatas $this->getAgencyPlaceDatas($advertiser$agency$workflowName);
  561.         if (\array_key_exists('show'$placesDatas)) {
  562.             $placeList $placesDatas['show'];
  563.         }
  564.         return $placeList;
  565.     }
  566.     public function getAgencyPlaceListEdit(Advertiser $advertiserAgency $agencystring $workflowName): array
  567.     {
  568.         $placeList = [];
  569.         $placesDatas $this->getAgencyPlaceDatas($advertiser$agency$workflowName);
  570.         if (\array_key_exists('edit'$placesDatas)) {
  571.             $placeList $placesDatas['edit'];
  572.         }
  573.         return $placeList;
  574.     }
  575.     public function getAgencyPlaceListAction(Advertiser $advertiserAgency $agencystring $workflowName): array
  576.     {
  577.         $placeList = [];
  578.         $placesDatas $this->getAgencyPlaceDatas($advertiser$agency$workflowName);
  579.         if (\array_key_exists('action'$placesDatas)) {
  580.             $placeList $placesDatas['action'];
  581.         }
  582.         return $placeList;
  583.     }
  584.     public function getUserOperationFamily(Advertiser $advertiserUser $user): ?OperationFamily
  585.     {
  586.         $operationFamily $user->getOperationFamily();
  587.         if ($operationFamily === null || $operationFamily->getAdvertiser() !== $advertiser) {
  588.             $operationFamily $this->entityManager->getRepository(OperationFamily::class)->findOneBy([
  589.                 'advertiser' => $advertiser,
  590.             ]);
  591.         }
  592.         return $operationFamily;
  593.     }
  594.     private function parseSecurityYaml(): void
  595.     {
  596.         $voters $this->customSecurityLoader->load('voters_path');
  597.         $this->anonListUrls $voters['anon'];
  598.         $this->authListUrls $voters['auth'];
  599.         $this->adminListUrls $voters['admin'];
  600.     }
  601.     private function setRgoto(string $url): void
  602.     {
  603.         $sfSession $this->requestStack->getSession();
  604.         $sfSession->set('rgoto'$url);
  605.         $sfSession->save();
  606.     }
  607. }