Loading module/Application/src/Application/Controller/PrivilegeController.php +19 −2 Changes for module/Application/src/Application/Controller/PrivilegeController.php: 19 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ use Application\Entity\Db\Role; use Application\Service\Etablissement\EtablissementServiceAwareTrait; use Application\Service\Role\RoleServiceAwareTrait; use Application\Service\Structure\StructureServiceAwareTrait; 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; Loading Loading @@ -58,19 +60,34 @@ class PrivilegeController extends AbstractController { $privilege_id = $this->params()->fromRoute("privilege"); $role_id = $this->params()->fromRoute("role"); /** * @var Privilege $privilege * @var Role $role */ $privilege = $this->entityManager->getRepository(Privilege::class)->find($privilege_id); $role = $this->entityManager->getRepository(Role::class)->find($role_id); $value = null; if( array_search($role, $privilege->getRole()->toArray()) !== false) { $privilege->removeRole($role); $this->entityManager->flush($privilege); try { $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de la suppression du privilège.",$e); } $value = 0; } else { $privilege->addRole($role); $this->entityManager->flush($privilege); try { $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de l'ajout du privilège.",$e); } $value = 1; } // retrait des profils associés à un role $this->getRoleService()->removeProfils($role); $queryParams = $this->params()->fromQuery(); return new ViewModel([ Loading module/Application/src/Application/Service/Profil/ProfilService.php +3 −2 Changes for module/Application/src/Application/Service/Profil/ProfilService.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ class ProfilService { } /** * // TODO : /?\ DQL plutôt que cela /?\ * Lors de l'affectation d'un profil à un rôle : * 1 - retrait des anciens privilèges accordés ; * 2 - affectation des privilèges du nouveau profil. Loading @@ -106,7 +107,7 @@ class ProfilService { if ($privilege->hasRole($role)) { $privilege->removeRole($role); try { $this->getServicePrivilege()->getEntityManager()->flush($privilege); $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors du retrait d'un privilège", $e); } Loading @@ -116,7 +117,7 @@ class ProfilService { foreach ($profil->getPrivileges() as $privilege) { $privilege->addRole($role); try { $this->getServicePrivilege()->getEntityManager()->flush($privilege); $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de l'ajout d'un privilège", $e); } Loading module/Application/src/Application/Service/Role/RoleService.php +15 −0 Changes for module/Application/src/Application/Service/Role/RoleService.php: 15 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -323,6 +323,21 @@ class RoleService extends BaseService return $roles; } /** * @param Role $role */ public function removeProfils($role) { foreach ($role->getProfils() as $profil) { $role->removeProfil($profil); try { $this->getEntityManager()->flush($role); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de la déassociation entre le role et le profil.",$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 Loading Loading
module/Application/src/Application/Controller/PrivilegeController.php +19 −2 Changes for module/Application/src/Application/Controller/PrivilegeController.php: 19 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -7,7 +7,9 @@ use Application\Entity\Db\Role; use Application\Service\Etablissement\EtablissementServiceAwareTrait; use Application\Service\Role\RoleServiceAwareTrait; use Application\Service\Structure\StructureServiceAwareTrait; 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; Loading Loading @@ -58,19 +60,34 @@ class PrivilegeController extends AbstractController { $privilege_id = $this->params()->fromRoute("privilege"); $role_id = $this->params()->fromRoute("role"); /** * @var Privilege $privilege * @var Role $role */ $privilege = $this->entityManager->getRepository(Privilege::class)->find($privilege_id); $role = $this->entityManager->getRepository(Role::class)->find($role_id); $value = null; if( array_search($role, $privilege->getRole()->toArray()) !== false) { $privilege->removeRole($role); $this->entityManager->flush($privilege); try { $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de la suppression du privilège.",$e); } $value = 0; } else { $privilege->addRole($role); $this->entityManager->flush($privilege); try { $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de l'ajout du privilège.",$e); } $value = 1; } // retrait des profils associés à un role $this->getRoleService()->removeProfils($role); $queryParams = $this->params()->fromQuery(); return new ViewModel([ Loading
module/Application/src/Application/Service/Profil/ProfilService.php +3 −2 Changes for module/Application/src/Application/Service/Profil/ProfilService.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ class ProfilService { } /** * // TODO : /?\ DQL plutôt que cela /?\ * Lors de l'affectation d'un profil à un rôle : * 1 - retrait des anciens privilèges accordés ; * 2 - affectation des privilèges du nouveau profil. Loading @@ -106,7 +107,7 @@ class ProfilService { if ($privilege->hasRole($role)) { $privilege->removeRole($role); try { $this->getServicePrivilege()->getEntityManager()->flush($privilege); $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors du retrait d'un privilège", $e); } Loading @@ -116,7 +117,7 @@ class ProfilService { foreach ($profil->getPrivileges() as $privilege) { $privilege->addRole($role); try { $this->getServicePrivilege()->getEntityManager()->flush($privilege); $this->getEntityManager()->flush($privilege); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de l'ajout d'un privilège", $e); } Loading
module/Application/src/Application/Service/Role/RoleService.php +15 −0 Changes for module/Application/src/Application/Service/Role/RoleService.php: 15 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -323,6 +323,21 @@ class RoleService extends BaseService return $roles; } /** * @param Role $role */ public function removeProfils($role) { foreach ($role->getProfils() as $profil) { $role->removeProfil($profil); try { $this->getEntityManager()->flush($role); } catch (OptimisticLockException $e) { throw new RuntimeException("Un problème est survenu lors de la déassociation entre le role et le profil.",$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 Loading