Skip to content
Snippets Groups Projects
Commit fda92c48 authored by lecluse's avatar lecluse
Browse files

Nouvelle optimisation au niveau des rôles de type établissement.

Nouvelle gestion des périmètres simplifiée et augmentée.
Refactoring
parent 4a5507a2
No related branches found
No related tags found
No related merge requests found
...@@ -111,11 +111,11 @@ class Module implements ConsoleUsageProviderInterface, ConsoleBannerProviderInte ...@@ -111,11 +111,11 @@ class Module implements ConsoleUsageProviderInterface, ConsoleBannerProviderInte
{ {
$role = $e->getApplication()->getServiceManager()->get('ApplicationContext')->getSelectedIdentityRole(); $role = $e->getApplication()->getServiceManager()->get('ApplicationContext')->getSelectedIdentityRole();
$routeMatch = $e->getRouteMatch(); $routeMatch = $e->getRouteMatch();
if ($role instanceof Acl\IntervenantRole) { if ($intervenant = $role->getIntervenant()) {
if (($value = $routeMatch->getParam($name = 'intervenant')) && $value != $role->getIntervenant()->getSourceCode()) { if (($value = $routeMatch->getParam($name = 'intervenant')) && $value != $intervenant->getSourceCode()) {
$routeMatch->setParam($name, $role->getIntervenant()->getSourceCode()); $routeMatch->setParam($name, $intervenant->getSourceCode());
} }
$routeMatch->setParam('intervenant', $role->getIntervenant()->getSourceCode()); $routeMatch->setParam('intervenant', $intervenant->getSourceCode());
} }
} }
......
...@@ -778,7 +778,6 @@ return array( ...@@ -778,7 +778,6 @@ return array(
'Application\View\Helper\OffreFormation\EtapeCentreCoutFormViewHelper' => __DIR__ . '/src/Application/View/Helper/OffreFormation/EtapeCentreCoutFormViewHelper.php', 'Application\View\Helper\OffreFormation\EtapeCentreCoutFormViewHelper' => __DIR__ . '/src/Application/View/Helper/OffreFormation/EtapeCentreCoutFormViewHelper.php',
'Application\View\Helper\OffreFormation\ElementModulateursSaisieFieldset' => __DIR__ . '/src/Application/View/Helper/OffreFormation/ElementModulateursSaisieFieldset.php', 'Application\View\Helper\OffreFormation\ElementModulateursSaisieFieldset' => __DIR__ . '/src/Application/View/Helper/OffreFormation/ElementModulateursSaisieFieldset.php',
'Application\View\Helper\EtablissementViewHelper' => __DIR__ . '/src/Application/View/Helper/EtablissementViewHelper.php', 'Application\View\Helper\EtablissementViewHelper' => __DIR__ . '/src/Application/View/Helper/EtablissementViewHelper.php',
'Application\View\Helper\IsAllowedCRUD' => __DIR__ . '/src/Application/View/Helper/IsAllowedCRUD.php',
'Application\View\Helper\Workflow' => __DIR__ . '/src/Application/View/Helper/Workflow.php', 'Application\View\Helper\Workflow' => __DIR__ . '/src/Application/View/Helper/Workflow.php',
'Application\View\Helper\VolumeHoraire\Liste' => __DIR__ . '/src/Application/View/Helper/VolumeHoraire/Liste.php', 'Application\View\Helper\VolumeHoraire\Liste' => __DIR__ . '/src/Application/View/Helper/VolumeHoraire/Liste.php',
'Application\View\Helper\AgrementViewHelper' => __DIR__ . '/src/Application/View/Helper/AgrementViewHelper.php', 'Application\View\Helper\AgrementViewHelper' => __DIR__ . '/src/Application/View/Helper/AgrementViewHelper.php',
......
...@@ -226,7 +226,6 @@ return [ ...@@ -226,7 +226,6 @@ return [
'view_helpers' => [ 'view_helpers' => [
'invokables' => [ 'invokables' => [
'agrement' => 'Application\View\Helper\AgrementViewHelper', 'agrement' => 'Application\View\Helper\AgrementViewHelper',
'isAllowedCRUD' => 'Application\View\Helper\IsAllowedCRUD',
], ],
], ],
'form_elements' => [ 'form_elements' => [
......
...@@ -3,82 +3,25 @@ ...@@ -3,82 +3,25 @@
namespace Application\Acl; namespace Application\Acl;
use UnicaenAuth\Acl\NamedRole; use UnicaenAuth\Acl\NamedRole;
use Application\Entity\Db\Role as DbRole; use Application\Entity\Db\Traits\StructureAwareTrait;
use Application\Entity\Db\Traits\PersonnelAwareTrait;
use Application\Entity\Db\Traits\IntervenantAwareTrait;
use Application\Entity\Db\Traits\PerimetreAwareTrait;
/** /**
* Rôle père de tous les rôles "administrateur". * Rôle
* *
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/ */
class Role extends NamedRole class Role extends NamedRole
{ {
use \Application\Entity\Db\Traits\StructureAwareTrait, use StructureAwareTrait;
\Application\Entity\Db\Traits\PersonnelAwareTrait, use PersonnelAwareTrait;
\Application\Entity\Db\Traits\IntervenantAwareTrait; use IntervenantAwareTrait;
use PerimetreAwareTrait;
const ROLE_ID = 'role'; const ROLE_ID = 'role';
/**
* Rôle en BDD
*
* @var DbRole
*/
protected $dbRole;
/**
* Détermine si le périmètre du rôle courant est de niveau intervenant
*
* @return bool
*/
public function isPerimetreIntervenant()
{
return $this->getIntervenant() ? true : false;
}
/**
* Détermine si le périmètre du rôle courant est de niveau composante
*
* @return bool
*/
public function isPerimetreComposante()
{
return $this->getStructure() ? true : false;
}
/**
* Détermine si le périmètre du rôle courant est de niveau établissement
*
* @return bool
*/
public function isPerimetreEtablissement()
{
return !$this->getStructure() && !$this->getIntervenant();
}
/**
* Détermine si le rôle courant possède un privilège ou non
*
* @param $privilege
*
* @return bool
*/
public function hasPrivilege($privilege)
{
if ($this->dbRole) {
return $this->dbRole->hasPrivilege($privilege);
} else {
return false;
}
}
public function __construct($id = self::ROLE_ID, $parent = 'user', $name = 'Rôle', $description = null, $selectable = true) public function __construct($id = self::ROLE_ID, $parent = 'user', $name = 'Rôle', $description = null, $selectable = true)
......
...@@ -93,7 +93,7 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface ...@@ -93,7 +93,7 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface
$serviceAuthUserContext = $this->getServiceLocator()->get('AuthUserContext'); $serviceAuthUserContext = $this->getServiceLocator()->get('AuthUserContext');
/* @var $serviceAuthUserContext \UnicaenAuth\Service\UserContext */ /* @var $serviceAuthUserContext \UnicaenAuth\Service\UserContext */
$utilisateur = $serviceAuthUserContext->getDbUser();
if ($ldapUser = $serviceAuthUserContext->getLdapUser()) { if ($ldapUser = $serviceAuthUserContext->getLdapUser()) {
$numeroPersonnel = (integer)$ldapUser->getSupannEmpId(); $numeroPersonnel = (integer)$ldapUser->getSupannEmpId();
...@@ -109,8 +109,9 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface ...@@ -109,8 +109,9 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface
// chargement des rôles métiers // chargement des rôles métiers
$qb = $this->getEntityManager()->createQueryBuilder() $qb = $this->getEntityManager()->createQueryBuilder()
->from("Application\Entity\Db\Role", "r") ->from("Application\Entity\Db\Role", "r")
->select("r, a, s") ->select("r, a, s, p")
->distinct() ->distinct()
->join("r.perimetre", "p")
->leftJoin("r.affectation", "a", \Doctrine\ORM\Query\Expr\Join::WITH, '1=compriseEntre(a.histoCreation,a.histoDestruction) AND a.personnel = :personnel') ->leftJoin("r.affectation", "a", \Doctrine\ORM\Query\Expr\Join::WITH, '1=compriseEntre(a.histoCreation,a.histoDestruction) AND a.personnel = :personnel')
->leftJoin("a.structure", "s") ->leftJoin("a.structure", "s")
->andWhere('1=compriseEntre(r.histoCreation,r.histoDestruction)') ->andWhere('1=compriseEntre(r.histoCreation,r.histoDestruction)')
...@@ -148,7 +149,9 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface ...@@ -148,7 +149,9 @@ class RoleProvider implements ProviderInterface, EntityManagerAwareInterface
/* FIN de deprecated */ /* FIN de deprecated */
$role = new $roleClass($roleId, $parent, $dbRole->getLibelle()); $role = new $roleClass($roleId, $parent, $dbRole->getLibelle());
/* @var $role Role */
$role->setPersonnel($personnel); $role->setPersonnel($personnel);
$role->setPerimetre($dbRole->getPerimetre());
// Si le rôle est de périmètre établissement, alors il se peut que l'on veuille zoomer sur une composante en particulier... // Si le rôle est de périmètre établissement, alors il se peut que l'on veuille zoomer sur une composante en particulier...
if ($this->structureSelectionnee && $dbRole->getPerimetre()->isEtablissement()) { if ($this->structureSelectionnee && $dbRole->getPerimetre()->isEtablissement()) {
......
<?php
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
/**
* IsAllowed View helper. Allows checking access to a resource/privilege in views.
*
* @author
*/
class IsAllowedCRUD extends AbstractHelper
{
/**
* @param mixed $resource
*
* @return bool
*/
public function __invoke($resource)
{
if ($this->getView()->isAllowed($resource, 'create')) {
echo 'create';
}
elseif ($this->getView()->isAllowed($resource, 'read')) {
echo 'read';
}
elseif ($this->getView()->isAllowed($resource, 'update')) {
echo 'update';
}
elseif ($this->getView()->isAllowed($resource, 'delete')) {
echo 'delete';
}
}
}
\ No newline at end of file
<?php <?php
namespace Application\View\Helper; namespace Application\View\Helper;
use Application\Traits\SessionContainerTrait;
use UnicaenAuth\View\Helper\UserProfileSelectRadioItem as UnicaenAuthViewHelper; use UnicaenAuth\View\Helper\UserProfileSelectRadioItem as UnicaenAuthViewHelper;
use Application\Service\Traits\StructureAwareTrait as StructureServiceAwareTrait;
use Application\Entity\Db\Traits\StructureAwareTrait;
/** /**
* Aide de vue dessinant un item de sélection d'un profil utilisateur. * Aide de vue dessinant un item de sélection d'un profil utilisateur.
...@@ -13,9 +15,10 @@ use UnicaenAuth\View\Helper\UserProfileSelectRadioItem as UnicaenAuthViewHelper; ...@@ -13,9 +15,10 @@ use UnicaenAuth\View\Helper\UserProfileSelectRadioItem as UnicaenAuthViewHelper;
*/ */
class UserProfileSelectRadioItem extends UnicaenAuthViewHelper class UserProfileSelectRadioItem extends UnicaenAuthViewHelper
{ {
use \Application\Service\Traits\StructureAwareTrait, use StructureServiceAwareTrait;
\Application\Entity\Db\Traits\StructureAwareTrait use StructureAwareTrait;
; use SessionContainerTrait;
/** /**
* Retourne le code HTML généré par cette aide de vue. * Retourne le code HTML généré par cette aide de vue.
...@@ -26,13 +29,15 @@ class UserProfileSelectRadioItem extends UnicaenAuthViewHelper ...@@ -26,13 +29,15 @@ class UserProfileSelectRadioItem extends UnicaenAuthViewHelper
{ {
$html = parent::render(); $html = parent::render();
if ($this->role instanceof \Application\Acl\AdministrateurRole) { $perimetre = $this->role->getPerimetre();
if ($perimetre && $perimetre->isEtablissement()) {
$selectClass = 'user-profile-select-input-structure'; $selectClass = 'user-profile-select-input-structure';
$select = new \Zend\Form\Element\Select('structure'); $select = new \Zend\Form\Element\Select('structure');
$select $select
->setEmptyOption("(Aucune)") ->setEmptyOption("(Aucune)")
->setValueOptions(array_map(function($v) { return (string) $v; }, $this->getStructures())) ->setValueOptions($this->getStructures())
->setValue($this->getStructure() ? $this->getStructure()->getId() : null) ->setValue($this->getStructure() ? $this->getStructure()->getId() : null)
->setAttribute('class', $selectClass) ->setAttribute('class', $selectClass)
->setAttribute('title', "Cliquez pour sélectionner la structure associée au profil $this->role"); ->setAttribute('title', "Cliquez pour sélectionner la structure associée au profil $this->role");
...@@ -67,7 +72,9 @@ EOS; ...@@ -67,7 +72,9 @@ EOS;
{ {
$radio = parent::createRadio(); $radio = parent::createRadio();
if ($this->role instanceof \Application\Acl\AdministrateurRole) { $perimetre = $this->role->getPerimetre();
if ($perimetre && $perimetre->isEtablissement()) {
$id = $this->role->getRoleId(); $id = $this->role->getRoleId();
$radio->setValueOptions([$id => $this->role->getRoleName()]); $radio->setValueOptions([$id => $this->role->getRoleName()]);
} }
...@@ -82,7 +89,16 @@ EOS; ...@@ -82,7 +89,16 @@ EOS;
*/ */
private function getStructures() private function getStructures()
{ {
$session = $this->getSessionContainer();
if (! isset($session->structures)){
$qb = $this->getServiceStructure()->finderByEnseignement(); $qb = $this->getServiceStructure()->finderByEnseignement();
return $this->getServiceStructure()->getList($qb); $s = $this->getServiceStructure()->getList($qb);
$session->structures = [];
foreach( $s as $structure ){
$session->structures[$structure->getId()] = (string)$structure;
}
}
return $session->structures;
} }
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ echo $this->messenger()->addMessagesFromFlashMessenger(); ...@@ -17,7 +17,7 @@ echo $this->messenger()->addMessagesFromFlashMessenger();
<?php <?php
if ($role){ if ($role){
if ($role->isPerimetreIntervenant()){ if ($role->getIntervenant()){
$intervenant = $role->getIntervenant(); $intervenant = $role->getIntervenant();
if ($intervenant->getStatut()->getNonAutorise()){ if ($intervenant->getStatut()->getNonAutorise()){
...@@ -38,7 +38,7 @@ echo $this->messenger()->addMessagesFromFlashMessenger(); ...@@ -38,7 +38,7 @@ echo $this->messenger()->addMessagesFromFlashMessenger();
} }
}elseif ($role->isPerimetreComposante()) { }elseif ($role->getStructure()) {
$url = $this->url('service/resume'); $url = $this->url('service/resume');
$label = $this->translate("Tableau synthétique des enseignements concernant ma composante..."); $label = $this->translate("Tableau synthétique des enseignements concernant ma composante...");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment