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

Propagation des modifications de privilèges du profil aux rôles associés

parent 56b82fd8
Loading
Loading
Loading
Loading
+3 −0
Changes for module/Application/src/Application/Controller/ProfilController.php: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -97,6 +97,9 @@ class ProfilController extends AbstractActionController {
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Un problème lors du changement de rôle s'est produit", $e);
        }
        // Application aux rôles associés au profil
        $this->getRoleService()->applyChangement($profil->getRoles(), $privilege, $value);

        return new JsonModel([
            'value' => $value,
        ]);
+23 −0
Changes for module/Application/src/Application/Service/Role/RoleService.php: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ use Application\Entity\Db\Utilisateur;
use Application\Filter\EtablissementPrefixFilter;
use Application\Filter\EtablissementPrefixFilterAwareTrait;
use Application\Service\BaseService;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\Query\Expr\Join;
@@ -338,6 +339,28 @@ class RoleService extends BaseService
        }
    }

    /**
     * @param ArrayCollection $roles
     * @param Privilege $privilege
     * @param boolean $etat
     */
    public function applyChangement($roles, $privilege, $etat)
    {
        /** @var Role $role */
        foreach ($roles as $role) {
            if ($etat) {
                $privilege->addRole($role);
            } else {
                $privilege->removeRole($role);
            }
            try {
                $this->getEntityManager()->flush($privilege);
            } catch (OptimisticLockException $e) {
                throw new RuntimeException("Un problème est survenu lors de l'application du changement du profil aux rôles associés.",$e);
            }
        }
    }

//SELECT * FROM ROLE R
//JOIN STRUCTURE S on R.STRUCTURE_ID = S.ID
//LEFT JOIN STRUCTURE_SUBSTIT SS on S.ID = SS.FROM_STRUCTURE_ID