Commit 802f1212 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout du rôle de responsable de structure

parent b7399b80
Loading
Loading
Loading
Loading
+26 −0
Changes for module/Application/config/merged/structure.config.php: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ return [
                    'action' => [
                        'ajouter-gestionnaire',
                        'retirer-gestionnaire',
                        'ajouter-responsable',
                        'retirer-responsable',
                    ],
                    'privileges' => StructurePrivileges::STRUCTURE_GESTIONNAIRE,
                    'assertion'  => StructureAssertion::class,
@@ -172,6 +174,30 @@ return [
                        'may_terminate' => true,
                        'child_routes' => [],
                    ],
                    'ajouter-responsable' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/ajouter-responsable/:structure',
                            'defaults' => [
                                'controller' => StructureController::class,
                                'action'     => 'ajouter-responsable',
                            ],
                        ],
                        'may_terminate' => true,
                        'child_routes' => [],
                    ],
                    'retirer-responsable' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/retirer-responsable/:structure/:responsable',
                            'defaults' => [
                                'controller' => StructureController::class,
                                'action'     => 'retirer-responsable',
                            ],
                        ],
                        'may_terminate' => true,
                        'child_routes' => [],
                    ],
                    'editer-description' => [
                        'type'  => Segment::class,
                        'options' => [
+17 −0
Changes for module/Application/src/Application/Assertion/AgentAssertion.php: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,17 @@ class AgentAssertion extends AbstractAssertion {
                if ($isGestionnaire) break;
            }
        }
        $isResponsable = false;
        if ($role->getRoleId === RoleConstant::RESPONSABLE) {
            $structures = [];
            foreach ($entity->getGrades() as $grade) {
                $structures[] = $grade->getStructure();
            }
            foreach ($structures as $structure) {
                $isResponsable = $this->getStructureService()->isResponsable($structure, $user);
                if ($isResponsable) break;
            }
        }

        switch($privilege) {
            case AgentPrivileges::AGENT_ELEMENT_VOIR:
@@ -48,6 +59,8 @@ class AgentAssertion extends AbstractAssertion {
                        return ($entity->getUtilisateur() === $user);
                    case RoleConstant::GESTIONNAIRE:
                        return $isGestionnaire;
                    case RoleConstant::RESPONSABLE:
                        return $isResponsable;
                }
                return false;
            case AgentPrivileges::AGENT_ELEMENT_AJOUTER:
@@ -61,6 +74,8 @@ class AgentAssertion extends AbstractAssertion {
                        return ($entity->getUtilisateur() === $user) AND $entity->hasEntretienEnCours();
                    case RoleConstant::GESTIONNAIRE:
                            return $isGestionnaire;
                    case RoleConstant::RESPONSABLE:
                        return $isResponsable;
                }
                return false;
            case AgentPrivileges::AGENT_ELEMENT_DETRUIRE:
@@ -78,6 +93,8 @@ class AgentAssertion extends AbstractAssertion {
                        return true;
                    case RoleConstant::GESTIONNAIRE:
                        return $isGestionnaire;
                    case RoleConstant::RESPONSABLE:
                        return $isResponsable;
                }
                return false;
        }
+16 −0
Changes for module/Application/src/Application/Assertion/EntretienProfessionnelAssertion.php: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Application\Entity\Db\Agent;
use Application\Entity\Db\EntretienProfessionnel;
use Application\Provider\Privilege\AgentPrivileges;
use Application\Provider\Privilege\EntretienproPrivileges;
use Application\Service\Structure\StructureServiceAwareTrait;
use UnicaenAuthentification\Assertion\AbstractAssertion;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
use Zend\Permissions\Acl\Resource\ResourceInterface;
@@ -14,6 +15,7 @@ use Zend\Permissions\Acl\Resource\ResourceInterface;
class EntretienProfessionnelAssertion extends AbstractAssertion {

    use UserServiceAwareTrait;
    use StructureServiceAwareTrait;

    protected function assertEntity(ResourceInterface $entity = null,  $privilege = null)
    {
@@ -25,6 +27,18 @@ class EntretienProfessionnelAssertion extends AbstractAssertion {
        $user = $this->getUserService()->getConnectedUser();
        $role = $this->getUserService()->getConnectedRole();

        $isResponsable = false;
        if ($role->getRoleId === RoleConstant::RESPONSABLE) {
            $structures = [];
            foreach ($entity->getGrades() as $grade) {
                $structures[] = $grade->getStructure();
            }
            foreach ($structures as $structure) {
                $isResponsable = $this->getStructureService()->isResponsable($structure, $user);
                if ($isResponsable) break;
            }
        }

        switch($privilege) {
            case EntretienproPrivileges::ENTRETIENPRO_VALIDER_AGENT :
                switch ($role->getRoleId()) {
@@ -52,6 +66,8 @@ class EntretienProfessionnelAssertion extends AbstractAssertion {
                    case RoleConstant::ADMIN_TECH:
                    case RoleConstant::DRH:
                        return true;
                    case RoleConstant::RESPONSABLE:
                        return $isResponsable;
                    default:
                        return false;
                }
+4 −0
Changes for module/Application/src/Application/Assertion/EntretienProfessionnelAssertionFactory.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Application\Assertion;

use Application\Service\Structure\StructureService;
use Interop\Container\ContainerInterface;
use UnicaenUtilisateur\Service\User\UserService;

@@ -14,12 +15,15 @@ class EntretienProfessionnelAssertionFactory {
    public function  __invoke(ContainerInterface $container)
    {
        /**
         * @var StructureService $structureService
         * @var UserService $userService
         */
        $structureService = $container->get(StructureService::class);
        $userService = $container->get(UserService::class);

        /** @var EntretienProfessionnelAssertion $assertion */
        $assertion = new EntretienProfessionnelAssertion();
        $assertion->setStructureService($structureService);
        $assertion->setUserService($userService);

        return $assertion;
+3 −1
Changes for module/Application/src/Application/Assertion/FichePosteAssertion.php: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class FichePosteAssertion extends AbstractAssertion {
        $role = $this->getUserService()->getConnectedRole();

        $isGestionnaire = false;
        if ($role->getRoleId() === RoleConstant::GESTIONNAIRE) {
        if ($role->getRoleId() === RoleConstant::GESTIONNAIRE || $role->getRoleId() === RoleConstant::RESPONSABLE) {
            $isGestionnaire = $this->getFichePosteService()->isGererPar($entity, $user);
        }

@@ -39,6 +39,7 @@ class FichePosteAssertion extends AbstractAssertion {
                    case RoleConstant::OBSERVATEUR:
                        return true;
                    case RoleConstant::GESTIONNAIRE:
                    case RoleConstant::RESPONSABLE:
                        return $isGestionnaire;
                    case RoleConstant::RESPONSABLE_EPRO:
                        //TODO return false;
@@ -55,6 +56,7 @@ class FichePosteAssertion extends AbstractAssertion {
                    case RoleConstant::ADMIN_TECH:
                        return true;
                    case RoleConstant::GESTIONNAIRE:
                    case RoleConstant::RESPONSABLE:
                        return $isGestionnaire;
                    default:
                        return false;
Loading