Commit ade2d40b authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Amélioration de la page des privilèges, notamment filtrage par rôle.

parent 2a632198
Loading
Loading
Loading
Loading
+100 −36
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenAuth\Entity\Db\CategoriePrivilege;
use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;
use Zend\View\Model\ViewModel;

@@ -27,33 +26,85 @@ class PrivilegeController extends AbstractController
    {
        $depend = $this->params()->fromQuery("depend");
        $categorie = $this->params()->fromQuery("categorie");
        $role = $this->params()->fromQuery("role");

        $qbRoles = $this->entityManager->getRepository(Role::class)->createQueryBuilder("r");
        $qbRoles
            ->addSelect('p')
            ->leftJoin('r.profils', 'p')
            ->addSelect('s')
            ->leftJoin('r.structure', 's')
            ->addSelect('ts')
            ->leftJoin('s.typeStructure', 'ts')
            ->orderBy("r.typeStructureDependant, r.libelle, r.structure", 'asc');
        $this->applyFilterDependance($qbRoles, $depend);
        $this->applyFilterRole($qbRoles, $role);
        /** @var Role[] $roles */
        $roles = $qbRoles->getQuery()->execute();

        $qbPrivileges = $this->entityManager->getRepository(Privilege::class)->createQueryBuilder("p");
        $qbPrivileges
            ->addSelect('r')
            ->leftJoin('p.role', 'r')
            ->orderBy("p.categorie, p.ordre", "ASC");
        $this->applyFilterCategorie($qbPrivileges, $categorie);
        /** @var Privilege[] $privileges */
        $privileges = $qbPrivileges->getQuery()->execute();

        $qb_depend = $this->entityManager->getRepository(Role::class)->createQueryBuilder("r");
        $qb_depend = $this->decorateWithDepend($qb_depend, $depend);
        $qb_depend = $qb_depend->orderBy("r.typeStructureDependant, r.libelle, r.structure", 'asc');
        $roles = $qb_depend->getQuery()->execute();
        $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();
        // Retrait des rôles associés à des structures historisées ou substituées
        $roles = $this->cleanRoles($roles);

        return new ViewModel([
            'roles'          => $roles,
            'privileges'     => $privileges,
            'rolesForFilter' => $this->fetchRolesForFilter($depend),
            'params'         => $this->params()->fromQuery(),
        ]);
    }

    private function fetchRolesForFilter($depend)
    {
        // pour filtre par (libellé de) rôle
        $qb = $this->entityManager->getRepository(Role::class)->createQueryBuilder("r");
        $qb
            ->orderBy('r.libelle');

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

        $substituees = $this->getStructureService()->getStructuresSubstituees();
        /** @var Role[] $roles */
        $roles = $qb->getQuery()->getResult();

        return $roles;
    }

    /**
     * Retrait des rôles associés à des structures historisées ou substituées
     *
     * @param Role[] $roles
     * @return Role[]
     */
    private function cleanRoles($roles)
    {
        $substituees = $this->structureService->getStructuresSubstituees();

        // Retrait des rôles associés à des structures historisées ou substituées
        $roles = array_filter($roles, function (Role $role) use ($substituees) {
            $structure = $role->getStructure();
            if (array_search($structure, $substituees))  return false;
            if ($structure === null) return true;
            $structureConcrete = $this->getStructureService()->findStructureConcreteFromStructure($structure);
            if ($structureConcrete === null) return true;
            if (array_search($structure, $substituees)) {
                return false;
            }
            if ($structure === null) {
                return true;
            }
            $structureConcrete = $this->structureService->findStructureConcreteFromStructure($structure);
            if ($structureConcrete === null) {
                return true;
            }

            return $structureConcrete->estNonHistorise();
        });

        return new ViewModel([
            'roles' => $roles,
            'privileges' => $privileges,
            'params' => $this->params()->fromQuery(),
        ]);
        return $roles;
    }

    public function modifierAction()
