Commit 2ccdc1c1 authored by David Surville's avatar David Surville
Browse files

Fusion branche 5.x dans release/1.3.0 : intégration des périmètres

parent 7f7de1b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class PrivilegeController extends AbstractActionController
        $privilegesByCategorie = $this->privilegeService->listByCategorie($namespace);

        $title = "Attribution des privilèges";
        return compact('title', 'form', 'roles', 'privilegesByCategorie', 'namespace');
        return compact('title', 'form', 'roles', 'privilegesByCategorie');
    }

    public function ajouterAction() : ViewModel
+52 −72
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ use BjyAuthorize\Provider\Resource\ProviderInterface as ResourceProviderInterfac
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\ORMException;
use UnicaenApp\Controller\Plugin\Exception\InvalidArgumentException;
use UnicaenPrivilege\Entity\Db\PrivilegeCategorieInterface;
use UnicaenPrivilege\Entity\Db\PrivilegeInterface;
use UnicaenPrivilege\Exception\RuntimeException;
@@ -27,69 +26,18 @@ class PrivilegeService extends CommonService implements PrivilegeProviderInterfa


    /**
     * @param string $entityClass
     * @param string $privilegeEntityClass
     * @return void
     */
    public function setEntityClass(string $entityClass) : void
    public function setEntityClass($privilegeEntityClass)
    {
        if (! class_exists($entityClass) || ! in_array(PrivilegeInterface::class, class_implements($entityClass))) {
            throw new InvalidArgumentException("L'entité associée aux privilèges doit implémenter " . PrivilegeInterface::class);
        if (! class_exists($privilegeEntityClass) || ! in_array(PrivilegeInterface::class, class_implements($privilegeEntityClass))) {
            throw new \InvalidArgumentException("L'entité associée aux privilèges doit implémenter " . PrivilegeInterface::class);
        }

        $this->entityClass = $entityClass;
    }

    /** ENTITY MANAGMENT **********************************************************************************************/

    /**
     * @param PrivilegeInterface $privilege
     * @return PrivilegeInterface
     */
    public function create(PrivilegeInterface $privilege) : PrivilegeInterface
    {
        try {
            $this->getEntityManager()->persist($privilege);
            $this->getEntityManager()->flush($privilege);
        } catch(ORMException $e) {
            throw new RuntimeException("Un problème est survenu lors de la création du privilège.", null, $e);
        }

        return $privilege;
    }

    /**
     * @param PrivilegeInterface $privilege
     * @return PrivilegeInterface
     */
    public function update(PrivilegeInterface $privilege) : PrivilegeInterface
    {
        try {
            $this->getEntityManager()->flush($privilege);
        } catch(ORMException $e) {
            throw new RuntimeException("Un problème est survenu lors de la mise à jour du privilège \"" . $privilege->getLibelle() . "\"", null, $e);
        }

        return $privilege;
        $this->entityClass = $privilegeEntityClass;
    }

    /**
     * @param PrivilegeInterface $privilege
     * @return PrivilegeInterface
     */
    public function delete(PrivilegeInterface $privilege) : PrivilegeInterface
    {
        try {
            $this->getEntityManager()->remove($privilege);
            $this->getEntityManager()->flush($privilege);
        } catch(ORMException $e) {
            throw new RuntimeException("Un problème est survenu lors de la suppression du privilège \"" . $privilege->getLibelle() . "\"", null, $e);
        }

        return $privilege;
    }

    /** REQUETAGE *****************************************************************************************************/

    /**
     * @param string $code
     * @param int|PrivilegeCategorieInterface $categorie
@@ -100,19 +48,6 @@ class PrivilegeService extends CommonService implements PrivilegeProviderInterfa
        return $this->getRepo()->findOneBy(['code' => $code, 'categorie' => $categorie]);
    }

    /**
     * @param string $code
     * @return PrivilegeInterface|null
     */
    public function findByFullCode(string $code) : ?PrivilegeInterface
    {
        [$categorieCode, $privilegeCode] = explode('-', $code);
        $categorie = $this->getPrivilegeCategorieService()->findByCode($categorieCode);
        if ($categorie === null) return null;
        $privilege = $this->findByCode($privilegeCode, $categorie);
        return $privilege;
    }

    /**
     * @param string $libelle
     * @param int|PrivilegeCategorieInterface $categorie
@@ -147,14 +82,59 @@ class PrivilegeService extends CommonService implements PrivilegeProviderInterfa
        foreach ($categories as $c) {
            $privileges = $this->findByCategorie($c);
            if(count($privileges) > 0) {
                $privilegesByCategorie[$c->getId()] = $privileges;
                $privilegesByCategorie[$c->getLibelle()] = $privileges;
            }
        }

        return $privilegesByCategorie;
    }

    /**
     * @param PrivilegeInterface $privilege
     * @return PrivilegeInterface
     */
    public function create(PrivilegeInterface $privilege)
    {
        try {
            $this->getEntityManager()->persist($privilege);
            $this->getEntityManager()->flush($privilege);
        } catch(ORMException $e) {
            throw new RuntimeException("Un problème est survenu lors de la création du privilège.", null, $e);
        }

        return $privilege;
    }

    /**
     * @param PrivilegeInterface $privilege
     * @return PrivilegeInterface
     */
    public function update(PrivilegeInterface $privilege)
    {
        try {
            $this->getEntityManager()->flush($privilege);
        } catch(ORMException $e) {
            throw new RuntimeException("Un problème est survenu lors de la mise à jour du privilège \"$privilege\"", null, $e);
        }

        return $privilege;
    }

    /**
     * @param PrivilegeInterface $privilege
     * @return PrivilegeInterface
     */
    public function delete(PrivilegeInterface $privilege)
    {
        try {
            $this->getEntityManager()->remove($privilege);
            $this->getEntityManager()->flush($privilege);
        } catch(ORMException $e) {
            throw new RuntimeException("Un problème est survenu lors de la suppression du privilège \"$privilege\"", null, $e);
        }

        return $privilege;
    }

    /**
     * @param RoleInterface $role
@@ -173,7 +153,7 @@ class PrivilegeService extends CommonService implements PrivilegeProviderInterfa
//            $this->getEntityManager()->flush();
            $this->update($privilege);
        } catch (ORMException $e) {
            throw new RuntimeException("Un problème est survenu lors du changement de privilège \"" . $privilege->getLibelle() . "\" pour le rôle \"" . $role->getLibelle() . "\".", $e);
            throw new RuntimeException("Un problème est survenu lors du changement de privilège \"$privilege\" pour le rôle \"$role\".", $e);
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ class PrivilegeViewHelper extends AbstractHelper
        $html = '<td class="role-privilege-statut text-center %s" style="border-right: 1px solid #ddd;" title="%s">%s</td>';
        return sprintf($html,
            $check ? 'success' : 'danger',
            ($check? 'Ajouter' : 'Retirer') . " le privilège [".$this->privilege->getCategorie()->getLibelle()."|".$this->privilege->getLibelle()."] au rôle [".$role->getLibelle()."]",
            ($check? 'Ajouter' : 'Retirer') . " le privilège \"" . $this->privilege->getCategorie() . " \ " . $this->privilege . "\" au rôle \"" . $role ."\"",
            $check ? $this->renderLienSupprimer($role) : $this->renderLienAjouter($role)
        );
    }