Commit 27e2c1af authored by root's avatar root
Browse files

Merge branch 'master' of https://git.unicaen.fr/dsi/preecog

parents ca7576df 6668c9fe
Loading
Loading
Loading
Loading
+11
Changes for module/Application/config/merged/agent.config.php: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ return [
                    'controller' => AgentController::class,
                    'action' => [
                        'rechercher',
                        'rechercher-large',
                        'rechercher-with-structure-mere',
                        'rechercher-responsable',
                        'rechercher-gestionnaire',
@@ -229,6 +230,16 @@ return [
                            ],
                        ],
                    ],
                    'rechercher-large' => [
                        'type'  => Literal::class,
                        'options' => [
                            'route'    => '/rechercher-large',
                            'defaults' => [
                                'controller' => AgentController::class,
                                'action'     => 'rechercher-large',
                            ],
                        ],
                    ],
                    'rechercher-with-structure-mere' => [
                        'type'  => Segment::class,
                        'options' => [
+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
+10
Changes for module/Application/src/Application/Controller/AgentController.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -395,6 +395,16 @@ class AgentController extends AbstractActionController

    /** Recherche d'agent  ********************************************************************************************/

    public function rechercherLargeAction() : JsonModel
    {
        if (($term = $this->params()->fromQuery('term'))) {
            $agents = $this->getAgentService()->getAgentsLargeByTerm($term);
            $result = $this->getAgentService()->formatAgentJSON($agents);
            return new JsonModel($result);
        }
        exit;
    }

    public function rechercherAction() : JsonModel
    {
        if (($term = $this->params()->fromQuery('term'))) {
+2 −1
Changes for module/Application/src/Application/Controller/ComplementController.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ class ComplementController extends AbstractActionController {
            case Complement::COMPLEMENT_TYPE_RESPONSABLE :
            case Complement::COMPLEMENT_TYPE_AUTORITE :
                $complement->setComplementType(Agent::class);
                $form->get('sas')->setAutocompleteSource($this->url()->fromRoute('agent/rechercher', [], [], true));
                /** @see AgentController::rechercherAction() */
                $form->get('sas')->setAutocompleteSource($this->url()->fromRoute('agent/rechercher-large', [], [], true));
                break;
            case Complement::COMPLEMENT_TYPE_STRUCTURE :
                $complement->setComplementType(Structure::class);
Loading