@@ -76,9 +127,7 @@ class PrivilegeController extends AbstractController
            } else {
                $value = 0;
            }
        }

        else {
        } else {

            if (array_search($role, $privilege->getRole()->toArray()) !== false) {
                $privilege->removeRole($role);
@@ -107,42 +156,57 @@ class PrivilegeController extends AbstractController
        //$this->redirect()->toRoute("roles", [], ["query" => $queryParams], true);
    }

    private function decorateWithDepend(QueryBuilder $qb, $depend) {
    private function applyFilterDependance(QueryBuilder $qb, $depend)
    {
        switch ($depend) {
            case "ED" :
                $qb = $qb->andWhere("r.typeStructureDependant = :type")
                $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "2");
                return $qb;
                break;
            case "UR" :
                $qb = $qb->andWhere("r.typeStructureDependant = :type")
                $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "3");
                return $qb;
                break;
            case "Etab" :
                $qb = $qb->andWhere("r.typeStructureDependant = :type")
                $qb->andWhere("r.typeStructureDependant = :type")
                    ->setParameter("type", "1");
                return $qb;
                break;
            case "These" :
                $qb = $qb->andWhere("r.theseDependant = :value")
                $qb->andWhere("r.theseDependant = :value")
                    ->setParameter("value", true);
                return $qb;
                break;
            case "Aucune" :
                $qb = $qb->andWhere("r.theseDependant = :value")
                $qb->andWhere("r.theseDependant = :value")
                    ->andWhere("r.typeStructureDependant IS NULL")
                    ->setParameter("value", false);
                return $qb;
                break;
            default:
                return $qb;
                break;
        }

        return $qb;
    }

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

        return $qb;
    }

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

        return $qb;
    }
}
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -343,7 +343,9 @@ class StructureService extends BaseService
    public function getStructuresSubstituantes($type = null, $order = null)
    {
        $qb = $this->getEntityManager()->getRepository(Structure::class)->createQueryBuilder("s")
            ->andWhere("s.structuresSubstituees IS NOT EMPTY");
            ->addSelect('substituees')
            ->join("s.structuresSubstituees", "substituees")/*
            ->andWhere("s.structuresSubstituees IS NOT EMPTY")*/;
        if ($type) {
            $typeStructure = $this->fetchTypeStructure($type);
            $qb->andWhere("s.typeStructure = :type")
+24 −17
Original line number Diff line number Diff line
<?php

use Application\Entity\Db\Role;
use Application\Entity\Db\Privilege;
use UnicaenAuth\Provider\Privilege\Privileges;
use Application\Entity\Db\Etablissement;

$canVisualiser = $this->isAllowed(Privileges::getResourceId(Privileges::DROIT_PRIVILEGE_VISUALISATION));
$canModifier = $this->isAllowed(Privileges::getResourceId(Privileges::DROIT_PRIVILEGE_EDITION));


/**
 * //Provenant du controleur
 * Provenant du controleur
 * @var Role[]          $roles
 * @var Privilege[]     $privileges
 * @var Etablissement[] $etablissements
 *
 * //Utilisée couramment
 * Utilisée couramment
 * @var Role            $role
 * @var Privilege       $privilege
 */
@@ -34,7 +36,8 @@
<table id='mytable' class='mytable table-bordered'>
    <thead>
    <tr>
            <th></th>  <! -- //empty first cell -->
        <th></th>
        <! -- //empty first cell -->
        <?php foreach ($roles as $role) : ?>
            <th class="role">
                <?php
@@ -60,9 +63,13 @@
                ?>
                <?php echo $role->getLibelle(); ?>
                <?php if (!$role->getProfils()->isEmpty()): ?>
                            <span class="glyphicon glyphicon-info-sign text-info" title="<?php foreach ($role->getProfils() as $profil) { echo "[".$profil->getLibelle()."] "; }?>"></span>
                    <span class="glyphicon glyphicon-info-sign text-info"
                          title="<?php foreach ($role->getProfils() as $profil) {
                              echo "[" . $profil->getLibelle() . "] ";
                          } ?>"></span>
                <?php else : ?>
                            <span class="glyphicon glyphicon-warning-sign text-warning" title="Aucun profil d'assigné à ce rôle"></span>
                    <span class="glyphicon glyphicon-warning-sign text-warning"
                          title="Aucun profil d'assigné à ce rôle"></span>
                <?php endif; ?>

                <br/>
@@ -74,6 +81,9 @@
    <tbody>
    <?php $previous_categorie = null; ?>
    <?php foreach ($privileges as $privilege) : ?>
        <?php
        $privilegeRoles = $privilege->getRole()->toArray();
        ?>
        <?php if ($previous_categorie !== $privilege->getCategorie()) : ?>
            <tr>
                <th colspan="<?php echo count($roles) + 1; ?>" class="categorie">
@@ -91,7 +101,7 @@
                $id = $privilege->getId() . '_' . $role->getId();
                ?>
                <td class="droit" id="<?php echo $id; ?>" title="<?php echo $title; ?>">
                            <?php if( array_search($role, $privilege->getRole()->toArray()) !== false) : ?>
                    <?php if (array_search($role, $privilegeRoles) !== false) : ?>
                        <span class="glyphicon glyphicon-ok text-success"></span>
                    <?php else: ?>
                        <span class="glyphicon glyphicon-remove text-danger"></span>
@@ -140,8 +150,9 @@
    });
