src/Security/RHFormVoter.php line 103

Open in your IDE?
  1. <?php
  2. //------------------------------------------------------------------------------
  3. // src/Security/RHFormVoter.php
  4. //------------------------------------------------------------------------------
  5. namespace App\Security;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use App\Entity\Access;
  10. use App\Entity\Config\Config;
  11. use App\Entity\Config\Module;
  12. use App\Entity\HR\AccessFunction;
  13. use App\Entity\HR\RHForm\RHForm;
  14. use App\Entity\Platform\Society;
  15. use App\Entity\Security\Acl;
  16. use App\Entity\Security\AclPermission;
  17. use App\Services\Config\ModuleTools;
  18. class RHFormVoter extends Voter
  19. {
  20.     //--------------------------------------------------------------------------------
  21.     // is_granted special constant
  22.     const IS_ACTIVE "rhform_is_active";
  23.     //--------------------------------------------------------------------------------
  24.     // is_granted constants
  25.     const ADD "add_rh_form";
  26.     const ADD_FOR_OTHERS "add_rh_form_for_others";
  27.     const ADD_ANY "add_rh_form_any";
  28.     const ADD_ALL "add_rh_form_all";    // Plan.io Task #462
  29.     const LISTING "list_rh_forms";
  30.     const LISTING_SOCIETY "list_rh_forms_society";
  31.     const LISTING_OWN "list_rh_forms_own";
  32.     const LISTING_ANY "list_rh_forms_any";
  33.     const LISTING_OTHER_THAN_OWN "list_rh_forms_other_than_own";
  34.     const VIEW "view_rh_form";
  35.     const EDIT "edit_rh_form";
  36.     const EDIT_STATUS "edit_rh_form_status";
  37.     const EDIT_DATES "edit_rh_form_dates";
  38.     const EDIT_HOURS "edit_rh_form_hours";
  39.     const DELETE "delete_rh_form";
  40.     const IS_GRANTED_CONSTANTS = array(
  41.         self::IS_ACTIVE,
  42.         self::ADD,
  43.         self::ADD_FOR_OTHERS,
  44.         self::ADD_ANY,
  45.         self::ADD_ALL,
  46.         self::LISTING,
  47.         self::LISTING_SOCIETY,
  48.         self::LISTING_OWN,
  49.         self::LISTING_ANY,
  50.         self::LISTING_OTHER_THAN_OWN,
  51.         self::VIEW,
  52.         self::EDIT,
  53.         self::EDIT_STATUS,
  54.         self::EDIT_DATES,
  55.         self::EDIT_HOURS,
  56.         self::DELETE,
  57.     );
  58.     //--------------------------------------------------------------------------------
  59.     // acl constants
  60.     const ACL_PERM_ADD "rh_form_add";
  61.     const ACL_PERM_ADD_FOR_OTHERS "rh_form_add_for_others";
  62.     const ACL_PERM_ADD_ALL "rh_form_add_all";
  63.     const ACL_PERM_LISTING "rh_form_list";
  64.     const ACL_PERM_LISTING_SOCIETY "rh_form_list_society";
  65.     const ACL_PERM_LISTING_OWN "rh_form_list_own";
  66.     const ACL_PERM_VIEW "rh_form_view";
  67.     const ACL_PERM_VIEW_SOCIETY "rh_form_view_society";
  68.     const ACL_PERM_VIEW_OWN "rh_form_view_own";
  69.     const ACL_PERM_EDIT "rh_form_edit";
  70.     const ACL_PERM_EDIT_SOCIETY "rh_form_edit_society";
  71.     const ACL_PERM_EDIT_OWN "rh_form_edit_own";
  72.     const ACL_PERM_EDIT_STATUS "rh_form_edit_status";
  73.     const ACL_PERM_EDIT_STATUS_SOCIETY "rh_form_edit_status_society";
  74.     const ACL_PERM_EDIT_DATES "rh_form_edit_dates";
  75.     const ACL_PERM_EDIT_DATES_SOCIETY "rh_form_edit_dates_society";
  76.     const ACL_PERM_EDIT_HOURS "rh_form_hours_edit";
  77.     const ACL_PERM_EDIT_HOURS_SOCIETY "rh_form_hours_edit_society";
  78.     //--------------------------------------------------------------------------------
  79.     public function __construct(ManagerRegistry $doctrineModuleTools $moduleTools)
  80.     {
  81.         $this->em $doctrine->getManager();
  82.         $this->moduleTools $moduleTools;
  83.         $this->aclRepository $this->em->getRepository(Acl::class);
  84.         $this->aclPermissionRepository $this->em->getRepository(AclPermission::class);
  85.     }
  86.     // Plan.io Task #4453 [See AccessVoter for details]
  87.     public function supportsAttribute(string $attribute): bool
  88.     {
  89.         return in_array($attributeself::IS_GRANTED_CONSTANTStrue);
  90.     }
  91.     protected function supports(string $attribute$subject null): bool
  92.     {
  93.         // if the attribute isn't one we support, return false
  94.         if (!in_array($attributeself::IS_GRANTED_CONSTANTS))
  95.         {
  96.             return false;
  97.         }
  98.         // only vote on RHForm objects inside this voter
  99.         if ($subject !== null && !$subject instanceof RHForm)
  100.         {
  101.             return false;
  102.         }
  103.         return true;
  104.     }
  105.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  106.     {
  107.         $user $token->getUser();
  108.         if (!$user instanceof Access)
  109.         {
  110.             // the user must be logged in; if not, deny access
  111.             return false;
  112.         }
  113.         // The user must have a function; if not deny access
  114.         $function $user->getFunction();
  115.         if ($function === null)        return false;
  116.         // Plan.io Task #3710 : Get current group
  117.         $currentGroup $user->getSocietyGroup();
  118.         if ($currentGroup === null)
  119.             return false;
  120.         // Module activated ?
  121.         if ($this->moduleTools->isInactiveByCode($currentGroupModule::MODULE_RHFORM))
  122.         {
  123.             return false;
  124.         }
  125.         // you know $subject is a RHForm object, thanks to supports
  126.         /** @var RHForm $rhForm */
  127.         $rhForm $subject;
  128.         // Check current group affectation
  129.         // Exception : own forms
  130.         if ($subject !== null && $subject->getAccess() !== null && !$subject->getAccess()->equals($user))
  131.         {
  132.             $subjectSociety $subject->getSociety();
  133.             if ($subjectSociety === null)
  134.                 return false;
  135.             $subjectGroup $subjectSociety->getGroup();
  136.             if ($subjectGroup === null)
  137.                 return false;
  138.             if (!$currentGroup->equals($subjectGroup))
  139.                 return false;
  140.         }
  141.         switch ($attribute)
  142.         {
  143.             // This is handled in the voteOnAttribute function,
  144.             // if we are here it means that the rhforms option is active
  145.             case self::IS_ACTIVE:
  146.                 return true;
  147.             case self::ADD:
  148.                 return $this->canAdd($user$function);
  149.             case self::ADD_FOR_OTHERS:
  150.                 return $this->canAddForOthers($user$function);
  151.             case self::ADD_ANY:
  152.                 return $this->canAddAny($user$function);
  153.             case self::ADD_ALL:
  154.                 return $this->canAddAll($user$function);
  155.             case self::LISTING:
  156.                 return $this->canList($user$function);
  157.             case self::LISTING_SOCIETY:
  158.                 return $this->canListSociety($user$function);
  159.             case self::LISTING_OWN:
  160.                 return $this->canListOwn($user$function);
  161.             case self::LISTING_ANY:
  162.                 return $this->canListAny($user$function);
  163.             case self::LISTING_OTHER_THAN_OWN:
  164.                 return $this->canListOtherThanOwn($user$function);
  165.             case self::VIEW:
  166.                 return $this->canView($rhForm$user$function);
  167.             case self::EDIT:
  168.                 return $this->canEdit($rhForm$user$function);
  169.             case self::EDIT_STATUS:
  170.                 return $this->canEditStatus($rhForm$user$function);
  171.             case self::EDIT_DATES:
  172.                 return $this->canEditDates($rhForm$user$function);
  173.             case self::EDIT_HOURS:
  174.                 return $this->canEditHours($rhForm$user$function);
  175.             case self::DELETE:
  176.                 return $this->canDelete($rhForm$user$function);
  177.         }
  178.         throw new \LogicException('This code should not be reached!');
  179.     }
  180.     // $access is the user trying to load the resource
  181.     // $rhForm is the resource being loaded
  182.     // Check if the Society of the resource
  183.     // belongs to the societies of the $access
  184.     private function checkSociety(RHForm $rhFormAccess $access)
  185.     {
  186.         // Get all the societies of the access
  187.         $societies $access->getSocieties();
  188.         // Get the Society of the RHForm
  189.         $rhFormSociety $rhForm->getSociety();
  190.         if ($rhFormSociety === null)
  191.             return false;
  192.         $found false;
  193.         foreach ($societies as $society)
  194.         {
  195.             if ($society->getId() == $rhFormSociety->getId())
  196.             {
  197.                 $found true;
  198.                 break;
  199.             }
  200.         }
  201.         return $found;
  202.     }
  203.     // Check if the $access is the author / access of the $rhForm
  204.     private function checkOwn(RHForm $rhFormAccess $access)
  205.     {
  206.         // Get author
  207.         $author $rhForm->getAuthor();
  208.         if ($author === null)
  209.             return false;
  210.         if ($author->getId() === $access->getId())
  211.             return true;
  212.         // Get access
  213.         $theOne $rhForm->getAccess();
  214.         if ($theOne === null)
  215.             return false;
  216.         if ($theOne->getId() === $access->getId())
  217.             return true;
  218.         return false;
  219.     }
  220.     private function canAdd(Access $userAccessFunction $function)
  221.     {
  222.         // Get Acl_Permission
  223.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ADD);
  224.         if ($aclPerm === null)        return false;
  225.         // Get Acl
  226.         $acl $this->aclRepository->findOneBy(array(
  227.             'function'        =>    $function,
  228.             'permission'    =>    $aclPerm
  229.         ));
  230.         if ($acl === null)        return false;
  231.         // Since only one acl type can exist
  232.         // we can return the result of the acl_permission
  233.         return $acl->getValue();
  234.     }
  235.     private function canAddForOthers(Access $userAccessFunction $function)
  236.     {
  237.         // Get Acl_Permission
  238.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ADD_FOR_OTHERS);
  239.         if ($aclPerm === null)        return false;
  240.         // Get Acl
  241.         $acl $this->aclRepository->findOneBy(array(
  242.             'function'        =>    $function,
  243.             'permission'    =>    $aclPerm
  244.         ));
  245.         if ($acl === null)        return false;
  246.         // Since only one acl type can exist
  247.         // we can return the result of the acl_permission
  248.         return $acl->getValue();
  249.     }
  250.     private function canAddAll(Access $userAccessFunction $function)
  251.     {
  252.         // Get Acl_Permission
  253.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ADD_ALL);
  254.         if ($aclPerm === null)        return false;
  255.         // Get Acl
  256.         $acl $this->aclRepository->findOneBy(array(
  257.             'function'        =>    $function,
  258.             'permission'    =>    $aclPerm
  259.         ));
  260.         if ($acl === null)        return false;
  261.         // Since only one acl type can exist
  262.         // we can return the result of the acl_permission
  263.         return $acl->getValue();
  264.     }
  265.     private function canAddAny(Access $userAccessFunction $function)
  266.     {
  267.         // Three Acl_Permission may exist
  268.         // The third one was added for Plan.io Task #4239
  269.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ADD);
  270.         $aclPermOthers $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ADD_FOR_OTHERS);
  271.         $aclPermAll $this->aclPermissionRepository->findOneByName(self::ACL_PERM_ADD_ALL);
  272.         // If all are null, exit
  273.         if ($aclPerm === null && $aclPermOthers === null && $aclPermAll === null)
  274.             return false;
  275.         // Get First one
  276.         if ($aclPerm !== null)
  277.         {
  278.             $acl $this->aclRepository->findOneBy(array(
  279.                 'function'        =>    $function,
  280.                 'permission'    =>    $aclPerm
  281.             ));
  282.             if ($acl !== null)
  283.             {
  284.                 if ($acl->getValue())
  285.                 {
  286.                     // A single positive answer is enough
  287.                     return true;
  288.                 }
  289.             }
  290.         }
  291.         // If we are here it means that nothing good has been found
  292.         // Load second permission
  293.         if ($aclPermOthers !== null)
  294.         {
  295.             $acl $this->aclRepository->findOneBy(array(
  296.                 'function'        =>    $function,
  297.                 'permission'    =>    $aclPermOthers
  298.             ));
  299.             if ($acl !== null)
  300.             {
  301.                 if ($acl->getValue())
  302.                 {
  303.                     // A single positive answer is enough
  304.                     return true;
  305.                 }
  306.             }
  307.         }
  308.         // If we are here it means that nothing good has been found
  309.         // Load third permission
  310.         if ($aclPermAll !== null)
  311.         {
  312.             $acl $this->aclRepository->findOneBy(array(
  313.                 'function'        =>    $function,
  314.                 'permission'    =>    $aclPermAll
  315.             ));
  316.             if ($acl !== null)
  317.             {
  318.                 if ($acl->getValue())
  319.                 {
  320.                     // A single positive answer is enough
  321.                     return true;
  322.                 }
  323.             }
  324.         }
  325.         // If we are here, all hope is lost
  326.         return false;
  327.     }
  328.     private function canList(Access $userAccessFunction $function)
  329.     {
  330.         // Get Acl_Permission
  331.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING);
  332.         if ($aclPerm === null)        return false;
  333.         // Get Acl
  334.         $acl $this->aclRepository->findOneBy(array(
  335.             'function'        =>    $function,
  336.             'permission'    =>    $aclPerm
  337.         ));
  338.         if ($acl === null)        return false;
  339.         // Since only one acl type can exist
  340.         // we can return the result of the acl_permission
  341.         return $acl->getValue();
  342.     }
  343.     private function canListSociety(Access $userAccessFunction $function)
  344.     {
  345.         // Get Acl_Permission
  346.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_SOCIETY);
  347.         if ($aclPerm === null)        return false;
  348.         // Get Acl
  349.         $acl $this->aclRepository->findOneBy(array(
  350.             'function'        =>    $function,
  351.             'permission'    =>    $aclPerm
  352.         ));
  353.         if ($acl === null)        return false;
  354.         // Since only one acl type can exist
  355.         // we can return the result of the acl_permission
  356.         // Further filtering is done in the Controller
  357.         return $acl->getValue();
  358.     }
  359.     private function canListOwn(Access $userAccessFunction $function)
  360.     {
  361.         // Get Acl_Permission
  362.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_OWN);
  363.         if ($aclPerm === null)        return false;
  364.         // Get Acl
  365.         $acl $this->aclRepository->findOneBy(array(
  366.             'function'        =>    $function,
  367.             'permission'    =>    $aclPerm
  368.         ));
  369.         if ($acl === null)        return false;
  370.         // Since only one acl type can exist
  371.         // we can return the result of the acl_permission
  372.         // Further filtering is done in the Controller
  373.         return $acl->getValue();
  374.     }
  375.     private function canListAny(Access $userAccessFunction $function)
  376.     {
  377.         // Two Acl_Permission may exist
  378.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING);
  379.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_SOCIETY);
  380.         $aclPermOwn $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_OWN);
  381.         // If both are null, exit
  382.         if ($aclPerm === null && $aclPermSociety === null && $aclPermOwn === null)
  383.             return false;
  384.         // Get First one
  385.         if ($aclPerm !== null)
  386.         {
  387.             $acl $this->aclRepository->findOneBy(array(
  388.                 'function'        =>    $function,
  389.                 'permission'    =>    $aclPerm
  390.             ));
  391.             if ($acl !== null)
  392.             {
  393.                 if ($acl->getValue())
  394.                 {
  395.                     // A single positive answer is enough
  396.                     return true;
  397.                 }
  398.             }
  399.         }
  400.         // If we are here it means that nothing good has been found
  401.         // Load second permission
  402.         if ($aclPermSociety !== null)
  403.         {
  404.             $acl $this->aclRepository->findOneBy(array(
  405.                 'function'        =>    $function,
  406.                 'permission'    =>    $aclPermSociety
  407.             ));
  408.             if ($acl !== null)
  409.             {
  410.                 if ($acl->getValue())
  411.                 {
  412.                     // A single positive answer is enough
  413.                     return true;
  414.                 }
  415.             }
  416.         }
  417.         // If we are here it means that nothing good has been found
  418.         // Load third permission
  419.         if ($aclPermOwn !== null)
  420.         {
  421.             $acl $this->aclRepository->findOneBy(array(
  422.                 'function'        =>    $function,
  423.                 'permission'    =>    $aclPermOwn
  424.             ));
  425.             if ($acl !== null)
  426.             {
  427.                 if ($acl->getValue())
  428.                 {
  429.                     // A single positive answer is enough
  430.                     return true;
  431.                 }
  432.             }
  433.         }
  434.         // If we are here, all hope is lost
  435.         return false;
  436.     }
  437.     private function canListOtherThanOwn(Access $userAccessFunction $function)
  438.     {
  439.         // Two Acl_Permission may exist
  440.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING);
  441.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_LISTING_SOCIETY);
  442.         // If both are null, exit
  443.         if ($aclPerm === null && $aclPermSociety === null)
  444.             return false;
  445.         // Get First one
  446.         if ($aclPerm !== null)
  447.         {
  448.             $acl $this->aclRepository->findOneBy(array(
  449.                 'function'        =>    $function,
  450.                 'permission'    =>    $aclPerm
  451.             ));
  452.             if ($acl !== null)
  453.             {
  454.                 if ($acl->getValue())
  455.                 {
  456.                     // A single positive answer is enough
  457.                     return true;
  458.                 }
  459.             }
  460.         }
  461.         // If we are here it means that nothing good has been found
  462.         // Load second permission
  463.         if ($aclPermSociety !== null)
  464.         {
  465.             $acl $this->aclRepository->findOneBy(array(
  466.                 'function'        =>    $function,
  467.                 'permission'    =>    $aclPermSociety
  468.             ));
  469.             if ($acl !== null)
  470.             {
  471.                 if ($acl->getValue())
  472.                 {
  473.                     // A single positive answer is enough
  474.                     return true;
  475.                 }
  476.             }
  477.         }
  478.         // If we are here, all hope is lost
  479.         return false;
  480.     }
  481.     private function canView(RHForm $rhFormAccess $userAccessFunction $function)
  482.     {
  483.         // Three Acl_Permission may exist
  484.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW);
  485.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_SOCIETY);
  486.         $aclPermOwn $this->aclPermissionRepository->findOneByName(self::ACL_PERM_VIEW_OWN);
  487.         // If all are null, exit
  488.         if ($aclPerm === null && $aclPermSociety === null && $aclPermOwn === null)
  489.             return false;
  490.         // Get First one
  491.         if ($aclPerm !== null)
  492.         {
  493.             $acl $this->aclRepository->findOneBy(array(
  494.                 'function'        =>    $function,
  495.                 'permission'    =>    $aclPerm
  496.             ));
  497.             if ($acl !== null)
  498.             {
  499.                 if ($acl->getValue())
  500.                 {
  501.                     // A single positive answer is enough
  502.                     return true;
  503.                 }
  504.             }
  505.         }
  506.         // If we are here it means that nothing good has been found
  507.         // Load second permission
  508.         if ($aclPermSociety !== null)
  509.         {
  510.             $acl $this->aclRepository->findOneBy(array(
  511.                 'function'        =>    $function,
  512.                 'permission'    =>    $aclPermSociety
  513.             ));
  514.             if ($acl !== null)
  515.             {
  516.                 if ($acl->getValue())
  517.                 {
  518.                     // A single positive answer is enough
  519.                     // In this case the good answer will be provided by the checkSociety
  520.                     return $this->checkSociety($rhForm$user);
  521.                 }
  522.             }
  523.         }
  524.         // If we are here it means that nothing good has been found
  525.         // Load third permission
  526.         if ($aclPermOwn !== null)
  527.         {
  528.             $acl $this->aclRepository->findOneBy(array(
  529.                 'function'        =>    $function,
  530.                 'permission'    =>    $aclPermOwn
  531.             ));
  532.             if ($acl !== null)
  533.             {
  534.                 if ($acl->getValue())
  535.                 {
  536.                     // A single positive answer is enough
  537.                     // In this case the good answer will be provided by the checkSociety
  538.                     return $this->checkOwn($rhForm$user);
  539.                 }
  540.             }
  541.         }
  542.         // If we are here, all hope is lost
  543.         return false;
  544.     }
  545.     private function canEdit(RHForm $rhFormAccess $userAccessFunction $function)
  546.     {
  547.         // Two Acl_Permission may exist
  548.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT);
  549.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_SOCIETY);
  550.         $aclPermOwn $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_OWN);
  551.         // If all are null, exit
  552.         if ($aclPerm === null && $aclPermSociety === null && $aclPermOwn === null)
  553.             return false;
  554.         // Get First one
  555.         if ($aclPerm !== null)
  556.         {
  557.             $acl $this->aclRepository->findOneBy(array(
  558.                 'function'        =>    $function,
  559.                 'permission'    =>    $aclPerm
  560.             ));
  561.             if ($acl !== null)
  562.             {
  563.                 if ($acl->getValue())
  564.                 {
  565.                     // A single positive answer is enough
  566.                     return true;
  567.                 }
  568.             }
  569.         }
  570.         // If we are here it means that nothing good has been found
  571.         // Load second permission
  572.         if ($aclPermSociety !== null)
  573.         {
  574.             $acl $this->aclRepository->findOneBy(array(
  575.                 'function'        =>    $function,
  576.                 'permission'    =>    $aclPermSociety
  577.             ));
  578.             if ($acl !== null)
  579.             {
  580.                 if ($acl->getValue())
  581.                 {
  582.                     // A single positive answer is enough
  583.                     // In this case the good answer will be provided by the checkSociety
  584.                     return $this->checkSociety($rhForm$user);
  585.                 }
  586.             }
  587.         }
  588.         // If we are here it means that nothing good has been found
  589.         // Load third permission
  590.         if ($aclPermOwn !== null)
  591.         {
  592.             $acl $this->aclRepository->findOneBy(array(
  593.                 'function'        =>    $function,
  594.                 'permission'    =>    $aclPermOwn
  595.             ));
  596.             if ($acl !== null)
  597.             {
  598.                 if ($acl->getValue())
  599.                 {
  600.                     // A single positive answer is enough
  601.                     // In this case the good answer will be provided by the checkSociety
  602.                     return $this->checkOwn($rhForm$user);
  603.                 }
  604.             }
  605.         }
  606.         // If we are here, all hope is lost
  607.         return false;
  608.     }
  609.     private function canEditStatus(RHForm $rhFormAccess $userAccessFunction $function)
  610.     {
  611.         // If annuled no one can edit sttaus
  612.         if ($rhForm->isAnnulled())
  613.             return false;
  614.         // Two Acl_Permission may exist
  615.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_STATUS);
  616.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_STATUS_SOCIETY);
  617.         // If all are null, exit
  618.         if ($aclPerm === null && $aclPermSociety === null)
  619.             return false;
  620.         // Get First one
  621.         if ($aclPerm !== null)
  622.         {
  623.             $acl $this->aclRepository->findOneBy(array(
  624.                 'function'        =>    $function,
  625.                 'permission'    =>    $aclPerm
  626.             ));
  627.             if ($acl !== null)
  628.             {
  629.                 if ($acl->getValue())
  630.                 {
  631.                     // A single positive answer is enough
  632.                     return true;
  633.                 }
  634.             }
  635.         }
  636.         // If we are here it means that nothing good has been found
  637.         // Load second permission
  638.         if ($aclPermSociety !== null)
  639.         {
  640.             $acl $this->aclRepository->findOneBy(array(
  641.                 'function'        =>    $function,
  642.                 'permission'    =>    $aclPermSociety
  643.             ));
  644.             if ($acl !== null)
  645.             {
  646.                 if ($acl->getValue())
  647.                 {
  648.                     // A single positive answer is enough
  649.                     // In this case the good answer will be provided by the checkSociety
  650.                     return $this->checkSociety($rhForm$user);
  651.                 }
  652.             }
  653.         }
  654.         // If we are here, all hope is lost
  655.         return false;
  656.     }
  657.     private function canEditDates(RHForm $rhFormAccess $userAccessFunction $function)
  658.     {
  659.         // If waiting validation, everyone can edit dates
  660.         if ($rhForm->isWaitingValidation())
  661.             return true;
  662.         // If closed or annuled no one can edit dates
  663.         if ($rhForm->isPartiallyClosed() || $rhForm->isClosed() || $rhForm->isAnnulled())
  664.             return false;
  665.         // Two Acl_Permission may exist
  666.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_DATES);
  667.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_DATES_SOCIETY);
  668.         // If all are null, exit
  669.         if ($aclPerm === null && $aclPermSociety === null)
  670.             return false;
  671.         // Get First one
  672.         if ($aclPerm !== null)
  673.         {
  674.             $acl $this->aclRepository->findOneBy(array(
  675.                 'function'        =>    $function,
  676.                 'permission'    =>    $aclPerm
  677.             ));
  678.             if ($acl !== null)
  679.             {
  680.                 if ($acl->getValue())
  681.                 {
  682.                     // A single positive answer is enough
  683.                     return true;
  684.                 }
  685.             }
  686.         }
  687.         // If we are here it means that nothing good has been found
  688.         // Load second permission
  689.         if ($aclPermSociety !== null)
  690.         {
  691.             $acl $this->aclRepository->findOneBy(array(
  692.                 'function'        =>    $function,
  693.                 'permission'    =>    $aclPermSociety
  694.             ));
  695.             if ($acl !== null)
  696.             {
  697.                 if ($acl->getValue())
  698.                 {
  699.                     // A single positive answer is enough
  700.                     // In this case the good answer will be provided by the checkSociety
  701.                     return $this->checkSociety($rhForm$user);
  702.                 }
  703.             }
  704.         }
  705.         // If we are here, all hope is lost
  706.         return false;
  707.     }
  708.     private function canEditHours(RHForm $rhFormAccess $userAccessFunction $function)
  709.     {
  710.         // Only available for RHForm_Hours
  711.         if ($rhForm->isHours() === false)
  712.             return false;
  713.         // Two Acl_Permission may exist
  714.         $aclPerm $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_HOURS);
  715.         $aclPermSociety $this->aclPermissionRepository->findOneByName(self::ACL_PERM_EDIT_HOURS_SOCIETY);
  716.         // If all are null, exit
  717.         if ($aclPerm === null && $aclPermSociety === null)
  718.             return false;
  719.         // Get First one
  720.         if ($aclPerm !== null)
  721.         {
  722.             $acl $this->aclRepository->findOneBy(array(
  723.                 'function'        =>    $function,
  724.                 'permission'    =>    $aclPerm
  725.             ));
  726.             if ($acl !== null)
  727.             {
  728.                 if ($acl->getValue())
  729.                 {
  730.                     // A single positive answer is enough
  731.                     return true;
  732.                 }
  733.             }
  734.         }
  735.         // If we are here it means that nothing good has been found
  736.         // Load second permission
  737.         if ($aclPermSociety !== null)
  738.         {
  739.             $acl $this->aclRepository->findOneBy(array(
  740.                 'function'        =>    $function,
  741.                 'permission'    =>    $aclPermSociety
  742.             ));
  743.             if ($acl !== null)
  744.             {
  745.                 if ($acl->getValue())
  746.                 {
  747.                     // A single positive answer is enough
  748.                     // In this case the good answer will be provided by the checkSociety
  749.                     return $this->checkSociety($rhForm$user);
  750.                 }
  751.             }
  752.         }
  753.         // If we are here, all hope is lost
  754.         return false;
  755.     }
  756.     private function canDelete(RHForm $rhFormAccess $userAccessFunction $function)
  757.     {
  758.         return false;
  759.     }
  760. }