Commit 85389a33 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Amélioration de la page consacrée aux profils (filtrage, explications,...

Amélioration de la page consacrée aux profils (filtrage, explications, esthétique) et harmonisation de la page Rôles et privilèges.
parent 63bcdac6
Loading
Loading
Loading
Loading
+11 −8
Changes for module/Application/config/others/droits.config.php: 11 added lines, 8 removed lines.
Original line number Diff line number Diff line
<?php

use Application\Controller\ProfilController;
use Application\Entity\Db\Privilege;
use Application\Entity\Db\Role;
use UnicaenAuth\Guard\PrivilegeController;
@@ -88,17 +89,19 @@ return [
                                        'resource'   => PrivilegeController::getResourceId('UnicaenAuth\Controller\Droits', 'roles'),
                                        'withtarget' => true,
                                    ],
                                    'privileges' => [
                                        'label'      => "Privilèges",
                                        'title'      => "Gestion des privilèges",
                                        'route'      => 'gestion-privilege',
                                    'profil' => [
                                        'label'      => "Profils et privilèges",
                                        'title'      => "Profils et privilèges",
                                        'route'      => 'profil',
                                        'query'      => ['depend' => ProfilController::PERIMETRE_Aucun],
                                        'resource'   => PrivilegeController::getResourceId('UnicaenAuth\Controller\Droits', 'privileges'),
                                        'withtarget' => true,
                                    ],
                                    'profil' => [
                                        'label'      => "Profils",
                                        'title'      => "Gestion des profils",
                                        'route'      => 'profil',
                                    'privileges' => [
                                        'label'      => "Rôles et privilèges",
                                        'title'      => "Rôles et privilèges",
                                        'route'      => 'gestion-privilege',
                                        'query'      => ['depend' => \Application\Controller\PrivilegeController::PERIMETRE_Aucun],
                                        'resource'   => PrivilegeController::getResourceId('UnicaenAuth\Controller\Droits', 'privileges'),
                                        'withtarget' => true,
                                    ],
+0 −4
Changes for module/Application/config/others/utilisateur.config.php: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ use Application\Service\Utilisateur\UtilisateurSearchService;
use Application\Service\Utilisateur\UtilisateurSearchServiceFactory;
use Application\Service\Utilisateur\UtilisateurService;
use Application\Service\Utilisateur\UtilisateurServiceFactory;
use Application\View\Helper\RoleHelper;
use Individu\View\Helper\IndividuUsurpationHelperFactory;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
@@ -325,9 +324,6 @@ return [
        ],
    ],
    'view_helpers'  => [
        'invokables' => [
            'role' => RoleHelper::class,
        ],
        'factories'  => [
            'individuUsurpation' => IndividuUsurpationHelperFactory::class,
        ],
+22 −17
Changes for module/Application/src/Application/Controller/PrivilegeController.php: 22 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -4,15 +4,16 @@ namespace Application\Controller;

use Application\Entity\Db\Privilege;
use Application\Entity\Db\Role;
use Structure\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\Role\RoleServiceAwareTrait;
use Structure\Service\Structure\StructureServiceAwareTrait;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\QueryBuilder;
use Laminas\View\Model\JsonModel;
use Laminas\View\Model\ViewModel;
use Structure\Service\Etablissement\EtablissementServiceAwareTrait;
use Structure\Service\Structure\StructureServiceAwareTrait;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;
use Laminas\View\Model\ViewModel;

class PrivilegeController extends AbstractController
{
@@ -22,6 +23,12 @@ class PrivilegeController extends AbstractController
    use EtablissementServiceAwareTrait;
    use PrivilegeServiceAwareTrait;

    const PERIMETRE_ED = 'ED';
    const PERIMETRE_UR = 'UR';
    const PERIMETRE_Etab = 'Etab';
    const PERIMETRE_These = 'These';
    const PERIMETRE_Aucun = 'Aucun';

    public function indexAction()
    {
        $depend = $this->params()->fromQuery("depend");
@@ -88,14 +95,13 @@ class PrivilegeController extends AbstractController
        $value = null;

        // /!\ si le role à un privilège desactivé la modification
        if (!$role->getProfils()->isEmpty()) {
        if ($role->getProfil()) {
            if (array_search($role, $privilege->getRole()->toArray()) !== false) {
                $value = 1;
            } else {
                $value = 0;
            }
        } else {

            if (array_search($role, $privilege->getRole()->toArray()) !== false) {
                $privilege->removeRole($role);
                try {
@@ -113,36 +119,35 @@ class PrivilegeController extends AbstractController
                }
                $value = 1;
            }
            // retrait des profils associés à un role
            $this->getRoleService()->removeProfils($role);
            // retrait du profil affecté à un role
            $this->getRoleService()->removeProfil($role);
        }

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

    private function applyFilterDependance(QueryBuilder $qb, $depend)
    private function applyFilterDependance(QueryBuilder $qb, $depend): QueryBuilder
    {
        switch ($depend) {
            case "ED" :
            case self::PERIMETRE_ED:
                $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "2");
                break;
            case "UR" :
            case self::PERIMETRE_UR:
                $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "3");
                break;
            case "Etab" :
            case self::PERIMETRE_Etab:
                $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "1");
                break;
            case "These" :
            case self::PERIMETRE_These:
                $qb->andWhere("r.theseDependant = :value")
                    ->setParameter("value", true);
                break;
            case "Aucune" :
            case self::PERIMETRE_Aucun:
                $qb->andWhere("r.theseDependant = :value")
                    ->andWhere("r.typeStructureDependant IS NULL")
                    ->setParameter("value", false);
@@ -154,7 +159,7 @@ class PrivilegeController extends AbstractController
        return $qb;
    }

    private function applyFilterCategorie(QueryBuilder $qb, $categorie)
    private function applyFilterCategorie(QueryBuilder $qb, $categorie): QueryBuilder
    {
        $qb->leftJoin('p.categorie', "cp");
        if ($categorie !== null && $categorie !== "") {
@@ -166,7 +171,7 @@ class PrivilegeController extends AbstractController
        return $qb;
    }

    private function applyFilterRole(QueryBuilder $qb, $role)
    private function applyFilterRole(QueryBuilder $qb, $role): QueryBuilder
    {
        if ($role !== null && $role !== "") {
            $qb
+100 −10
Changes for module/Application/src/Application/Controller/ProfilController.php: 100 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -9,18 +9,26 @@ use Application\Form\ProfilForm;
use Application\Service\Profil\ProfilServiceAwareTrait;
use Application\Service\Role\RoleServiceAwareTrait;
use Doctrine\ORM\OptimisticLockException;
use UnicaenApp\Exception\RuntimeException;
use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;
use Doctrine\ORM\QueryBuilder;
use Laminas\Http\Request;
use Laminas\Http\Response;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\JsonModel;
use Laminas\View\Model\ViewModel;
use UnicaenApp\Exception\RuntimeException;
use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;

class ProfilController extends AbstractActionController {
class ProfilController extends AbstractActionController
{
    use PrivilegeServiceAwareTrait;
    use ProfilServiceAwareTrait;
    use RoleServiceAwareTrait;

    const PERIMETRE_ED = "ED";
    const PERIMETRE_UR = "UR";
    const PERIMETRE_Etab = "Etab";
    const PERIMETRE_Aucun = "Aucun";

    /**
     * @var ProfilForm
     */
@@ -34,17 +42,97 @@ class ProfilController extends AbstractActionController {
        $this->profilForm = $profilForm;
    }

    public function indexAction()
    public function indexAction(): ViewModel
    {
        $profils = $this->getProfilService()->getProfils();
        $privileges = $this->getServicePrivilege()->getRepo()->findBy([], ['categorie' => 'ASC', 'ordre' => 'ASC']);
        $depend = $this->params()->fromQuery("depend");
        $categorie = $this->params()->fromQuery("categorie");
        $profil = $this->params()->fromQuery("profil");
        
        $qbProfils = $this->profilService->getRepository()->createQueryBuilder("profil");
        $qbProfils
            ->addSelect('ts')->leftJoin('profil.structureType', 'ts')
            ->orderBy("profil.structureType, profil.libelle", 'asc');
        $this->applyFilterDependance($qbProfils, $depend);
        $this->applyFilterProfil($qbProfils, $profil);
        /** @var Profil[] $profils */
        $profils = $qbProfils->getQuery()->execute();

        $qbPrivileges = $this->getServicePrivilege()->getRepo()->createQueryBuilder("p");
        $qbPrivileges
            ->addSelect('profil')->leftJoin('p.profils', 'profil')
            ->orderBy("p.categorie, p.ordre", "ASC");
        $this->applyFilterCategorie($qbPrivileges, $categorie);
        /** @var Privilege[] $privileges */
        $privileges = $qbPrivileges->getQuery()->execute();

        return new ViewModel([
            'profils' => $profils,
            'privileges' => $privileges,
            'profilsForFilter' => $this->fetchProfilsForFilter($depend),
            'params' => $this->params()->fromQuery(),
        ]);
    }

    private function applyFilterDependance(QueryBuilder $qb, $depend): QueryBuilder
    {
        switch ($depend) {
            case self::PERIMETRE_ED:
                $qb->andWhere("profil.structureType = :type")->setParameter("type", "2");
                break;
            case self::PERIMETRE_UR:
                $qb->andWhere("profil.structureType = :type")->setParameter("type", "3");
                break;
            case self::PERIMETRE_Etab:
                $qb->andWhere("profil.structureType = :type")->setParameter("type", "1");
                break;
            case self::PERIMETRE_Aucun:
                $qb->andWhere("profil.structureType IS NULL");
                break;
            default:
                break;
        }

        return $qb;
    }

    private function applyFilterCategorie(QueryBuilder $qb, $categorie): QueryBuilder
    {
        $qb->leftJoin('p.categorie', "cp");
        if ($categorie !== null && $categorie !== "") {
            $qb
                ->andWhere("cp.code = :type")
                ->setParameter("type", $categorie);
        }

        return $qb;
    }

    private function applyFilterProfil(QueryBuilder $qb, $profil): QueryBuilder
    {
        if ($profil !== null && $profil !== "") {
            $qb
                ->andWhere("profil.libelle = :profil")
                ->setParameter("profil", $profil);
        }

        return $qb;
    }

    private function fetchProfilsForFilter($depend): array
    {
        // pour filtre par (libellé de) rôle
        $qb = $this->profilService->getRepository()->createQueryBuilder("profil");
        $qb
            ->orderBy('profil.libelle');

        $this->applyFilterDependance($qb, $depend);

        /** @var Profil[] $profils */
        $profils = $qb->getQuery()->getResult();

        return $profils;
    }

    public function editerAction() {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');
@@ -120,7 +208,7 @@ class ProfilController extends AbstractActionController {
        ]);
    }

    public function gererRolesAction()
    public function gererRolesAction(): ViewModel
    {
        /** @var Profil $profil */
        $profilId   = $this->params()->fromRoute('profil');
@@ -134,7 +222,7 @@ class ProfilController extends AbstractActionController {
        ]);
    }

    public function ajouterRoleAction()
    public function ajouterRoleAction(): Response
    {
        /** @var Profil $profil */
        $profilId = $this->params()->fromRoute('profil');
@@ -145,7 +233,8 @@ class ProfilController extends AbstractActionController {
        if ($request->isPost()) {
            $data = $request->getPost();
            /** @var Role $role */
            $roleId = $data['role'];
            $roleId = $data['role'] ?? null;
            if ($roleId) {
                $role = $this->getRoleService()->getRepository()->find($roleId);

                if (!$profil->hasRole($role)) {
@@ -154,8 +243,9 @@ class ProfilController extends AbstractActionController {
                    $this->getProfilService()->applyProfilToRole($profil, $role);
                }
            }
        }

        $this->redirect()->toRoute('profil/gerer-roles', ['profil' => $profil->getId()], [], true);
        return $this->redirect()->toRoute('profil/gerer-roles', ['profil' => $profil->getId()], [], true);
    }

    public function retirerRoleAction()
+2 −2
Changes for module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Profil.dcm.xml: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Application\Entity\Db\Profil" table="PROFIL">
            <!--repository-class="Application\Entity\Db\Repository\RoleRepository">-->
    <entity name="Application\Entity\Db\Profil" table="PROFIL"
            repository-class="Application\Entity\Db\Repository\ProfilRepository">
        <id name="id" type="integer" column="id">
            <generator strategy="SEQUENCE"/>
        </id>
Loading