</script>

<style>


<style>
    table.mytable {
        background-color: white;
    }
@@ -163,28 +174,24 @@
        text-align: left;
        vertical-align: top;
    }
    .depend
    {

    .depend {
    / / text-orientation: upright;
    }

    .ecole-doctorale
    {
    .ecole-doctorale {
        color: #5B2268;
    }

    .unite-recherche
    {
    .unite-recherche {
        color: #0a3783;
    }

    .etablissement
    {
    .etablissement {
        color: #870a0a;
    }

    .these
    {
    .these {
        color: #004602;
    }

+27 −8
Original line number Diff line number Diff line
<?php

use Application\Entity\Db\These;
use Application\Entity\Db\Role;
use Application\View\Renderer\PhpRenderer;

/**
 * @var PhpRenderer $this
 * @var string      $text
 * @var Role[]      $rolesForFilter
 */

/**
@@ -16,15 +17,16 @@ use Application\View\Renderer\PhpRenderer;
 */
$urlFiltrer = function ($paramName, $paramValue, $queryParams) {
    $queryParams[$paramName] = $paramValue;

    return $this->url('gestion-privilege', [], ['query' => $queryParams], true);
};

echo $this->filterPanel([
    $this->translate("Depend") => [
    $this->translate("Dépendance") => [
        'paramName'   => 'depend',
        'paramConfig' => [
            ['value' => '',                             'label' => $this->translate(" - ") ],
            ['value' => $v = "Aucune",                  'label' => $this->translate("Aucun") ],
            ['value' => '', 'label' => $this->translate("(Peu importe)")],
            ['value' => $v = "Aucune", 'label' => $this->translate("Sans dépendance")],
            ['value' => $v = "ED", 'label' => $this->translate("École doctorale")],
            ['value' => $v = "UR", 'label' => $this->translate("Unité de recherche")],
            ['value' => $v = "Etab", 'label' => $this->translate("Établissement")],
@@ -36,12 +38,11 @@ echo $this->filterPanel([
    ],
]);


echo $this->filterPanel([
    $this->translate("Catégorie") => [
        'paramName'   => 'categorie',
        'paramConfig' => [
            ['value' => '',                             'label' => $this->translate(" - ") ],
            ['value' => '', 'label' => $this->translate("(Peu importe)")],
            ['value' => $v = "droit", 'label' => $this->translate("Droit")],
            ['value' => $v = "import", 'label' => $this->translate("Import")],
            ['value' => $v = "these", 'label' => $this->translate("These")],
@@ -51,7 +52,8 @@ echo $this->filterPanel([
            ['value' => $v = "indicateur", 'label' => $this->translate("Indicateur")],
            ['value' => $v = "substitution", 'label' => $this->translate("Substitution")],
            ['value' => $v = "validation", 'label' => $this->translate("Validation")],
            ['value' => $v = "fichier-divers",          'label' => $this->translate("Fichier") ],
            ['value' => $v = "fichier-divers", 'label' => $this->translate("Fichier divers")],
            ['value' => $v = "fichier-commun", 'label' => $this->translate("Fichier commun")],
            ['value' => $v = "faq", 'label' => $this->translate("FAQ")],

        ],
@@ -60,6 +62,23 @@ echo $this->filterPanel([
    ],
]);

?>
$values = [
    ['value' => '', 'label' => $this->translate("(Tous)")],
];
foreach ($rolesForFilter as $role) {
    $values[$role->getLibelle()] = [
        'value' => $role->getLibelle(),
        'label' => $this->translate($role->getLibelle()),
    ];
}

echo $this->filterPanel([
    $this->translate("Rôle") => [
        'paramName'   => 'role',
        'paramConfig' => $values,
        'filterUrl'   => $urlFiltrer,
        'titre'       => "Filtrage par rôle",
    ],
]);