Commit 49a13cbf authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Amelioration de la partie entretien professionnel

parent 0134665b
Loading
Loading
Loading
Loading
+24
Changes for module/Application/config/merged/entretien-professionnel.config.php: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

namespace Application;

use Application\Assertion\EntretienProfessionnelAssertion;
use Application\Assertion\EntretienProfessionnelAssertionFactory;
use Application\Controller\EntretienProfessionnelController;
use Application\Controller\EntretienProfessionnelControllerFactory;
use Application\Form\EntretienProfessionnel\EntretienProfessionnelForm;
@@ -25,11 +27,32 @@ use Application\Service\EntretienProfessionnel\EntretienProfessionnelObservation
use Application\Service\EntretienProfessionnel\EntretienProfessionnelService;
use Application\Service\EntretienProfessionnel\EntretienProfessionnelServiceFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProvider;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;

return [
    'bjyauthorize' => [
        'resource_providers' => [
            'BjyAuthorize\Provider\Resource\Config' => [
                'EntretienProfessionnel' => [],
            ],
        ],
        'rule_providers' => [
            PrivilegeRuleProvider::class => [
                'allow' => [
                    [
                        'privileges' => [
                            EntretienproPrivileges::ENTRETIENPRO_VALIDER_AGENT,
                            EntretienproPrivileges::ENTRETIENPRO_VALIDER_RESPONSABLE,
                            EntretienproPrivileges::ENTRETIENPRO_VALIDER_DRH,
                        ],
                        'resources' => ['EntretienProfessionnel'],
                        'assertion' => EntretienProfessionnelAssertion::class
                    ],
                ],
            ],
        ],
        'guards' => [
            PrivilegeController::class => [
                [
@@ -422,6 +445,7 @@ return [

    'service_manager' => [
        'factories' => [
            EntretienProfessionnelAssertion::class => EntretienProfessionnelAssertionFactory::class,
            EntretienProfessionnelService::class => EntretienProfessionnelServiceFactory::class,
            EntretienProfessionnelCampagneService::class => EntretienProfessionnelCampagneServiceFactory::class,
            EntretienProfessionnelObservationService::class => EntretienProfessionnelObservationServiceFactory::class,
+3 −1
Changes for module/Application/src/Application/Assertion/AgentAssertion.php: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ class AgentAssertion extends AbstractAssertion {
            return false;
        }

        /** @var Agent $entity */

        $user = $this->getUserService()->getConnectedUser();
        $role = $this->getUserService()->getConnectedRole();

@@ -61,7 +63,7 @@ class AgentAssertion extends AbstractAssertion {
                    case RoleConstant::ADMIN_TECH:
                        return true;
                    case RoleConstant::PERSONNEL:
                        return ($entity->getUtilisateur() === $user);
                        return ($entity->getUtilisateur() === $user) AND $entity->hasEntretienEnCours();
                    case RoleConstant::GESTIONNAIRE:
                            return $isGestionnaire;
                }
+61
Changes for module/Application/src/Application/Assertion/EntretienProfessionnelAssertion.php: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Assertion;

use Application\Constant\RoleConstant;
use Application\Entity\Db\Agent;
use Application\Entity\Db\EntretienProfessionnel;
use Application\Provider\Privilege\AgentPrivileges;
use Application\Provider\Privilege\EntretienproPrivileges;
use UnicaenAuthentification\Assertion\AbstractAssertion;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
use Zend\Permissions\Acl\Resource\ResourceInterface;

class EntretienProfessionnelAssertion extends AbstractAssertion {

    use UserServiceAwareTrait;

    protected function assertEntity(ResourceInterface $entity = null,  $privilege = null)
    {
        if (!$entity instanceof EntretienProfessionnel) {
            return false;
        }

        /** @var Agent $entity */
        $user = $this->getUserService()->getConnectedUser();
        $role = $this->getUserService()->getConnectedRole();

        switch($privilege) {
            case EntretienproPrivileges::ENTRETIENPRO_VALIDER_AGENT :
                switch ($role->getRoleId()) {
                    case RoleConstant::ADMIN_FONC:
                    case RoleConstant::ADMIN_TECH:
                        return true;
                    case RoleConstant::PERSONNEL:
                        return $entity->getAgent()->getUtilisateur() === $user;
                    default:
                        return false;
                }
            case EntretienproPrivileges::ENTRETIENPRO_VALIDER_RESPONSABLE :
                switch ($role->getRoleId()) {
                    case RoleConstant::ADMIN_FONC:
                    case RoleConstant::ADMIN_TECH:
                        return true;
                    case RoleConstant::GESTIONNAIRE:
                        return $entity->getResponsable() === $user;
                    default:
                        return false;
                }
            case EntretienproPrivileges::ENTRETIENPRO_VALIDER_DRH :
                switch ($role->getRoleId()) {
                    case RoleConstant::ADMIN_FONC:
                    case RoleConstant::ADMIN_TECH:
                    case RoleConstant::DRH:
                        return true;
                    default:
                        return false;
                }
        }
        return true;
    }
}
 No newline at end of file
+27
Changes for module/Application/src/Application/Assertion/EntretienProfessionnelAssertionFactory.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Assertion;

use Interop\Container\ContainerInterface;
use UnicaenUtilisateur\Service\User\UserService;

class EntretienProfessionnelAssertionFactory {

    /**
     * @param ContainerInterface $container
     * @return EntretienProfessionnelAssertion
     */
    public function  __invoke(ContainerInterface $container)
    {
        /**
         * @var UserService $userService
         */
        $userService = $container->get(UserService::class);

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

        return $assertion;
    }
}
 No newline at end of file
+1
Changes for module/Application/src/Application/Constant/RoleConstant.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,4 +11,5 @@ class RoleConstant {
    const VALIDATEUR        = 'Validateur';
    const OBSERVATEUR       = 'Observateur';
    const RESPONSABLE_EPRO  = "Responsable d'entretien pro.";
    const DRH               = "Direction des ressources humaines";
}
 No newline at end of file
Loading