src/Security/DevisVoter.php line 160

Open in your IDE?
  1. <?php
  2. //------------------------------------------------------------------------------
  3. // src/Security/DevisVoter.php
  4. //------------------------------------------------------------------------------
  5. namespace App\Security;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
  8. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. use App\Entity\Access;
  11. use App\Entity\APIRest\AccessAPI;
  12. use App\Entity\Config\Config;
  13. use App\Entity\Config\Module;
  14. use App\Entity\HR\AccessFunction;
  15. use App\Entity\Planning\Task;
  16. use App\Entity\Platform\Devis\Devis;
  17. use App\Entity\Mission\Mission;
  18. use App\Entity\Security\Acl;
  19. use App\Entity\Security\AclPermission;
  20. use App\Services\LogTools;
  21. use App\Services\Config\ModuleTools;
  22. use App\Services\Config\OptionConfigTools;
  23. class DevisVoter extends Voter
  24. {
  25.     // For now manager = author (both)
  26.     //--------------------------------------------------------------------------------
  27.     // is_granted constants
  28.     const IS_ACTIVE "devis_is_active";
  29.     const ADD "add_devis";
  30.     // Plan.io Task #3605
  31.     const ADD_GHOST "add_ghost_devis";
  32.     const EDIT_GHOST "edit_ghost_devis";
  33.     // Plan.io Task #3633
  34.     // This is to allow users to manually update the products of a ghost devis
  35.     // without actually modifying the original devis
  36.     const UPDATE_GHOST "update_ghost_devis";
  37.     const LISTING "list_devis";
  38.     const LISTING_SOCIETY "list_devis_society";
  39.     const LISTING_MANAGER "list_devis_manager";
  40.     const LISTING_ANY "list_devis_any";
  41.     const VIEW "view_devis";
  42.     const VIEW_PDF_HT_INTERNAL "view_pdf_devis_ht_internal";
  43.     const VIEW_PDF_HT_PUBLIC "view_pdf_devis_ht_public";
  44.     const VIEW_PDF_TTC_PUBLIC "view_pdf_devis_ttc_public";
  45.     const VIEW_PDF_NO_PRICE "view_pdf_devis_no_price";
  46.     const VIEW_PDF_WITH_PRICE "view_pdf_devis_with_price";
  47.     const EDIT "edit_devis";
  48.     const DELETE "delete_devis";
  49.     const ANNUL "annul_devis";
  50.     const REVIVE "revive_devis";
  51.     // Plan.io Task #3621
  52.     const EDIT_IKEA_OS_FROM_TASK "edit_devis_ikea_order_number_from_task";
  53.     const IS_GRANTED_CONSTANTS = array(
  54.         self::IS_ACTIVE,
  55.         self::ADD,
  56.         self::LISTING,
  57.         self::LISTING_SOCIETY,
  58.         self::LISTING_MANAGER,
  59.         self::LISTING_ANY,
  60.         self::VIEW,
  61.         self::VIEW_PDF_HT_INTERNAL,
  62.         self::VIEW_PDF_HT_PUBLIC,
  63.         self::VIEW_PDF_TTC_PUBLIC,
  64.         self::VIEW_PDF_NO_PRICE,
  65.         self::VIEW_PDF_WITH_PRICE,
  66.         self::EDIT,
  67.         self::DELETE,
  68.         self::ANNUL,
  69.         self::REVIVE,
  70.         // Plan.io Task #3605
  71.         self::ADD_GHOST,
  72.         self::EDIT_GHOST,
  73.         // Plan.io Task #3633
  74.         self::UPDATE_GHOST,
  75.         // Plan.io Task #3621
  76.         self::EDIT_IKEA_OS_FROM_TASK,
  77.     );
  78.     const IS_GRANTED_CONSTANTS_SHARING_EXCEPTION = array(
  79.         self::VIEW,
  80.         self::VIEW_PDF_HT_INTERNAL,
  81.         self::VIEW_PDF_HT_PUBLIC,
  82.         self::VIEW_PDF_TTC_PUBLIC,
  83.         self::VIEW_PDF_NO_PRICE,
  84.     );
  85.     //--------------------------------------------------------------------------------
  86.     // acl constants
  87.     const ACL_PERM_ADD "devis_add";
  88.     // Plan.io Task #3633
  89.     const ACL_PERM_UPDATE_GHOST "ghost_devis_update";
  90.     const ACL_PERM_LISTING "devis_list";
  91.     const ACL_PERM_LISTING_SOCIETY "devis_list_society";
  92.     const ACL_PERM_LISTING_MANAGER "devis_list_manager";
  93.     const ACL_PERM_VIEW "devis_view";
  94.     const ACL_PERM_VIEW_SOCIETY "devis_view_society";
  95.     const ACL_PERM_VIEW_MANAGER "devis_view_manager";
  96.     const ACL_PERM_VIEW_CLIENT_MANAGER "devis_view_ind_manager";
  97.     const ACL_PERM_VIEW_IF_TASK "devis_view_if_task";
  98.     const ACL_PERM_EDIT "devis_edit";
  99.     const ACL_PERM_EDIT_SOCIETY "devis_edit_society";
  100.     const ACL_PERM_EDIT_MANAGER "devis_edit_manager";
  101.     const ACL_PERM_EDIT_CLIENT_MANAGER "devis_edit_ind_manager";
  102.     const ACL_PERM_EDIT_IF_TASK "devis_edit_if_task";
  103.     const ACL_PERM_ANNUL "devis_annul";
  104.     const ACL_PERM_ANNUL_SOCIETY "devis_annul_society";
  105.     const ACL_PERM_REVIVE "devis_revive";
  106.     const ACL_PERM_REVIVE_SOCIETY "devis_revive_society";
  107.     const ACL_PERM_VIEW_PDF_HT_INTERNAL "devis_view_pdf_ht_internal";
  108.     const ACL_PERM_VIEW_PDF_HT_INTERNAL_SOCIETY "devis_view_pdf_ht_internal_society";
  109.     const ACL_PERM_VIEW_PDF_HT_INTERNAL_MANAGER "devis_view_pdf_ht_internal_manager";
  110.     const ACL_PERM_VIEW_PDF_HT_INTERNAL_CLIENT_MANAGER "devis_view_pdf_ht_internal_ind_manager";
  111.     const ACL_PERM_VIEW_PDF_HT_PUBLIC "devis_view_pdf_ht_public";
  112.     const ACL_PERM_VIEW_PDF_HT_PUBLIC_SOCIETY "devis_view_pdf_ht_public_society";
  113.     const ACL_PERM_VIEW_PDF_HT_PUBLIC_MANAGER "devis_view_pdf_ht_public_manager";
  114.     const ACL_PERM_VIEW_PDF_HT_PUBLIC_CLIENT_MANAGER "devis_view_pdf_ht_public_ind_manager";
  115.     const ACL_PERM_VIEW_PDF_TTC_PUBLIC "devis_view_pdf_ttc_public";
  116.     const ACL_PERM_VIEW_PDF_TTC_PUBLIC_SOCIETY "devis_view_pdf_ttc_public_society";
  117.     const ACL_PERM_VIEW_PDF_TTC_PUBLIC_MANAGER "devis_view_pdf_ttc_public_manager";
  118.     const ACL_PERM_VIEW_PDF_TTC_PUBLIC_CLIENT_MANAGER "devis_view_pdf_ttc_public_ind_manager";
  119.     const ACL_PERM_VIEW_PDF_NO_PRICE "devis_view_pdf_no_price_public";
  120.     const ACL_PERM_VIEW_PDF_NO_PRICE_SOCIETY "devis_view_pdf_no_price_public_society";
  121.     const ACL_PERM_VIEW_PDF_NO_PRICE_MANAGER "devis_view_pdf_no_price_public_manager";
  122.     const ACL_PERM_VIEW_PDF_NO_PRICE_CLIENT_MANAGER "devis_view_pdf_no_price_public_ind_manager";
  123.     //--------------------------------------------------------------------------------
  124.     public function __construct(AccessDecisionManagerInterface $accessDecisionManagerManagerRegistry $doctrineModuleTools $moduleToolsOptionConfigTools $optionConfigToolsLogTools $logTools)
  125.     {
  126.         $this->accessDecisionManager $accessDecisionManager;
  127.         $this->em $doctrine->getManager();
  128.         $this->moduleTools $moduleTools;
  129.         $this->optionConfigTools $optionConfigTools;
  130.         $this->logTools $logTools;
  131.         $this->aclRepository $this->em->getRepository(Acl::class);
  132.         $this->aclPermissionRepository $this->em->getRepository(AclPermission::class);
  133.     }
  134.     // Plan.io Task #4453 [See AccessVoter for details]
  135.     public function supportsAttribute(string $attribute): bool
  136.     {
  137.         return in_array($attributeself::IS_GRANTED_CONSTANTStrue);
  138.     }
  139.     
  140.     protected function supports(string $attribute$subject): bool
  141.     {
  142.         // if the attribute isn't one we support, return false
  143.         if (!in_array($attributeself::IS_GRANTED_CONSTANTS))
  144.         {
  145.             return false;
  146.         }
  147.         // Only vote on Devis and Mission objects inside this voter
  148.         if ($subject !== null && !($subject instanceof Devis || $subject instanceof Mission))
  149.         {
  150.             return false;
  151.         }
  152.         return true;
  153.     }
  154.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  155.     {
  156.         $user $token->getUser();
  157.         // Plan.io Task #3707
  158.         if ($user instanceof AccessAPI)
  159.         {
  160.             if ($user->getAccess() === null)
  161.             {
  162.                 return false;
  163.             }
  164.             $user $user->getAccess();
  165.         }
  166.         // Plan.io Task #3707
  167.         // At this point $user is an object of Access type
  168.         // even if the $token->getUser() is AccessAPI
  169.         if (!$user instanceof Access)
  170.         {
  171.             // the user must be logged in; if not, deny access
  172.             return false;
  173.         }
  174.         // The user must have a function; if not deny access
  175.         $function $user->getFunction();
  176.         if ($function === null)        return false;
  177.         // Plan.io Task #3710 : Get current group
  178.         $currentGroup $user->getSocietyGroup();
  179.         if ($currentGroup === null)
  180.             return false;
  181.         $this->currentGroup $currentGroup;
  182.         // Module activated ?
  183.         if ($this->moduleTools->isInactiveByCode($currentGroupModule::MODULE_DEVIS))
  184.         {
  185.             return false;
  186.         }
  187.         // Required modules : Misison, Product
  188.         if ($this->moduleTools->isInactiveByCode($currentGroupModule::MODULE_MISSION) && $this->moduleTools->isInactiveByCode($currentGroupModule::MODULE_MISSION_LIGHT) && $this->moduleTools->isInactiveByCode($currentGroupModule::MODULE_MISSION_PLUS))
  189.         {
  190.             return false;
  191.         }
  192.         if ($this->moduleTools->isInactiveByCode($currentGroupModule::MODULE_PRODUCT))
  193.         {
  194.             return false;
  195.         }
  196.         $devis null;
  197.         $mission null;
  198.         if ($subject instanceof Devis)
  199.         {
  200.             /** @var Devis $devis */
  201.             $devis $subject;
  202.             // Check current group affectation
  203.             // Make an exception for "view/pdf" : take sharing into account
  204.             if ($devis !== null)
  205.             {
  206.                 $devisSociety $devis->getSociety();
  207.                 if ($devisSociety === null)
  208.                     return false;
  209.                 $devisSocietyGroup $devisSociety->getGroup();
  210.                 if ($devisSocietyGroup === null)
  211.                     return false;
  212.                 if (!in_array($attributeself::IS_GRANTED_CONSTANTS_SHARING_EXCEPTION))
  213.                 {
  214.                     // Just check currentGroup
  215.                     if (!$currentGroup->equals($devisSocietyGroup))
  216.                         return false;
  217.                 }
  218.                 else
  219.                 {
  220.                     // Take sharing into account
  221.                     // If the devis belongs to a mission that was created by the currentGroup
  222.                     // (devis.mission.societyGroupAuthor == currentGroup)
  223.                     // Then it can see the devis
  224.                     if (!$currentGroup->equals($devisSocietyGroup))
  225.                     {
  226.                         if ($devis->getMission() !== null)
  227.                         {
  228.                             $missionSocietyGroupAuthor $devis->getMission()->getSocietyGroupAuthor();
  229.                             if (!$currentGroup->equals($missionSocietyGroupAuthor))
  230.                             {
  231.                                 return false;
  232.                             }
  233.                         }
  234.                     }
  235.                 }
  236.             }
  237.         }
  238.         else
  239.         {
  240.             if ($subject instanceof Mission)
  241.             {
  242.                 /** @var Mission $mission */
  243.                 $mission $subject;
  244.                 // Plan.io Task #3517
  245.                 // Adding a devis counts as editing a mission
  246.                 // So check if the current user has access to this mission
  247.                 // If this is too restrictive, change 'edit_mission' with 'view_mission'
  248.                 // 'view_mission' is better ;)
  249.                 if (!$this->accessDecisionManager->decide($token, ['view_mission'], $mission))
  250.                 {
  251.                     return false;
  252.                 }
  253.             }
  254.         }
  255.         switch ($attribute)
  256.         {
  257.             case self::IS_ACTIVE:
  258.                 return true;
  259.             // We are only adding devis for missions, so this makes sense
  260.             case self::ADD:
  261.                 return $this->canAdd($mission$user$function);
  262.             // Plan.io Task #3605
  263.             case self::ADD_GHOST:
  264.                 return $this->canAddGhost($devis$user$function);
  265.             case self::EDIT_GHOST:
  266.                 return $this->canEditGhost($devis$user$function);
  267.             // Plan.io Task #3633
  268.             case self::UPDATE_GHOST:
  269.                 return $this->canUpdateGhost($devis$user$function);
  270.             case self::LISTING:
  271.                 return $this->canList($user$function);
  272.             case self::LISTING_SOCIETY:
  273.                 return $this->canListSociety($user$function);
  274.             case self::LISTING_MANAGER:
  275.                 return $this->canListManager($user$function);
  276.             case self::LISTING_ANY:
  277.                 return $this->canListAny($user$function);
  278.             case self::VIEW:
  279.                 return $this->canView($devis$user$function);
  280.             case self::VIEW_PDF_HT_INTERNAL:
  281.                 return $this->canViewPdfHtInternal($devis$user$function);
  282.             case self::VIEW_PDF_HT_PUBLIC:
  283.                 return $this->canViewPdfHtPublic($devis$user$function);
  284.             case self::VIEW_PDF_TTC_PUBLIC:
  285.                 return $this->canViewPdfTtcPublic($devis$user$function);
  286.             case self::VIEW_PDF_NO_PRICE:
  287.                 return $this->canViewPdfNoPrice($devis$user$function);
  288.             case self::VIEW_PDF_WITH_PRICE:
  289.                 return $this->canViewPdfWithPrice($devis$user$function);
  290.             case self::EDIT:
  291.                 return $this->canEdit($devis$user$function$currentGroup);
  292.             case self::DELETE:
  293.                 return $this->canDelete($devis$user$function);
  294.             case self::ANNUL:
  295.                 return $this->canAnnul($devis$user$function$currentGroup);
  296.             case self::REVIVE:
  297.                 return $this->canRevive($devis$user$function$currentGroup);
  298.             // Plan.io Task #3621
  299.             case self::EDIT_IKEA_OS_FROM_TASK:
  300.                 return $this->canEditIkeaDataFromTask($devis$user$function$currentGroup);
  301.         }
  302.         throw new \LogicException('This code should not be reached!');
  303.     }
  304.     // $access is the user trying to load the resource
  305.     // $devis is the resource being loaded
  306.     // Check if the Society of the resource
  307.     // belongs to the societies of the $access
  308.     private function checkSociety(Devis $devisAccess $access)
  309.     {
  310.         // Get all the societies of the access
  311.         $societies $access->getSocieties();
  312.         // Get the Society of the Devis
  313.         $devisSociety $devis->getSociety();
  314.         if ($devisSociety === null)
  315.             return false;
  316.         $found false;
  317.         foreach ($societies as $society)
  318.         {
  319.             if ($society->getId() == $devisSociety->getId())
  320.             {
  321.                 $found true;
  322.                 break;
  323.             }
  324.         }
  325.         return $found;
  326.     }
  327.     // Check if the $access is the manager / author of the $devis
  328.     private function checkManager(Devis $devisAccess $access)
  329.     {
  330.         // Get manager
  331.         $manager $devis->getManager();
  332.         $author $devis->getAuthor();
  333.         if ($manager === null && $author === null)
  334.             return false;
  335.         if ($manager !== null)
  336.             if ($manager->getId() === $access->getId())
  337.                 return true;
  338.         if ($author !== null)
  339.             if ($author->getId() === $access->getId())
  340.                 return true;
  341.         return false;
  342.     }
  343.     // Check if the $access is the manager of the $devis
  344.     private function checkClientManager(Devis $devisAccess $access)
  345.     {
  346.         // Get Client
  347.         $client $devis->getReceiver();
  348.         if ($client === null)
  349.             return false;
  350.         if ($client->getIndividual() !== null)
  351.         {
  352.             // Only Individuals have managers
  353.             // Get manager
  354.             $manager $devis->getReceiver()->getIndividual()->getManager();
  355.             if ($manager === null)
  356.                 return false;
  357.             if ($manager->getId() === $access->getId())
  358.                 return true;
  359.         }
  360.         return false;
  361.     }
  362.     // Check if there is at least one task
  363.     // having this access as resource and this devis
  364.     private function checkTask(Devis $devisAccess $access)
  365.     {
  366.         $taskRep $this->em->getRepository(Task::class);
  367.         $resources $access->getPlanningResources();
  368.         foreach ($resources as $r)
  369.         {
  370.             $tasks $taskRep->findForDevisAndResource($devis$r);
  371.             if (count($tasks) > 0)
  372.                 return true;
  373.         }
  374.         return false;
  375.     }
  376.     private function canAdd(Mission $missionAccess $userAccessFunction $function)
  377.     {
  378.         // Deny actions on archivedRefused objects
  379.         if ($mission->isArchivedRefused())
  380.         {
  381.             return false;
  382.         }
  383.         // If the mission is shared and the author is the current group, deny adding devis
  384.         // When a mission is shared, the author cannot edit it
  385.         if ($mission->isShared())
  386.         {
  387.             if ($mission->isSharedBySocietyGroup($this->currentGroup))
  388.             {
  389.                 return false;
  390.             }
  391.         }
  392.         // Get Acl_Permission
  393.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ADD);
  394.         if ($aclPerm === null)        return false;
  395.         // Get Acl
  396.         $acl $this->aclRepository->findOneBy(array(
  397.             'function'        =>    $function,
  398.             'permission'    =>    $aclPerm
  399.         ));
  400.         if ($acl === null)        return false;
  401.         // Since only one acl type can exist
  402.         // we can return the result of the acl_permission
  403.         return $acl->getValue();
  404.     }
  405.     // Plan.io Task #3605
  406.     private function canAddGhost(Devis $devisAccess $userAccessFunction $function)
  407.     {
  408.         if (!$this->optionConfigTools->isActive_GhostInvoicing($this->currentGroup))
  409.         {
  410.             return false;
  411.         }
  412.         if ($devis->getGhost() !== null)
  413.         {
  414.             return false;
  415.         }
  416.         if (!$this->canAdd($devis->getMission(), $user$function))
  417.         {
  418.             return false;
  419.         }
  420.         $template $devis->getTemplate();
  421.         if ($template === null)
  422.         {
  423.             return false;
  424.         }
  425.         if ($template->hasProductWithInvoicingProduct())
  426.         {
  427.             return true;
  428.         }
  429.         return false;
  430.     }
  431.     // Plan.io Task #3605
  432.     private function canEditGhost(Devis $devisAccess $userAccessFunction $function)
  433.     {
  434.         if ($devis->getGhost() === null)
  435.         {
  436.             return false;
  437.         }
  438.         if (!$this->canEdit($devis$user$function$this->currentGroup))
  439.         {
  440.             return false;
  441.         }
  442.         $template $devis->getTemplate();
  443.         if ($template === null)
  444.         {
  445.             return false;
  446.         }
  447.         if ($template->hasProductWithInvoicingProduct())
  448.         {
  449.             return true;
  450.         }
  451.         return false;
  452.     }
  453.     // Plan.io Task #3633
  454.     private function canUpdateGhost(Devis $devisAccess $userAccessFunction $function)
  455.     {
  456.         if ($devis->getGhost() === null)
  457.         {
  458.             return false;
  459.         }
  460.         // Get Acl_Permission
  461.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_UPDATE_GHOST);
  462.         if ($aclPerm === null)        return false;
  463.         // Get Acl
  464.         $acl $this->aclRepository->findOneBy(array(
  465.             'function'        =>    $function,
  466.             'permission'    =>    $aclPerm
  467.         ));
  468.         if ($acl === null)        return false;
  469.         // Since only one acl type can exist
  470.         // we can return the result of the acl_permission
  471.         return $acl->getValue();
  472.     }
  473.     private function canList(Access $userAccessFunction $function)
  474.     {
  475.         // Get Acl_Permission
  476.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING);
  477.         if ($aclPerm === null)        return false;
  478.         // Get Acl
  479.         $acl $this->aclRepository->findOneBy(array(
  480.             'function'        =>    $function,
  481.             'permission'    =>    $aclPerm
  482.         ));
  483.         if ($acl === null)        return false;
  484.         // Since only one acl type can exist
  485.         // we can return the result of the acl_permission
  486.         return $acl->getValue();
  487.     }
  488.     private function canListSociety(Access $userAccessFunction $function)
  489.     {
  490.         // Get Acl_Permission
  491.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_SOCIETY);
  492.         if ($aclPerm === null)        return false;
  493.         // Get Acl
  494.         $acl $this->aclRepository->findOneBy(array(
  495.             'function'        =>    $function,
  496.             'permission'    =>    $aclPerm
  497.         ));
  498.         if ($acl === null)        return false;
  499.         // Since only one acl type can exist
  500.         // we can return the result of the acl_permission
  501.         // Further filtering is done in the Controller
  502.         return $acl->getValue();
  503.     }
  504.     private function canListManager(Access $userAccessFunction $function)
  505.     {
  506.         // Get Acl_Permission
  507.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_MANAGER);
  508.         if ($aclPerm === null)        return false;
  509.         // Get Acl
  510.         $acl $this->aclRepository->findOneBy(array(
  511.             'function'        =>    $function,
  512.             'permission'    =>    $aclPerm
  513.         ));
  514.         if ($acl === null)        return false;
  515.         // Since only one acl type can exist
  516.         // we can return the result of the acl_permission
  517.         // Further filtering is done in the Controller
  518.         return $acl->getValue();
  519.     }
  520.     private function canListAny(Access $userAccessFunction $function)
  521.     {
  522.         // Three Acl_Permission may exist
  523.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING);
  524.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_SOCIETY);
  525.         $aclPermManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_MANAGER);
  526.         // If all are null, exit
  527.         if ($aclPerm === null && $aclPermSociety === null && $aclPermManager === null)
  528.             return false;
  529.         // Get First one
  530.         if ($aclPerm !== null)
  531.         {
  532.             $acl $this->aclRepository->findOneBy(array(
  533.                 'function'        =>    $function,
  534.                 'permission'    =>    $aclPerm
  535.             ));
  536.             if ($acl !== null)
  537.             {
  538.                 if ($acl->getValue())
  539.                 {
  540.                     // A single positive answer is enough
  541.                     return true;
  542.                 }
  543.             }
  544.         }
  545.         // If we are here it means that nothing good has been found
  546.         // Load second permission
  547.         if ($aclPermSociety !== null)
  548.         {
  549.             $acl $this->aclRepository->findOneBy(array(
  550.                 'function'        =>    $function,
  551.                 'permission'    =>    $aclPermSociety
  552.             ));
  553.             if ($acl !== null)
  554.             {
  555.                 if ($acl->getValue())
  556.                 {
  557.                     // A single positive answer is enough
  558.                     return true;
  559.                 }
  560.             }
  561.         }
  562.         // If we are here it means that nothing good has been found
  563.         // Load third permission
  564.         if ($aclPermManager !== null)
  565.         {
  566.             $acl $this->aclRepository->findOneBy(array(
  567.                 'function'        =>    $function,
  568.                 'permission'    =>    $aclPermManager
  569.             ));
  570.             if ($acl !== null)
  571.             {
  572.                 if ($acl->getValue())
  573.                 {
  574.                     // A single positive answer is enough
  575.                     return true;
  576.                 }
  577.             }
  578.         }
  579.         // If we are here, all hope is lost
  580.         return false;
  581.     }
  582.     private function canView(Devis $devis nullAccess $userAccessFunction $function)
  583.     {
  584.         // Get Acl_Permissions
  585.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW);
  586.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_SOCIETY);
  587.         $aclPermManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_MANAGER);
  588.         $aclPermClientManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_CLIENT_MANAGER);
  589.         $aclPermIfTask $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_IF_TASK);
  590.         // If all are null, exit
  591.         if ($aclPerm === null && $aclPermSociety === null && $aclPermManager === null && $aclPermClientManager === null && $aclPermIfTask === null)
  592.             return false;
  593.         // The aclPermIfTask should be checked first, and if it is false, the others should be cheked
  594.         // ($aclPerm ^ $aclPermSociety ^ $aclPermManager ^ $aclPermClientManager) = empty
  595.         // ($aclPerm ^ $aclPermSociety ^ $aclPermManager ^ $aclPermClientManager) ^ $aclPermIfTask = not empty
  596.         // This means that an user can have access to the devis of his society
  597.         // and also have access to the devis realted to his tasks
  598.         if ($aclPermIfTask !== null)
  599.         {
  600.             $acl $this->aclRepository->findOneBy(array(
  601.                 'function'        =>    $function,
  602.                 'permission'    =>    $aclPermIfTask
  603.             ));
  604.             if ($acl !== null)
  605.             {
  606.                 if ($acl->getValue())
  607.                 {
  608.                     if ($this->checkTask($devis$user))
  609.                         return true;
  610.                 }
  611.             }
  612.         }
  613.         // If we are here it means that the user doesn't have access to the Devis
  614.         // by the bias of one of his tasks
  615.         // So check regular permissions next
  616.         // Get First one
  617.         if ($aclPerm !== null)
  618.         {
  619.             $acl $this->aclRepository->findOneBy(array(
  620.                 'function'        =>    $function,
  621.                 'permission'    =>    $aclPerm
  622.             ));
  623.             if ($acl !== null)
  624.             {
  625.                 if ($acl->getValue())
  626.                 {
  627.                     // A single positive answer is enough
  628.                     return true;
  629.                 }
  630.             }
  631.         }
  632.         // If we are here it means that nothing good has been found
  633.         // Load second permission
  634.         if ($aclPermSociety !== null)
  635.         {
  636.             $acl $this->aclRepository->findOneBy(array(
  637.                 'function'        =>    $function,
  638.                 'permission'    =>    $aclPermSociety
  639.             ));
  640.             if ($acl !== null)
  641.             {
  642.                 if ($acl->getValue())
  643.                 {
  644.                     // A single positive answer is enough
  645.                     // In this case the good answer will be provided by the checkSociety
  646.                     return $this->checkSociety($devis$user);
  647.                 }
  648.             }
  649.         }
  650.         // If we are here it means that nothing good has been found
  651.         // Load third permission
  652.         if ($aclPermManager !== null)
  653.         {
  654.             $acl $this->aclRepository->findOneBy(array(
  655.                 'function'        =>    $function,
  656.                 'permission'    =>    $aclPermManager
  657.             ));
  658.             if ($acl !== null)
  659.             {
  660.                 if ($acl->getValue())
  661.                 {
  662.                     // A single positive answer is enough
  663.                     // In this case the good answer will be provided by the checkSociety
  664.                     return $this->checkManager($devis$user);
  665.                 }
  666.             }
  667.         }
  668.         // If we are here it means that nothing good has been found
  669.         // Load fourth permission
  670.         if ($aclPermClientManager !== null)
  671.         {
  672.             $acl $this->aclRepository->findOneBy(array(
  673.                 'function'        =>    $function,
  674.                 'permission'    =>    $aclPermClientManager
  675.             ));
  676.             if ($acl !== null)
  677.             {
  678.                 if ($acl->getValue())
  679.                 {
  680.                     // A single positive answer is enough
  681.                     // In this case the good answer will be provided by the checkSociety
  682.                     return $this->checkClientManager($devis$user);
  683.                 }
  684.             }
  685.         }
  686.         // If we are here, all hope is lost
  687.         return false;
  688.     }
  689.     private function canViewPdfHtInternal(Devis $devis nullAccess $userAccessFunction $function)
  690.     {
  691.         // Unfinished Simulations
  692.         if ($devis->getReceiver() === null)
  693.             return false;
  694.         // Four Acl_Permission may exist
  695.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_INTERNAL);
  696.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_INTERNAL_SOCIETY);
  697.         $aclPermManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_INTERNAL_MANAGER);
  698.         $aclPermClientManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_INTERNAL_CLIENT_MANAGER);
  699.         // If all are null, exit
  700.         if ($aclPerm === null && $aclPermSociety === null && $aclPermManager === null && $aclPermClientManager === null)
  701.             return false;
  702.         // Get First one
  703.         if ($aclPerm !== null)
  704.         {
  705.             $acl $this->aclRepository->findOneBy(array(
  706.                 'function'        =>    $function,
  707.                 'permission'    =>    $aclPerm
  708.             ));
  709.             if ($acl !== null)
  710.             {
  711.                 if ($acl->getValue())
  712.                 {
  713.                     // A single positive answer is enough
  714.                     return true;
  715.                 }
  716.             }
  717.         }
  718.         // If we are here it means that nothing good has been found
  719.         // Load second permission
  720.         if ($aclPermSociety !== null)
  721.         {
  722.             $acl $this->aclRepository->findOneBy(array(
  723.                 'function'        =>    $function,
  724.                 'permission'    =>    $aclPermSociety
  725.             ));
  726.             if ($acl !== null)
  727.             {
  728.                 if ($acl->getValue())
  729.                 {
  730.                     // A single positive answer is enough
  731.                     // In this case the good answer will be provided by the checkSociety
  732.                     return $this->checkSociety($devis$user);
  733.                 }
  734.             }
  735.         }
  736.         // If we are here it means that nothing good has been found
  737.         // Load third permission
  738.         if ($aclPermManager !== null)
  739.         {
  740.             $acl $this->aclRepository->findOneBy(array(
  741.                 'function'        =>    $function,
  742.                 'permission'    =>    $aclPermManager
  743.             ));
  744.             if ($acl !== null)
  745.             {
  746.                 if ($acl->getValue())
  747.                 {
  748.                     // A single positive answer is enough
  749.                     // In this case the good answer will be provided by the checkSociety
  750.                     return $this->checkManager($devis$user);
  751.                 }
  752.             }
  753.         }
  754.         // If we are here it means that nothing good has been found
  755.         // Load fourth permission
  756.         if ($aclPermClientManager !== null)
  757.         {
  758.             $acl $this->aclRepository->findOneBy(array(
  759.                 'function'        =>    $function,
  760.                 'permission'    =>    $aclPermClientManager
  761.             ));
  762.             if ($acl !== null)
  763.             {
  764.                 if ($acl->getValue())
  765.                 {
  766.                     // A single positive answer is enough
  767.                     // In this case the good answer will be provided by the checkSociety
  768.                     return $this->checkClientManager($devis$user);
  769.                 }
  770.             }
  771.         }
  772.         // If we are here, all hope is lost
  773.         return false;
  774.     }
  775.     private function canViewPdfHtPublic(Devis $devis nullAccess $userAccessFunction $function)
  776.     {
  777.         // Unfinished Simulations
  778.         if ($devis->getReceiver() === null)
  779.             return false;
  780.         // Four Acl_Permission may exist
  781.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_PUBLIC);
  782.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_PUBLIC_SOCIETY);
  783.         $aclPermManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_PUBLIC_MANAGER);
  784.         $aclPermClientManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_HT_PUBLIC_CLIENT_MANAGER);
  785.         // If all are null, exit
  786.         if ($aclPerm === null && $aclPermSociety === null && $aclPermManager === null && $aclPermClientManager === null)
  787.             return false;
  788.         // Get First one
  789.         if ($aclPerm !== null)
  790.         {
  791.             $acl $this->aclRepository->findOneBy(array(
  792.                 'function'        =>    $function,
  793.                 'permission'    =>    $aclPerm
  794.             ));
  795.             if ($acl !== null)
  796.             {
  797.                 if ($acl->getValue())
  798.                 {
  799.                     // A single positive answer is enough
  800.                     return true;
  801.                 }
  802.             }
  803.         }
  804.         // If we are here it means that nothing good has been found
  805.         // Load second permission
  806.         if ($aclPermSociety !== null)
  807.         {
  808.             $acl $this->aclRepository->findOneBy(array(
  809.                 'function'        =>    $function,
  810.                 'permission'    =>    $aclPermSociety
  811.             ));
  812.             if ($acl !== null)
  813.             {
  814.                 if ($acl->getValue())
  815.                 {
  816.                     // A single positive answer is enough
  817.                     // In this case the good answer will be provided by the checkSociety
  818.                     return $this->checkSociety($devis$user);
  819.                 }
  820.             }
  821.         }
  822.         // If we are here it means that nothing good has been found
  823.         // Load third permission
  824.         if ($aclPermManager !== null)
  825.         {
  826.             $acl $this->aclRepository->findOneBy(array(
  827.                 'function'        =>    $function,
  828.                 'permission'    =>    $aclPermManager
  829.             ));
  830.             if ($acl !== null)
  831.             {
  832.                 if ($acl->getValue())
  833.                 {
  834.                     // A single positive answer is enough
  835.                     // In this case the good answer will be provided by the checkSociety
  836.                     return $this->checkManager($devis$user);
  837.                 }
  838.             }
  839.         }
  840.         // If we are here it means that nothing good has been found
  841.         // Load fourth permission
  842.         if ($aclPermClientManager !== null)
  843.         {
  844.             $acl $this->aclRepository->findOneBy(array(
  845.                 'function'        =>    $function,
  846.                 'permission'    =>    $aclPermClientManager
  847.             ));
  848.             if ($acl !== null)
  849.             {
  850.                 if ($acl->getValue())
  851.                 {
  852.                     // A single positive answer is enough
  853.                     // In this case the good answer will be provided by the checkSociety
  854.                     return $this->checkClientManager($devis$user);
  855.                 }
  856.             }
  857.         }
  858.         // If we are here, all hope is lost
  859.         return false;
  860.     }
  861.     private function canViewPdfTtcPublic(Devis $devis nullAccess $userAccessFunction $function)
  862.     {
  863.         // Unfinished Simulations
  864.         // if ($devis->getReceiver() === null)
  865.         //     return false;
  866.         // Four Acl_Permission may exist
  867.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_TTC_PUBLIC);
  868.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_TTC_PUBLIC_SOCIETY);
  869.         $aclPermManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_TTC_PUBLIC_MANAGER);
  870.         $aclPermClientManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_TTC_PUBLIC_CLIENT_MANAGER);
  871.         // If all are null, exit
  872.         if ($aclPerm === null && $aclPermSociety === null && $aclPermManager === null && $aclPermClientManager === null)
  873.             return false;
  874.         // Get First one
  875.         if ($aclPerm !== null)
  876.         {
  877.             $acl $this->aclRepository->findOneBy(array(
  878.                 'function'        =>    $function,
  879.                 'permission'    =>    $aclPerm
  880.             ));
  881.             if ($acl !== null)
  882.             {
  883.                 if ($acl->getValue())
  884.                 {
  885.                     // A single positive answer is enough
  886.                     return true;
  887.                 }
  888.             }
  889.         }
  890.         // If we are here it means that nothing good has been found
  891.         // Load second permission
  892.         if ($aclPermSociety !== null)
  893.         {
  894.             $acl $this->aclRepository->findOneBy(array(
  895.                 'function'        =>    $function,
  896.                 'permission'    =>    $aclPermSociety
  897.             ));
  898.             if ($acl !== null)
  899.             {
  900.                 if ($acl->getValue())
  901.                 {
  902.                     // A single positive answer is enough
  903.                     // In this case the good answer will be provided by the checkSociety
  904.                     return $this->checkSociety($devis$user);
  905.                 }
  906.             }
  907.         }
  908.         // If we are here it means that nothing good has been found
  909.         // Load third permission
  910.         if ($aclPermManager !== null)
  911.         {
  912.             $acl $this->aclRepository->findOneBy(array(
  913.                 'function'        =>    $function,
  914.                 'permission'    =>    $aclPermManager
  915.             ));
  916.             if ($acl !== null)
  917.             {
  918.                 if ($acl->getValue())
  919.                 {
  920.                     // A single positive answer is enough
  921.                     // In this case the good answer will be provided by the checkSociety
  922.                     return $this->checkManager($devis$user);
  923.                 }
  924.             }
  925.         }
  926.         // If we are here it means that nothing good has been found
  927.         // Load fourth permission
  928.         if ($aclPermClientManager !== null)
  929.         {
  930.             $acl $this->aclRepository->findOneBy(array(
  931.                 'function'        =>    $function,
  932.                 'permission'    =>    $aclPermClientManager
  933.             ));
  934.             if ($acl !== null)
  935.             {
  936.                 if ($acl->getValue())
  937.                 {
  938.                     // A single positive answer is enough
  939.                     // In this case the good answer will be provided by the checkSociety
  940.                     return $this->checkClientManager($devis$user);
  941.                 }
  942.             }
  943.         }
  944.         // If we are here, all hope is lost
  945.         return false;
  946.     }
  947.     private function canViewPdfNoPrice(Devis $devis nullAccess $userAccessFunction $function)
  948.     {
  949.         // Unfinished Simulations
  950.         // if ($devis->getReceiver() === null)
  951.         //     return false;
  952.         // Four Acl_Permission may exist
  953.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_NO_PRICE);
  954.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_NO_PRICE_SOCIETY);
  955.         $aclPermManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_NO_PRICE_MANAGER);
  956.         $aclPermClientManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_PDF_NO_PRICE_CLIENT_MANAGER);
  957.         // If all are null, exit
  958.         if ($aclPerm === null && $aclPermSociety === null && $aclPermManager === null && $aclPermClientManager === null)
  959.             return false;
  960.         // Get First one
  961.         if ($aclPerm !== null)
  962.         {
  963.             $acl $this->aclRepository->findOneBy(array(
  964.                 'function'        =>    $function,
  965.                 'permission'    =>    $aclPerm
  966.             ));
  967.             if ($acl !== null)
  968.             {
  969.                 if ($acl->getValue())
  970.                 {
  971.                     // A single positive answer is enough
  972.                     return true;
  973.                 }
  974.             }
  975.         }
  976.         // If we are here it means that nothing good has been found
  977.         // Load second permission
  978.         if ($aclPermSociety !== null)
  979.         {
  980.             $acl $this->aclRepository->findOneBy(array(
  981.                 'function'        =>    $function,
  982.                 'permission'    =>    $aclPermSociety
  983.             ));
  984.             if ($acl !== null)
  985.             {
  986.                 if ($acl->getValue())
  987.                 {
  988.                     // A single positive answer is enough
  989.                     // In this case the good answer will be provided by the checkSociety
  990.                     return $this->checkSociety($devis$user);
  991.                 }
  992.             }
  993.         }
  994.         // If we are here it means that nothing good has been found
  995.         // Load third permission
  996.         if ($aclPermManager !== null)
  997.         {
  998.             $acl $this->aclRepository->findOneBy(array(
  999.                 'function'        =>    $function,
  1000.                 'permission'    =>    $aclPermManager
  1001.             ));
  1002.             if ($acl !== null)
  1003.             {
  1004.                 if ($acl->getValue())
  1005.                 {
  1006.                     // A single positive answer is enough
  1007.                     // In this case the good answer will be provided by the checkSociety
  1008.                     return $this->checkManager($devis$user);
  1009.                 }
  1010.             }
  1011.         }
  1012.         // If we are here it means that nothing good has been found
  1013.         // Load fourth permission
  1014.         if ($aclPermClientManager !== null)
  1015.         {
  1016.             $acl $this->aclRepository->findOneBy(array(
  1017.                 'function'        =>    $function,
  1018.                 'permission'    =>    $aclPermClientManager
  1019.             ));
  1020.             if ($acl !== null)
  1021.             {
  1022.                 if ($acl->getValue())
  1023.                 {
  1024.                     // A single positive answer is enough
  1025.                     // In this case the good answer will be provided by the checkSociety
  1026.                     return $this->checkClientManager($devis$user);
  1027.                 }
  1028.             }
  1029.         }
  1030.         // If we are here, all hope is lost
  1031.         return false;
  1032.     }
  1033.     // Plan.io Task #3621
  1034.     private function canEditConditions(Devis $devis)
  1035.     {
  1036.         // Plan.io Task #4329
  1037.         if ($devis->hasDrafts())
  1038.         {
  1039.             return false;
  1040.         }
  1041.         // Plan.io Task #3793
  1042.         if ($devis->hasSignature())
  1043.         {
  1044.             return false;
  1045.         }
  1046.         // Deny edit on archivedRefused objects
  1047.         if ($devis->isArchivedRefused())
  1048.         {
  1049.             return false;
  1050.         }
  1051.         // Deny for an annulled devis
  1052.         if ($devis->isAnnulled())
  1053.         {
  1054.             return false;
  1055.         }
  1056.         // Deny for a devis that is partially or totally invoiced
  1057.         if ($devis->isInvoiced() || $devis->isPartiallyInvoiced())
  1058.         {
  1059.             return false;
  1060.         }
  1061.         // If the Devis has been sent to the Rekto Platform, deny edit
  1062.         if ($devis->getRemoteId() !== null)
  1063.         {
  1064.             return false;
  1065.         }
  1066.         // Unfinished Simulations
  1067.         if ($devis->getReceiver() === null)
  1068.         {
  1069.             return false;
  1070.         }
  1071.         return true;
  1072.     }
  1073.     private function canViewPdfWithPrice(Devis $devis nullAccess $userAccessFunction $function)
  1074.     {
  1075.         if ($this->canViewPdfHtPublic($devis$user$function))
  1076.         {
  1077.             return true;
  1078.         }
  1079.         if ($this->canViewPdfHtPublic($devis$user$function))
  1080.         {
  1081.             return true;
  1082.         }
  1083.         if ($this->canViewPdfTtcPublic($devis$user$function))
  1084.         {
  1085.             return true;
  1086.         }
  1087.         // If we are here, all hope is lost
  1088.         return false;
  1089.     }
  1090.     private function canEdit(Devis $devis nullAccess $userAccessFunction $function$currentGroup$withConditions true)
  1091.     {
  1092.         // Plan.io Task #3621
  1093.         if ($withConditions)
  1094.         {
  1095.             if (!$this->canEditConditions($devis))
  1096.             {
  1097.                 return false;
  1098.             }
  1099.         }
  1100.         // Get Acl_Permissions
  1101.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT);
  1102.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_SOCIETY);
  1103.         $aclPermManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_MANAGER);
  1104.         $aclPermClientManager $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_CLIENT_MANAGER);
  1105.         $aclPermIfTask $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_IF_TASK);
  1106.         // If all are null, exit
  1107.         if ($aclPerm === null && $aclPermSociety === null && $aclPermManager === null && $aclPermClientManager === null && $aclPermIfTask === null)
  1108.             return false;
  1109.         // The aclPermIfTask should be checked first, and if it is false, the others should be cheked
  1110.         // ($aclPerm ^ $aclPermSociety ^ $aclPermManager ^ $aclPermClientManager) = empty
  1111.         // ($aclPerm ^ $aclPermSociety ^ $aclPermManager ^ $aclPermClientManager) ^ $aclPermIfTask = not empty
  1112.         // This means that an user can have access to the devis of his society
  1113.         // and also have access to the devis realted to his tasks
  1114.         if ($aclPermIfTask !== null)
  1115.         {
  1116.             $acl $this->aclRepository->findOneBy(array(
  1117.                 'function'        =>    $function,
  1118.                 'permission'    =>    $aclPermIfTask
  1119.             ));
  1120.             if ($acl !== null)
  1121.             {
  1122.                 if ($acl->getValue())
  1123.                 {
  1124.                     if ($this->checkTask($devis$user))
  1125.                         return true;
  1126.                 }
  1127.             }
  1128.         }
  1129.         // If we are here it means that the user doesn't have access to the Devis
  1130.         // by the bias of one of his tasks
  1131.         // So check regular permissions next
  1132.         // Get First one
  1133.         if ($aclPerm !== null)
  1134.         {
  1135.             $acl $this->aclRepository->findOneBy(array(
  1136.                 'function'        =>    $function,
  1137.                 'permission'    =>    $aclPerm
  1138.             ));
  1139.             if ($acl !== null)
  1140.             {
  1141.                 if ($acl->getValue())
  1142.                 {
  1143.                     // A single positive answer is enough
  1144.                     return true;
  1145.                 }
  1146.             }
  1147.         }
  1148.         // If we are here it means that nothing good has been found
  1149.         // Load second permission
  1150.         if ($aclPermSociety !== null)
  1151.         {
  1152.             $acl $this->aclRepository->findOneBy(array(
  1153.                 'function'        =>    $function,
  1154.                 'permission'    =>    $aclPermSociety
  1155.             ));
  1156.             if ($acl !== null)
  1157.             {
  1158.                 if ($acl->getValue())
  1159.                 {
  1160.                     // A single positive answer is enough
  1161.                     // In this case the good answer will be provided by the checkSociety
  1162.                     return $this->checkSociety($devis$user);
  1163.                 }
  1164.             }
  1165.         }
  1166.         // If we are here it means that nothing good has been found
  1167.         // Load third permission
  1168.         if ($aclPermManager !== null)
  1169.         {
  1170.             $acl $this->aclRepository->findOneBy(array(
  1171.                 'function'        =>    $function,
  1172.                 'permission'    =>    $aclPermManager
  1173.             ));
  1174.             if ($acl !== null)
  1175.             {
  1176.                 if ($acl->getValue())
  1177.                 {
  1178.                     // A single positive answer is enough
  1179.                     // In this case the good answer will be provided by the checkSociety
  1180.                     return $this->checkManager($devis$user);
  1181.                 }
  1182.             }
  1183.         }
  1184.         // If we are here it means that nothing good has been found
  1185.         // Load fourth permission
  1186.         if ($aclPermClientManager !== null)
  1187.         {
  1188.             $acl $this->aclRepository->findOneBy(array(
  1189.                 'function'        =>    $function,
  1190.                 'permission'    =>    $aclPermClientManager
  1191.             ));
  1192.             if ($acl !== null)
  1193.             {
  1194.                 if ($acl->getValue())
  1195.                 {
  1196.                     // A single positive answer is enough
  1197.                     // In this case the good answer will be provided by the checkSociety
  1198.                     return $this->checkClientManager($devis$user);
  1199.                 }
  1200.             }
  1201.         }
  1202.         // If we are here, all hope is lost
  1203.         return false;
  1204.     }
  1205.     private function canDelete(Devis $devis nullAccess $userAccessFunction $function)
  1206.     {
  1207.         return false;
  1208.     }
  1209.     private function canAnnul(Devis $devis nullAccess $userAccessFunction $function$currentGroup)
  1210.     {
  1211.         // Plan.io Task #4329
  1212.         if ($devis->hasDrafts())
  1213.         {
  1214.             return false;
  1215.         }
  1216.         // Deny for an annulled devis
  1217.         if ($devis->isAnnulled())
  1218.             return false;
  1219.         // Deny for a devis that is partially or totally invoiced
  1220.         if ($devis->isInvoiced() || $devis->isPartiallyInvoiced())
  1221.             return false;
  1222.         // Get Acl_Permissions
  1223.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ANNUL);
  1224.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ANNUL_SOCIETY);
  1225.         // If all are null, exit
  1226.         if ($aclPerm === null && $aclPermSociety === null)
  1227.             return false;
  1228.         // Get First one
  1229.         if ($aclPerm !== null)
  1230.         {
  1231.             $acl $this->aclRepository->findOneBy(array(
  1232.                 'function'        =>    $function,
  1233.                 'permission'    =>    $aclPerm
  1234.             ));
  1235.             if ($acl !== null)
  1236.             {
  1237.                 if ($acl->getValue())
  1238.                 {
  1239.                     // A single positive answer is enough
  1240.                     return true;
  1241.                 }
  1242.             }
  1243.         }
  1244.         // If we are here it means that nothing good has been found
  1245.         // Load second permission
  1246.         if ($aclPermSociety !== null)
  1247.         {
  1248.             $acl $this->aclRepository->findOneBy(array(
  1249.                 'function'        =>    $function,
  1250.                 'permission'    =>    $aclPermSociety
  1251.             ));
  1252.             if ($acl !== null)
  1253.             {
  1254.                 if ($acl->getValue())
  1255.                 {
  1256.                     // A single positive answer is enough
  1257.                     // In this case the good answer will be provided by the checkSociety
  1258.                     return $this->checkSociety($devis$user);
  1259.                 }
  1260.             }
  1261.         }
  1262.         // If we are here, all hope is lost
  1263.         return false;
  1264.     }
  1265.     private function canRevive(Devis $devis nullAccess $userAccessFunction $function$currentGroup)
  1266.     {
  1267.         // Deny reviving a devis that is not annulled
  1268.         if ($devis->isAnnulled() == false)
  1269.             return false;
  1270.         // Get Acl_Permissions
  1271.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_REVIVE);
  1272.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_REVIVE_SOCIETY);
  1273.         // If all are null, exit
  1274.         if ($aclPerm === null && $aclPermSociety === null)
  1275.             return false;
  1276.         // Get First one
  1277.         if ($aclPerm !== null)
  1278.         {
  1279.             $acl $this->aclRepository->findOneBy(array(
  1280.                 'function'        =>    $function,
  1281.                 'permission'    =>    $aclPerm
  1282.             ));
  1283.             if ($acl !== null)
  1284.             {
  1285.                 if ($acl->getValue())
  1286.                 {
  1287.                     // A single positive answer is enough
  1288.                     return true;
  1289.                 }
  1290.             }
  1291.         }
  1292.         // If we are here it means that nothing good has been found
  1293.         // Load second permission
  1294.         if ($aclPermSociety !== null)
  1295.         {
  1296.             $acl $this->aclRepository->findOneBy(array(
  1297.                 'function'        =>    $function,
  1298.                 'permission'    =>    $aclPermSociety
  1299.             ));
  1300.             if ($acl !== null)
  1301.             {
  1302.                 if ($acl->getValue())
  1303.                 {
  1304.                     // A single positive answer is enough
  1305.                     // In this case the good answer will be provided by the checkSociety
  1306.                     return $this->checkSociety($devis$user);
  1307.                 }
  1308.             }
  1309.         }
  1310.         // If we are here, all hope is lost
  1311.         return false;
  1312.     }
  1313.     // Plan.io Task #3621
  1314.     private function canEditIkeaDataFromTask(Devis $devis$user$function$currentGroup)
  1315.     {
  1316.         return $this->canEdit($devis$user$function$currentGroupfalse);
  1317.     }
  1318. }