Loading module/Application/config/others/utilisateur.config.php +23 −42 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Zend\Mvc\Router\Http\Literal; use Application\Form\Validator\PasswordValidator; use Application\Form\Validator\NewEmailValidator; use Application\Form\Validator\Factory\NewEmailValidatorFactory; use Zend\Mvc\Router\Http\Segment; return [ 'bjyauthorize' => [ Loading @@ -25,19 +26,6 @@ return [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'index', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_CONSULTATION, ], [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'ajouter', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_MODIFICATION, ], [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'rechercher-people', 'rechercher-individu', ], Loading @@ -46,13 +34,8 @@ return [ [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'attribuer-role', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_ATTRIBUTION_ROLE, ], [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'retirer-role', 'ajouter-role', 'creation-utilisateur', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_MODIFICATION, Loading @@ -75,54 +58,52 @@ return [ 'may_terminate' => true, ], 'utilisateur' => [ 'type' => 'Segment', 'type' => Segment::class, 'options' => [ 'route' => '/[:language/]utilisateur', 'route' => '/utilisateur', // 'route' => '/[:language/]utilisateur', 'defaults' => [ '__NAMESPACE__' => 'Application\Controller', 'controller' => 'Utilisateur', 'action' => 'index', 'language' => 'fr_FR', // 'language' => 'fr_FR', ], ], 'may_terminate' => true, 'child_routes' => [ 'ajouter' => [ 'type' => 'Segment', 'rechercher-people' => [ 'type' => Segment::class, 'options' => [ 'route' => '/ajouter', 'route' => '/rechercher-people', 'defaults' => [ 'action' => 'ajouter', 'action' => 'rechercher-people', ], ], ], 'attribuer-role' => [ 'type' => 'Segment', 'rechercher-individu' => [ 'type' => Segment::class, 'options' => [ 'route' => '/attribuer-role/:utilisateur', 'constraints' => [ 'utilisateur' => '\d+', ], 'route' => '/rechercher-individu', 'defaults' => [ 'action' => 'attribuer-role', 'action' => 'rechercher-individu', ], ], ], 'rechercher-people' => [ 'type' => 'Segment', 'retirer-role' => [ 'type' => Segment::class, 'options' => [ 'route' => '/rechercher-people', 'route' => '/retirer-role/:individu/:role', 'defaults' => [ 'action' => 'rechercher-people', 'action' => 'retirer-role', ], ], ], 'rechercher-individu' => [ 'type' => 'Segment', 'ajouter-role' => [ 'type' => Segment::class, 'options' => [ 'route' => '/rechercher-individu', 'route' => '/ajouter-role/:individu/:role', 'defaults' => [ 'action' => 'rechercher-individu', 'action' => 'ajouter-role', ], ], ], Loading module/Application/src/Application/Controller/Factory/UtilisateurControllerFactory.php +12 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ namespace Application\Controller\Factory; use Application\Controller\UtilisateurController; use Application\Service\EcoleDoctorale\EcoleDoctoraleService; use Application\Service\Etablissement\EtablissementService; use Application\Service\Individu\IndividuServiceLocateTrait; use Application\Service\Role\RoleService; use Application\Service\UniteRecherche\UniteRechercheService; use Application\Service\Utilisateur\UtilisateurService; use Doctrine\ORM\EntityManager; use UnicaenLdap\Service\People as LdapPeopleService; Loading @@ -22,11 +25,17 @@ class UtilisateurControllerFactory * @var RoleService $roleService * @var UtilisateurService $utilisateurService * @var LdapPeopleService $ldapPeopleService * @var EtablissementService $etablissementService * @var EcoleDoctoraleService $ecoleService * @var UniteRechercheService $uniteService * @var EntityManager $entityManager; */ $roleService = $sl->get('RoleService'); $ldapPeopleService = $sl->get('LdapServicePeople'); $utilisateurService = $sl->get('UtilisateurService'); $etablissementService = $sl->get('EtablissementService'); $ecoleService = $sl->get('EcoleDoctoraleService'); $uniteService = $sl->get('UniteRechercheService'); $entityManager = $sl->get('doctrine.entitymanager.orm_default'); $controller = new UtilisateurController(); Loading @@ -34,6 +43,9 @@ class UtilisateurControllerFactory $controller->setLdapPeopleService($ldapPeopleService); $controller->setUtilisateurService($utilisateurService); $controller->setIndividuService($this->locateIndividuService($sl)); $controller->setUniteRechercheService($uniteService); $controller->setEcoleDoctoraleService($ecoleService); $controller->setEtablissementService($etablissementService); $controller->setEntityManager($entityManager); return $controller; Loading module/Application/src/Application/Controller/UtilisateurController.php +46 −175 Original line number Diff line number Diff line Loading @@ -7,8 +7,11 @@ use Application\Entity\Db\Role; use Application\Entity\Db\Utilisateur; use Application\Form\CreationUtilisateurForm; use Application\RouteMatch; use Application\Service\EcoleDoctorale\EcoleDoctoraleServiceAwareTrait; use Application\Service\Etablissement\EtablissementServiceAwareTrait; use Application\Service\Individu\IndividuServiceAwareTrait; use Application\Service\Role\RoleServiceAwareTrait; use Application\Service\UniteRecherche\UniteRechercheServiceAwareTrait; use Application\Service\UserContextServiceAwareTrait; use Application\Service\Utilisateur\UtilisateurServiceAwareTrait; use Application\View\Helper\Sortable; Loading Loading @@ -39,168 +42,42 @@ class UtilisateurController extends \UnicaenAuth\Controller\UtilisateurControlle use LdapPeopleServiceAwareTrait; use IndividuServiceAwareTrait; use EntityManagerAwareTrait; use EcoleDoctoraleServiceAwareTrait; use UniteRechercheServiceAwareTrait; use EtablissementServiceAwareTrait; /** * @return array|\Zend\Http\Response|ViewModel * NOTA BENE : il s'agit des individus et non des utilisateurs car ils sont ceux qui portent les rôles */ public function indexAction() { /** * Application des filtres et tris par défaut. */ $needsRedirect = false; $queryParams = $this->params()->fromQuery(); // filtres // $etatThese = $this->params()->fromQuery($name = 'etatThese'); // if ($etatThese === null) { // null <=> paramètre absent // // filtrage par défaut : thèse en préparation // $queryParams = array_merge($queryParams, [$name => Utilisateur::ETAT_EN_COURS]); // $needsRedirect = true; // } // tris $sort = $this->params()->fromQuery('sort'); if ($sort === null) { // null <=> paramètre absent // tri par défaut : datePremiereInscription $queryParams = array_merge($queryParams, ['sort' => 'u.displayName', 'direction' => Sortable::ASC]); $needsRedirect = true; } // redirection si nécessaire if ($needsRedirect) { return $this->redirect()->toRoute(null, [], ['query' => $queryParams], true); } $text = $this->params()->fromQuery('text'); $dir = $this->params()->fromQuery('direction', Sortable::ASC); $maxi = $this->params()->fromQuery('maxi', 40); $page = $this->params()->fromQuery('page', 1); $individu = null; $roles = null; $qb = $this->utilisateurService->getRepository()->createQueryBuilder('u'); // if ($etatThese) { // $qb->andWhere('t.etatThese = :etat')->setParameter('etat', $etatThese); // } foreach (explode('+', $sort) as $sortProp) { $qb->addOrderBy($sortProp, $dir); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost()['individu']; /** @var Individu $individu */ $individu = $this->individuService->getIndviduById($data['id']); $rolesAffectes = $this->roleService->getRoleByIndividu($individu); } /** * Filtres découlant du rôle de l'utilisateur. */ $this->decorateQbFromSelectedRole($qb); /** * Prise en compte du champ de recherche textuelle. */ // if (strlen($text) > 1) { // $results = $this->theseService->rechercherThese($text); // $sourceCodes = array_unique(array_keys($results)); // if ($sourceCodes) { // $qb // ->andWhere($qb->expr()->in('t.sourceCode', ':sourceCodes')) // ->setParameter('sourceCodes', $sourceCodes); // } // else { // $qb->andWhere("0 = 1"); // i.e. aucune thèse trouvée // } // } $paginator = new \Zend\Paginator\Paginator(new DoctrinePaginator(new Paginator($qb, true))); $paginator ->setPageRange(30) ->setItemCountPerPage((int)$maxi) ->setCurrentPageNumber((int)$page); $roleModeles = $this->roleService->getRoleModeleByStructures(); $qb = $this->roleService->getRepository()->createQueryBuilder('r'); $qb ->join('r.source', 's', Join::WITH, 's.importable = 0') ->andWhere('r.attributionAutomatique = 0') ->andWhere($qb->expr()->notIn('r.roleId', [ Role::ROLE_ID_ECOLE_DOCT, Role::ROLE_ID_UNITE_RECH, ])) ->andWhere('1 = pasHistorise(r)') ->orderBy('r.roleId'); $rolesStatiques = $qb->getQuery()->getResult(); $qb = $this->roleService->getRepository()->createQueryBuilder('r') ->andWhere('r.attributionAutomatique = 1') ->andWhere('1 = pasHistorise(r)') ->orderBy('r.roleId'); $rolesDynamiques = $qb->getQuery()->getResult(); $roles = $this->roleService->getRoles(); $etablissements = $this->etablissementService->getEtablissements(); $unites = $this->uniteRechercheService->getUnitesRecherches(); $ecoles = $this->ecoleDoctoraleService->getEcolesDoctorales(); return new ViewModel([ 'utilisateurs' => $paginator, 'modeles' => $roleModeles, 'roles' => $rolesStatiques, 'rolesDynamiques' => $rolesDynamiques, 'text' => $text, 'individu' => $individu, 'roles' => $roles, 'rolesAffectes' => $rolesAffectes, 'etablissements' => $etablissements, 'ecoles' => $ecoles, 'unites' => $unites, ]); } private function decorateQbFromSelectedRole(QueryBuilder $qb) { return $qb; } public function ajouterAction() { $data = $this->params()->fromPost('people'); if (!empty($data['id'])) { /** @var People $people */ if ($people = $this->ldapPeopleService->get($data['id'])) { $username = $people->get('supannAliasLogin'); $utilisateur = $this->utilisateurService->getRepository()->findOneBy(['username' => $username]); if (! $utilisateur) { $utilisateur = $this->utilisateurService->createFromPeople($people); $this->flashMessenger()->addSuccessMessage("$utilisateur a été ajouté-e avec succès à la liste des utilisateurs"); } else { $this->flashMessenger()->addErrorMessage("$utilisateur existe déjà dans la liste des utilisateurs"); } } } return $this->redirect()->toRoute('utilisateur'); } public function attribuerRoleAction() { $utilisateur = $this->requestUtilisateur(); $role = $this->postRole(); if (! $role) { exit; } $qb = $this->utilisateurService->getRepository()->createQueryBuilder('u') ->addSelect('r') ->join('u.roles', 'r', Join::WITH, 'r = :role') ->andWhere('u = :user') ->setParameter('role', $role) ->setParameter('user', $utilisateur); $result = $qb->getQuery()->getResult(); // retrait du rôle if (count($result) > 0) { $utilisateur->removeRole($role); $message = "Le rôle '$role' a été retiré avec succès à l'utilisateur '$utilisateur'."; } // accord du rôle else { $utilisateur->addRole($role); $message = "Le rôle '$role' a été accordé avec succès à l'utilisateur '$utilisateur'."; } try { $this->utilisateurService->getEntityManager()->flush($utilisateur); } catch (OptimisticLockException $e) { throw new RuntimeException("Erreur rencontrée lors de l'enregistrement de l'utilisateur", null, $e); } return new JsonModel(['status' => 'success', 'message' => $message]); } /** * AJAX. * Loading Loading @@ -273,32 +150,6 @@ class UtilisateurController extends \UnicaenAuth\Controller\UtilisateurControlle exit; } /** * @return Utilisateur */ private function requestUtilisateur() { /** @var RouteMatch $match */ $match = $this->getEvent()->getRouteMatch(); return $match->getUtilisateur(); } /** * @return Role */ private function postRole() { $roleId = $this->params()->fromPost('role'); if (! $roleId) { return null; } /** @var Role $role */ $role = $this->roleService->getRepository()->findOneBy([(is_numeric($roleId) ? 'id' : 'roleId') => $roleId]); return $role; } public function creationUtilisateurAction() { Loading Loading @@ -347,4 +198,24 @@ class UtilisateurController extends \UnicaenAuth\Controller\UtilisateurControlle 'form' => $form, ]); } public function retirerRoleAction() { $individuId = $this->params()->fromRoute('individu'); $roleId = $this->params()->fromRoute('role'); $this->roleService->removeRole($individuId, $roleId); return new ViewModel([]); } public function ajouterRoleAction() { $individuId = $this->params()->fromRoute('individu'); $roleId = $this->params()->fromRoute('role'); $this->roleService->addRole($individuId, $roleId); return new ViewModel([]); } } No newline at end of file module/Application/src/Application/Entity/Db/Individu.php +1 −0 Original line number Diff line number Diff line Loading @@ -359,6 +359,7 @@ class Individu implements HistoriqueAwareInterface, SourceAwareInterface */ public function getDateNaissanceToString() { if ($this->dateNaissance === null) return ""; return $this->dateNaissance->format(Constants::DATE_FORMAT); } Loading module/Application/src/Application/Service/Role/RoleService.php +49 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,21 @@ class RoleService extends BaseService return $individuRole; } public function getRoleByIndividu($individu) { $qb = $this->getEntityManager()->getRepository(IndividuRole::class)->createQueryBuilder("ir") ->andWhere("ir.individu = :individu") ->setParameter("individu", $individu); $results = $qb->getQuery()->getResult(); /** @var IndividuRole $result */ $roles = []; foreach($results as $result) { $roles[] = $result->getRole(); } return $roles; } /** * @param int $individuRoleId Loading Loading @@ -219,5 +234,39 @@ class RoleService extends BaseService return $role; } public function removeRole($individuId, $roleId) { $qb = $this->getEntityManager()->getRepository(IndividuRole::class)->createQueryBuilder("ir") ->leftJoin("ir.individu","i") ->leftJoin("ir.role","r") ->andWhere("i.id = :individuId") ->andWhere("r.id = :roleId") ->setParameter("individuId", $individuId) ->setParameter("roleId", $roleId); $result = $qb->getQuery()->getOneOrNullResult(); if ($result !== null) { $this->getEntityManager()->remove($result); $this->getEntityManager()->flush($result); } } public function addRole($individuId, $roleId) { $individu = $this->getEntityManager()->getRepository(Individu::class)->findOneBy(["id"=>$individuId]); $role = $this->getEntityManager()->getRepository(Role::class)->findOneBy(["id"=>$roleId]); $ir = new IndividuRole(); $ir->setIndividu($individu); $ir->setRole($role); $this->getEntityManager()->persist($ir); $this->getEntityManager()->flush($ir); } public function getRoles() { $result = $this->getEntityManager()->getRepository(Role::class)->findAll(); return $result; } } No newline at end of file Loading
module/Application/config/others/utilisateur.config.php +23 −42 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Zend\Mvc\Router\Http\Literal; use Application\Form\Validator\PasswordValidator; use Application\Form\Validator\NewEmailValidator; use Application\Form\Validator\Factory\NewEmailValidatorFactory; use Zend\Mvc\Router\Http\Segment; return [ 'bjyauthorize' => [ Loading @@ -25,19 +26,6 @@ return [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'index', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_CONSULTATION, ], [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'ajouter', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_MODIFICATION, ], [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'rechercher-people', 'rechercher-individu', ], Loading @@ -46,13 +34,8 @@ return [ [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'attribuer-role', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_ATTRIBUTION_ROLE, ], [ 'controller' => 'Application\Controller\Utilisateur', 'action' => [ 'retirer-role', 'ajouter-role', 'creation-utilisateur', ], 'privileges' => UtilisateurPrivileges::UTILISATEUR_MODIFICATION, Loading @@ -75,54 +58,52 @@ return [ 'may_terminate' => true, ], 'utilisateur' => [ 'type' => 'Segment', 'type' => Segment::class, 'options' => [ 'route' => '/[:language/]utilisateur', 'route' => '/utilisateur', // 'route' => '/[:language/]utilisateur', 'defaults' => [ '__NAMESPACE__' => 'Application\Controller', 'controller' => 'Utilisateur', 'action' => 'index', 'language' => 'fr_FR', // 'language' => 'fr_FR', ], ], 'may_terminate' => true, 'child_routes' => [ 'ajouter' => [ 'type' => 'Segment', 'rechercher-people' => [ 'type' => Segment::class, 'options' => [ 'route' => '/ajouter', 'route' => '/rechercher-people', 'defaults' => [ 'action' => 'ajouter', 'action' => 'rechercher-people', ], ], ], 'attribuer-role' => [ 'type' => 'Segment', 'rechercher-individu' => [ 'type' => Segment::class, 'options' => [ 'route' => '/attribuer-role/:utilisateur', 'constraints' => [ 'utilisateur' => '\d+', ], 'route' => '/rechercher-individu', 'defaults' => [ 'action' => 'attribuer-role', 'action' => 'rechercher-individu', ], ], ], 'rechercher-people' => [ 'type' => 'Segment', 'retirer-role' => [ 'type' => Segment::class, 'options' => [ 'route' => '/rechercher-people', 'route' => '/retirer-role/:individu/:role', 'defaults' => [ 'action' => 'rechercher-people', 'action' => 'retirer-role', ], ], ], 'rechercher-individu' => [ 'type' => 'Segment', 'ajouter-role' => [ 'type' => Segment::class, 'options' => [ 'route' => '/rechercher-individu', 'route' => '/ajouter-role/:individu/:role', 'defaults' => [ 'action' => 'rechercher-individu', 'action' => 'ajouter-role', ], ], ], Loading
module/Application/src/Application/Controller/Factory/UtilisateurControllerFactory.php +12 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ namespace Application\Controller\Factory; use Application\Controller\UtilisateurController; use Application\Service\EcoleDoctorale\EcoleDoctoraleService; use Application\Service\Etablissement\EtablissementService; use Application\Service\Individu\IndividuServiceLocateTrait; use Application\Service\Role\RoleService; use Application\Service\UniteRecherche\UniteRechercheService; use Application\Service\Utilisateur\UtilisateurService; use Doctrine\ORM\EntityManager; use UnicaenLdap\Service\People as LdapPeopleService; Loading @@ -22,11 +25,17 @@ class UtilisateurControllerFactory * @var RoleService $roleService * @var UtilisateurService $utilisateurService * @var LdapPeopleService $ldapPeopleService * @var EtablissementService $etablissementService * @var EcoleDoctoraleService $ecoleService * @var UniteRechercheService $uniteService * @var EntityManager $entityManager; */ $roleService = $sl->get('RoleService'); $ldapPeopleService = $sl->get('LdapServicePeople'); $utilisateurService = $sl->get('UtilisateurService'); $etablissementService = $sl->get('EtablissementService'); $ecoleService = $sl->get('EcoleDoctoraleService'); $uniteService = $sl->get('UniteRechercheService'); $entityManager = $sl->get('doctrine.entitymanager.orm_default'); $controller = new UtilisateurController(); Loading @@ -34,6 +43,9 @@ class UtilisateurControllerFactory $controller->setLdapPeopleService($ldapPeopleService); $controller->setUtilisateurService($utilisateurService); $controller->setIndividuService($this->locateIndividuService($sl)); $controller->setUniteRechercheService($uniteService); $controller->setEcoleDoctoraleService($ecoleService); $controller->setEtablissementService($etablissementService); $controller->setEntityManager($entityManager); return $controller; Loading
module/Application/src/Application/Controller/UtilisateurController.php +46 −175 Original line number Diff line number Diff line Loading @@ -7,8 +7,11 @@ use Application\Entity\Db\Role; use Application\Entity\Db\Utilisateur; use Application\Form\CreationUtilisateurForm; use Application\RouteMatch; use Application\Service\EcoleDoctorale\EcoleDoctoraleServiceAwareTrait; use Application\Service\Etablissement\EtablissementServiceAwareTrait; use Application\Service\Individu\IndividuServiceAwareTrait; use Application\Service\Role\RoleServiceAwareTrait; use Application\Service\UniteRecherche\UniteRechercheServiceAwareTrait; use Application\Service\UserContextServiceAwareTrait; use Application\Service\Utilisateur\UtilisateurServiceAwareTrait; use Application\View\Helper\Sortable; Loading Loading @@ -39,168 +42,42 @@ class UtilisateurController extends \UnicaenAuth\Controller\UtilisateurControlle use LdapPeopleServiceAwareTrait; use IndividuServiceAwareTrait; use EntityManagerAwareTrait; use EcoleDoctoraleServiceAwareTrait; use UniteRechercheServiceAwareTrait; use EtablissementServiceAwareTrait; /** * @return array|\Zend\Http\Response|ViewModel * NOTA BENE : il s'agit des individus et non des utilisateurs car ils sont ceux qui portent les rôles */ public function indexAction() { /** * Application des filtres et tris par défaut. */ $needsRedirect = false; $queryParams = $this->params()->fromQuery(); // filtres // $etatThese = $this->params()->fromQuery($name = 'etatThese'); // if ($etatThese === null) { // null <=> paramètre absent // // filtrage par défaut : thèse en préparation // $queryParams = array_merge($queryParams, [$name => Utilisateur::ETAT_EN_COURS]); // $needsRedirect = true; // } // tris $sort = $this->params()->fromQuery('sort'); if ($sort === null) { // null <=> paramètre absent // tri par défaut : datePremiereInscription $queryParams = array_merge($queryParams, ['sort' => 'u.displayName', 'direction' => Sortable::ASC]); $needsRedirect = true; } // redirection si nécessaire if ($needsRedirect) { return $this->redirect()->toRoute(null, [], ['query' => $queryParams], true); } $text = $this->params()->fromQuery('text'); $dir = $this->params()->fromQuery('direction', Sortable::ASC); $maxi = $this->params()->fromQuery('maxi', 40); $page = $this->params()->fromQuery('page', 1); $individu = null; $roles = null; $qb = $this->utilisateurService->getRepository()->createQueryBuilder('u'); // if ($etatThese) { // $qb->andWhere('t.etatThese = :etat')->setParameter('etat', $etatThese); // } foreach (explode('+', $sort) as $sortProp) { $qb->addOrderBy($sortProp, $dir); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost()['individu']; /** @var Individu $individu */ $individu = $this->individuService->getIndviduById($data['id']); $rolesAffectes = $this->roleService->getRoleByIndividu($individu); } /** * Filtres découlant du rôle de l'utilisateur. */ $this->decorateQbFromSelectedRole($qb); /** * Prise en compte du champ de recherche textuelle. */ // if (strlen($text) > 1) { // $results = $this->theseService->rechercherThese($text); // $sourceCodes = array_unique(array_keys($results)); // if ($sourceCodes) { // $qb // ->andWhere($qb->expr()->in('t.sourceCode', ':sourceCodes')) // ->setParameter('sourceCodes', $sourceCodes); // } // else { // $qb->andWhere("0 = 1"); // i.e. aucune thèse trouvée // } // } $paginator = new \Zend\Paginator\Paginator(new DoctrinePaginator(new Paginator($qb, true))); $paginator ->setPageRange(30) ->setItemCountPerPage((int)$maxi) ->setCurrentPageNumber((int)$page); $roleModeles = $this->roleService->getRoleModeleByStructures(); $qb = $this->roleService->getRepository()->createQueryBuilder('r'); $qb ->join('r.source', 's', Join::WITH, 's.importable = 0') ->andWhere('r.attributionAutomatique = 0') ->andWhere($qb->expr()->notIn('r.roleId', [ Role::ROLE_ID_ECOLE_DOCT, Role::ROLE_ID_UNITE_RECH, ])) ->andWhere('1 = pasHistorise(r)') ->orderBy('r.roleId'); $rolesStatiques = $qb->getQuery()->getResult(); $qb = $this->roleService->getRepository()->createQueryBuilder('r') ->andWhere('r.attributionAutomatique = 1') ->andWhere('1 = pasHistorise(r)') ->orderBy('r.roleId'); $rolesDynamiques = $qb->getQuery()->getResult(); $roles = $this->roleService->getRoles(); $etablissements = $this->etablissementService->getEtablissements(); $unites = $this->uniteRechercheService->getUnitesRecherches(); $ecoles = $this->ecoleDoctoraleService->getEcolesDoctorales(); return new ViewModel([ 'utilisateurs' => $paginator, 'modeles' => $roleModeles, 'roles' => $rolesStatiques, 'rolesDynamiques' => $rolesDynamiques, 'text' => $text, 'individu' => $individu, 'roles' => $roles, 'rolesAffectes' => $rolesAffectes, 'etablissements' => $etablissements, 'ecoles' => $ecoles, 'unites' => $unites, ]); } private function decorateQbFromSelectedRole(QueryBuilder $qb) { return $qb; } public function ajouterAction() { $data = $this->params()->fromPost('people'); if (!empty($data['id'])) { /** @var People $people */ if ($people = $this->ldapPeopleService->get($data['id'])) { $username = $people->get('supannAliasLogin'); $utilisateur = $this->utilisateurService->getRepository()->findOneBy(['username' => $username]); if (! $utilisateur) { $utilisateur = $this->utilisateurService->createFromPeople($people); $this->flashMessenger()->addSuccessMessage("$utilisateur a été ajouté-e avec succès à la liste des utilisateurs"); } else { $this->flashMessenger()->addErrorMessage("$utilisateur existe déjà dans la liste des utilisateurs"); } } } return $this->redirect()->toRoute('utilisateur'); } public function attribuerRoleAction() { $utilisateur = $this->requestUtilisateur(); $role = $this->postRole(); if (! $role) { exit; } $qb = $this->utilisateurService->getRepository()->createQueryBuilder('u') ->addSelect('r') ->join('u.roles', 'r', Join::WITH, 'r = :role') ->andWhere('u = :user') ->setParameter('role', $role) ->setParameter('user', $utilisateur); $result = $qb->getQuery()->getResult(); // retrait du rôle if (count($result) > 0) { $utilisateur->removeRole($role); $message = "Le rôle '$role' a été retiré avec succès à l'utilisateur '$utilisateur'."; } // accord du rôle else { $utilisateur->addRole($role); $message = "Le rôle '$role' a été accordé avec succès à l'utilisateur '$utilisateur'."; } try { $this->utilisateurService->getEntityManager()->flush($utilisateur); } catch (OptimisticLockException $e) { throw new RuntimeException("Erreur rencontrée lors de l'enregistrement de l'utilisateur", null, $e); } return new JsonModel(['status' => 'success', 'message' => $message]); } /** * AJAX. * Loading Loading @@ -273,32 +150,6 @@ class UtilisateurController extends \UnicaenAuth\Controller\UtilisateurControlle exit; } /** * @return Utilisateur */ private function requestUtilisateur() { /** @var RouteMatch $match */ $match = $this->getEvent()->getRouteMatch(); return $match->getUtilisateur(); } /** * @return Role */ private function postRole() { $roleId = $this->params()->fromPost('role'); if (! $roleId) { return null; } /** @var Role $role */ $role = $this->roleService->getRepository()->findOneBy([(is_numeric($roleId) ? 'id' : 'roleId') => $roleId]); return $role; } public function creationUtilisateurAction() { Loading Loading @@ -347,4 +198,24 @@ class UtilisateurController extends \UnicaenAuth\Controller\UtilisateurControlle 'form' => $form, ]); } public function retirerRoleAction() { $individuId = $this->params()->fromRoute('individu'); $roleId = $this->params()->fromRoute('role'); $this->roleService->removeRole($individuId, $roleId); return new ViewModel([]); } public function ajouterRoleAction() { $individuId = $this->params()->fromRoute('individu'); $roleId = $this->params()->fromRoute('role'); $this->roleService->addRole($individuId, $roleId); return new ViewModel([]); } } No newline at end of file
module/Application/src/Application/Entity/Db/Individu.php +1 −0 Original line number Diff line number Diff line Loading @@ -359,6 +359,7 @@ class Individu implements HistoriqueAwareInterface, SourceAwareInterface */ public function getDateNaissanceToString() { if ($this->dateNaissance === null) return ""; return $this->dateNaissance->format(Constants::DATE_FORMAT); } Loading
module/Application/src/Application/Service/Role/RoleService.php +49 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,21 @@ class RoleService extends BaseService return $individuRole; } public function getRoleByIndividu($individu) { $qb = $this->getEntityManager()->getRepository(IndividuRole::class)->createQueryBuilder("ir") ->andWhere("ir.individu = :individu") ->setParameter("individu", $individu); $results = $qb->getQuery()->getResult(); /** @var IndividuRole $result */ $roles = []; foreach($results as $result) { $roles[] = $result->getRole(); } return $roles; } /** * @param int $individuRoleId Loading Loading @@ -219,5 +234,39 @@ class RoleService extends BaseService return $role; } public function removeRole($individuId, $roleId) { $qb = $this->getEntityManager()->getRepository(IndividuRole::class)->createQueryBuilder("ir") ->leftJoin("ir.individu","i") ->leftJoin("ir.role","r") ->andWhere("i.id = :individuId") ->andWhere("r.id = :roleId") ->setParameter("individuId", $individuId) ->setParameter("roleId", $roleId); $result = $qb->getQuery()->getOneOrNullResult(); if ($result !== null) { $this->getEntityManager()->remove($result); $this->getEntityManager()->flush($result); } } public function addRole($individuId, $roleId) { $individu = $this->getEntityManager()->getRepository(Individu::class)->findOneBy(["id"=>$individuId]); $role = $this->getEntityManager()->getRepository(Role::class)->findOneBy(["id"=>$roleId]); $ir = new IndividuRole(); $ir->setIndividu($individu); $ir->setRole($role); $this->getEntityManager()->persist($ir); $this->getEntityManager()->flush($ir); } public function getRoles() { $result = $this->getEntityManager()->getRepository(Role::class)->findAll(); return $result; } } No newline at end of file