Commit 736d73c2 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Début d'assertion de route sur les agents

parent 77c11697
Loading
Loading
Loading
Loading
+63 −3
Changes for module/Application/src/Application/Assertion/AgentAssertion.php: 63 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -10,9 +10,11 @@ use Structure\Provider\RoleProvider;
use Structure\Service\Structure\StructureServiceAwareTrait;
use UnicaenPrivilege\Assertion\AbstractAssertion;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Permissions\Acl\Resource\ResourceInterface;

class AgentAssertion extends AbstractAssertion {
class AgentAssertion extends AbstractAssertion
{
    use AgentServiceAwareTrait;
    use StructureServiceAwareTrait;
    use UserServiceAwareTrait;
@@ -30,12 +32,14 @@ class AgentAssertion extends AbstractAssertion {
        $role = $this->getUserService()->getConnectedRole();



        $structures = [];
        foreach ($entity->getAffectations() as $affectation) {
            $structures[] = $affectation->getStructure();
        }
        $isResponsable = false; $isGestionnaire = false; $isSuperieur = false; $isAutorite = false;
        $isResponsable = false;
        $isGestionnaire = false;
        $isSuperieur = false;
        $isAutorite = false;
        if ($role->getRoleId() === RoleProvider::RESPONSABLE) $isResponsable = $this->getStructureService()->isResponsableS($structures, $agent);
        if ($role->getRoleId() === RoleProvider::GESTIONNAIRE) $isGestionnaire = $this->getStructureService()->isGestionnaireS($structures, $agent);
        if ($role->getRoleId() === Agent::ROLE_SUPERIEURE) $isSuperieur = $entity->hasSuperieurHierarchique($agent);
@@ -105,4 +109,60 @@ class AgentAssertion extends AbstractAssertion {

        return true;
    }

    /**
     * @param AbstractActionController $controller
     * @param $action
     * @param $privilege
     * @return bool
     */
    protected function assertController($controller, $action = null, $privilege = null): bool
    {
        $user = $this->getUserService()->getConnectedUser();
        $agent = $this->getAgentService()->getAgentByUser($user);
        $role = $this->getUserService()->getConnectedRole();

        /** @var Agent|null $entity */
        $entity = null;
        if ($agent) {
            $agentId = (($this->getMvcEvent()->getRouteMatch()->getParam('agent')));
            $entity = $this->getAgentService()->getAgent($agentId);
        }

        $structures = [];
        foreach ($entity->getAffectations() as $affectation) {
            $structures[] = $affectation->getStructure();
        }
        $isResponsable = false;
        $isGestionnaire = false;
        $isSuperieur = false;
        $isAutorite = false;
        if ($role->getRoleId() === RoleProvider::RESPONSABLE) $isResponsable = $this->getStructureService()->isResponsableS($structures, $agent);
        if ($role->getRoleId() === RoleProvider::GESTIONNAIRE) $isGestionnaire = $this->getStructureService()->isGestionnaireS($structures, $agent);
        if ($role->getRoleId() === Agent::ROLE_SUPERIEURE) $isSuperieur = $entity->hasSuperieurHierarchique($agent);
        if ($role->getRoleId() === Agent::ROLE_AUTORITE) $isAutorite = $entity->hasAutoriteHierarchique($agent);

        switch ($action) {
            case 'afficher' :
            case 'afficher-statuts-grades' :
            switch ($role->getRoleId()) {
                case RoleConstant::ADMIN_TECH :
                case RoleConstant::ADMIN_FONC :
                case RoleConstant::OBSERVATEUR :
                    return true;
                case RoleProvider::RESPONSABLE:
                    return $isResponsable;
                case RoleProvider::GESTIONNAIRE:
                    return $isGestionnaire;
                case Agent::ROLE_SUPERIEURE:
                    return $isSuperieur;
                case Agent::ROLE_AUTORITE:
                    return $isAutorite;
                case Agent::ROLE_AGENT :
                    return $entity === $agent;
            }
            return false;
        }
        return true;
    }
}
 No newline at end of file
+5
Changes for module/Application/src/Application/Assertion/AgentAssertionFactory.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Application\Service\Agent\AgentService;
use Interop\Container\ContainerInterface;
use Structure\Service\Structure\StructureService;
use UnicaenUtilisateur\Service\User\UserService;
use Zend\Mvc\Application;

class AgentAssertionFactory {

@@ -30,6 +31,10 @@ class AgentAssertionFactory {
        $assertion->setStructureService($structureService);
        $assertion->setUserService($userService);

        /* @var $application Application */
        $application = $container->get('Application');
        $mvcEvent    = $application->getMvcEvent();
        $assertion->setMvcEvent($mvcEvent);
        return $assertion;
    }
}
 No newline at end of file