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

Séparation de la partie profil des roles

parent a2caa630
Loading
Loading
Loading
Loading
+0 −58
Changes for module/Application/config/others/admin.config.php: 0 added lines, 58 removed lines.
Original line number Diff line number Diff line
@@ -50,29 +50,16 @@ return [
                    'controller' => \Application\Controller\PrivilegeController::class,
                    'action'     => [
                        'index',
                        'role-modele-index',
                    ],
                    'privileges' => [
                        Privileges::DROIT_PRIVILEGE_VISUALISATION,
                        Privileges::DROIT_PRIVILEGE_EDITION,
                    ],
                ],
                [
                    'controller' => \Application\Controller\PrivilegeController::class,
                    'action'     => [
                        'editer-profil',
                        'supprimer-profil',
                        'gerer-roles',
                    ],
                    'privileges' => [
                        Privileges::DROIT_PRIVILEGE_EDITION,
                    ],
                ],
                [
                    'controller' => \Application\Controller\PrivilegeController::class,
                    'action'     => [
                        'modifier',
                        'modifier-modele',
                    ],
                    'privileges' => [
                        Privileges::DROIT_PRIVILEGE_EDITION,
@@ -130,49 +117,6 @@ return [
                    ],
                ],
            ],
            'gestion-role-modele' => [
                'type'          => Literal::class,
                'options'       => [
                    'route'    => '/gestion-role-modele',
                    'defaults' => [
                        'controller'    => \Application\Controller\PrivilegeController::class,
                        'action'        => 'role-modele-index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'editer' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/editer[/:profil]',
                            'defaults' => [
                                'controller'    => \Application\Controller\PrivilegeController::class,
                                'action'        => 'editer-profil',
                            ],
                        ],
                    ],
                    'supprimer' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/supprimer/:profil',
                            'defaults' => [
                                'controller'    => \Application\Controller\PrivilegeController::class,
                                'action'        => 'supprimer-profil',
                            ],
                        ],
                    ],
                    'gerer-roles' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/gerer-roles/:profil',
                            'defaults' => [
                                'controller'    => \Application\Controller\PrivilegeController::class,
                                'action'        => 'gerer-roles',
                            ],
                        ],
                    ],
                ],
            ],
            'role-ordre' => [
                'type'          => Literal::class,
                'options'       => [
@@ -337,13 +281,11 @@ return [
        ],
        'factories' => [
            'MailConfirmationForm' => MailConfirmationFormFactory::class,
            ProfilForm::class => ProfilFormFactory::class,
        ],
    ],
    'hydrators' => [
        'factories' => [
            'MailConfirmationHydrator' => MailConfirmationHydratorFactory::class,
            ProfilHydrator::class => ProfilHydratorFactory::class,
        ]
    ],

+131 −0
Changes for module/Application/config/others/profil.config.php: 131 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application;

use Application\Controller\Factory\ProfilControllerFactory;
use Application\Controller\ProfilController;
use Application\Form\Factory\ProfilFormFactory;
use Application\Form\Factory\ProfilHydratorFactory;
use Application\Form\Hydrator\ProfilHydrator;
use Application\Form\ProfilForm;
use Application\Service\Profil\ProfilService;
use Application\Service\Profil\ProfilServiceFactory;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenAuth\Provider\Privilege\Privileges;
use Zend\Mvc\Router\Http\Literal;
use Zend\Mvc\Router\Http\Segment;

return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [
                [
                    'controller' => ProfilController::class,
                    'action' => [
                        'index',
                    ],
                    'privileges' => [
                        Privileges::DROIT_PRIVILEGE_VISUALISATION,
                        Privileges::DROIT_PRIVILEGE_EDITION,
                    ],
                ],
                [
                    'controller' => ProfilController::class,
                    'action' => [
                        'editer',
                        'supprimer',
                        'gerer-roles',
                        'modifier-profil-privilege'
                    ],
                    'privileges' => [
                        Privileges::DROIT_PRIVILEGE_EDITION,
                    ],
                ],
            ],
        ],
    ],
    'router' => [
        'routes' => [
            'profil' => [
                'type'          => Literal::class,
                'options'       => [
                    'route'    => '/profil',
                    'defaults' => [
                        'controller'    => ProfilController::class,
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'editer' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/editer[/:profil]',
                            'defaults' => [
                                'controller'    => ProfilController::class,
                                'action'        => 'editer',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'supprimer' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/supprimer/:profil',
                            'defaults' => [
                                'controller'    => ProfilController::class,
                                'action'        => 'supprimer',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'gerer-roles' => [
                        'type'          => Segment::class,
                        'options'       => [
                            'route'    => '/gerer-roles/:profil',
                            'defaults' => [
                                'controller'    => ProfilController::class,
                                'action'        => 'gerer-roles',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                ],
            ],
            'modifier-profil-privilege' => [
                'type'          => Segment::class,
                'options'       => [
                    'route'    => '/modifier-profil-privilege/:profil/:privilege',
                    'defaults' => [
                        'controller'    => ProfilController::class,
                        'action'        => 'modifier-profil-privilege',
                    ],
                ],
                'may_terminate' => true,
            ],
        ],
    ],
    'navigation' => [
    ],
    'service_manager' => [
        'factories' => [
            ProfilService::class => ProfilServiceFactory::class,
        ],
    ],
    'controllers'     => [
        'factories' => [
            ProfilController::class => ProfilControllerFactory::class,
        ],
    ],

    'form_elements'   => [
        'factories' => [
            ProfilForm::class => ProfilFormFactory::class,
        ],
    ],
    'hydrators' => [
        'factories' => [
            ProfilHydrator::class => ProfilHydratorFactory::class,
        ]
    ],
];
 No newline at end of file
+27 −0
Changes for module/Application/src/Application/Controller/Factory/ProfilControllerFactory.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller\Factory;

use Application\Controller\ProfilController;
use Application\Service\Profil\ProfilService;
use UnicaenAuth\Service\PrivilegeService;
use Zend\Mvc\Controller\ControllerManager;

class ProfilControllerFactory {

    public function __invoke(ControllerManager $controllerManager) {

        /**
         * @var PrivilegeService $privilegeService
         * @var ProfilService $profilService
         */
        $privilegeService = $controllerManager->getServiceLocator()->get('UnicaenAuth\Service\Privilege');
        $profilService = $controllerManager->getServiceLocator()->get(ProfilService::class);

        /** @var ProfilController $controller */
        $controller = new ProfilController();
        $controller->setServicePrivilege($privilegeService);
        $controller->setProfilService($profilService);
        return $controller;
    }
}
 No newline at end of file
+0 −103
Changes for module/Application/src/Application/Controller/PrivilegeController.php: 0 added lines, 103 removed lines.
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@ namespace Application\Controller;

use Application\Entity\Db\Privilege;
use Application\Entity\Db\Role;
use Application\Entity\Db\Profil;
use Application\Form\ProfilForm;
use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\Role\RoleServiceAwareTrait;
use Application\Service\Structure\StructureServiceAwareTrait;
@@ -13,8 +11,6 @@ use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenAuth\Entity\Db\CategoriePrivilege;
use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;
use Zend\Http\Request;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;

class PrivilegeController extends AbstractController
@@ -83,36 +79,6 @@ class PrivilegeController extends AbstractController
        //$this->redirect()->toRoute("roles", [], ["query" => $queryParams], true);
    }

    public function modifierModeleAction()
    {
        $privilege_id = $this->params()->fromRoute("privilege");
        $role_id = $this->params()->fromRoute("role");

        /**
         * @var Profil $role
         * @var Privilege $privilege
         */
        $role = $this->entityManager->getRepository(Profil::class)->find($role_id);
        $privilege = $this->entityManager->getRepository(Privilege::class)->find($privilege_id);

        $value = null;
        if( $role->hasPrivilege($privilege)) {
            $privilege->removeProfil($role);
            $value = 0;
        } else {
            $privilege->addProfil($role);
            $value = 1;
        }
//        $this->entityManager->flush($role);
        $this->entityManager->flush($privilege);

        $queryParams = $this->params()->fromQuery();
        return new JsonModel([
            'value' => $value,
        ]);
        //$this->redirect()->toRoute("roles", [], ["query" => $queryParams], true);
    }

    private function decorateWithDepend(QueryBuilder $qb, $depend) {
        switch($depend) {
            case "ED" :
@@ -151,73 +117,4 @@ class PrivilegeController extends AbstractController
        }
        return $qb;
    }

    public function roleModeleIndexAction() {

        $modeles = $this->getRoleService()->getProfils();

        //$privileges = $this->getServicePrivilege()->getRepo()->findAll();
        $qb_categorie = $this->entityManager->getRepository(Privilege::class)->createQueryBuilder("p");
//        $qb_categorie = $this->decorateWithCategorie($qb_categorie, $categorie);
        $qb_categorie->orderBy("p.categorie, p.ordre","ASC");
        $privileges = $qb_categorie->getQuery()->execute();

        return new ViewModel([
            'modeles' => $modeles,
            'privileges' => $privileges,
        ]);
    }

    public function editerProfilAction() {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');

        $profil = null;
        if($profilId)   $profil = $this->getRoleService()->getProfil($profilId);
        else            $profil = new Profil();

        /** @var ProfilForm $form */
        $form = $this->getServiceLocator()->get('FormElementManager')->get(ProfilForm::class);
        $form->bind($profil);

        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                if ($profilId)  $this->getRoleService()->updateProfil($profil);
                else            $this->getRoleService()->createProfil($profil);
                $this->redirect()->toRoute('gestion-role-modele', [], [], true);
            }
        }

        return new ViewModel([
            'form' => $form,
        ]);
    }

    public function supprimerProfilAction() {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');
        $profil = $this->getRoleService()->getProfil($profilId);

        if ($profil) {
            $this->getRoleService()->deleteProfil($profil);
        }

        $this->redirect()->toRoute('gestion-role-modele', [], [], true);

    }

    public function gererRolesAction()
    {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');
        $profil = $this->getRoleService()->getProfil($profilId);

        return new ViewModel([
            'profil' => $profil,
        ]);
    }
}
 No newline at end of file
+112 −0
Changes for module/Application/src/Application/Controller/ProfilController.php: 112 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Application\Controller;

use Application\Entity\Db\Privilege;
use Application\Entity\Db\Profil;
use Application\Form\ProfilForm;
use Application\Service\Profil\ProfilServiceAwareTrait;
use Doctrine\ORM\OptimisticLockException;
use UnicaenApp\Exception\RuntimeException;
use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;
use Zend\Http\Request;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;

class ProfilController extends AbstractActionController {
    use PrivilegeServiceAwareTrait;
    use ProfilServiceAwareTrait;

    public function indexAction()
    {
        $profils = $this->getProfilService()->getProfils();
        $privileges = $this->getServicePrivilege()->getRepo()->findBy([], ['categorie' => 'ASC', 'ordre' => 'ASC']);

        return new ViewModel([
            'profils' => $profils,
            'privileges' => $privileges,
        ]);
    }

    public function editerAction() {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');

        $profil = null;
        if($profilId)   $profil = $this->getProfilService()->getProfil($profilId);
        else            $profil = new Profil();

        /** @var ProfilForm $form */
        $form = $this->getServiceLocator()->get('FormElementManager')->get(ProfilForm::class);
        $form->bind($profil);

        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                if ($profilId)  $this->getProfilService()->update($profil);
                else            $this->getProfilService()->create($profil);
                $this->redirect()->toRoute('profil', [], [], true);
            }
        }

        return new ViewModel([
            'form' => $form,
        ]);
    }

    public function supprimerAction() {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');
        $profil = $this->getProfilService()->getProfil($profilId);

        if ($profil) {
            $this->getProfilService()->delete($profil);
        }

        $this->redirect()->toRoute('profil', [], [], true);

    }

    public function modifierProfilPrivilegeAction()
    {
        $privilegeId = $this->params()->fromRoute("privilege");
        $profilId = $this->params()->fromRoute("profil");

        /** @var Profil $profil */
        $profil = $this->getProfilService()->getProfil($profilId);
        /** @var Privilege $privilege */
        $privilege = $this->getServicePrivilege()->getRepo()->find($privilegeId);

        $value = null;
        if( $profil->hasPrivilege($privilege)) {
            $privilege->removeProfil($profil);
            $value = 0;
        } else {
            $privilege->addProfil($profil);
            $value = 1;
        }
        try {
            $this->getServicePrivilege()->getEntityManager()->flush($privilege);
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Un problème lors du changement de rôle s'est produit", $e);
        }
        return new JsonModel([
            'value' => $value,
        ]);
    }

    public function gererRolesAction()
    {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');
        $profil = $this->getProfilService()->getProfil($profilId);

        return new ViewModel([
            'profil' => $profil,
        ]);
    }
}
 No newline at end of file
Loading