Loading code/test2.php +2 −18 Changes for code/test2.php: 2 added lines, 18 removed lines. Original line number Diff line number Diff line Loading @@ -8,21 +8,5 @@ * @var $viewFile string */ /** * @var $si \Application\Service\IntervenantService */ $si = $container->get(\Application\Service\IntervenantService::class); $routeParams = [ 'code:OSE5ea29a39d99a0', '51954', '51965', '39778', '45xc', ]; foreach ($routeParams as $routeParam) { $i = $si->getByRouteParam($routeParam); var_dump($routeParam . ' = ' . ($i ? $i->getId() . ':' : '- NULL -') . $i); } $sql = 'update intervenant set utilisateur_code = \'dd\' where id = 196998;'; $container->get(\Application\Constants::BDD)->getConnection()->execute($sql); No newline at end of file data/ddl/trigger/INTERVENANT_CK.sql +12 −0 Changes for data/ddl/trigger/INTERVENANT_CK.sql: 12 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -36,4 +36,16 @@ BEGIN IF cs > 0 THEN raise_application_error(-20101, 'Un intervenant ne peut pas avoir deux fois le même statut le même année'); END IF; -- On ne peut pas assicoer un même login à plusieurs intervenants SELECT COUNT(*) INTO cs FROM INTERVENANT WHERE id <> :NEW.id AND histo_destruction IS NULL AND code <> :NEW.code AND annee_id = :NEW.annee_id AND utilisateur_code = :NEW.utilisateur_code ; IF cs > 0 THEN raise_application_error(-20101, 'L''utilisateur est déjà utilisé pour un autre intervenant. Merci d''en choisir un autre.'); END IF; END; No newline at end of file module/Application/src/Application/Connecteur/LdapConnecteur.php +56 −3 Changes for module/Application/src/Application/Connecteur/LdapConnecteur.php: 56 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -98,6 +98,13 @@ class LdapConnecteur extends AbstractService public function isActif(): bool { return \AppConfig::get('ldap', 'actif', true); } /** * @param string $critere * Loading @@ -106,7 +113,7 @@ class LdapConnecteur extends AbstractService public function rechercheUtilisateurs($critere) { $result = []; if (($username = $critere) && \AppConfig::get('ldap', 'actif', true)) { if (($username = $critere) && $this->isActif()) { $foundUsers = $this->mapperPeople->findAllByNameOrUsername($username, $this->getUtilisateurLogin(), $this->getUtilisateurFiltre()); /* @var $foundUsers People[] */ Loading Loading @@ -155,7 +162,6 @@ class LdapConnecteur extends AbstractService /** * Enregistre un people dans la BDD et retourne l'enregistrement correspondant. S'il existe déjà alors il est simplement * retourné... Loading @@ -165,7 +171,7 @@ class LdapConnecteur extends AbstractService * * @return Utilisateur */ public function getUtilisateur($login, $autoInsert = true) public function getUtilisateur(string $login, bool $autoInsert = true): ?Utilisateur { if ($user = $this->getServiceUtilisateur()->getRepo()->findOneBy(['username' => $login])) return $user; // si on le trouve alors c'est OK if ($user = $this->mapperUser->findByUsername($login)) return $user; // si on le trouve alors c'est OK Loading @@ -190,6 +196,53 @@ class LdapConnecteur extends AbstractService /** * Enregistre un people dans la BDD et retourne l'enregistrement correspondant. S'il existe déjà alors il est simplement * retourné... * * @param string $login * @param boolean $autoInsert * * @return Utilisateur */ public function getUtilisateurFromCode(string $code, bool $autoInsert = true): ?Utilisateur { if ($user = $this->getServiceUtilisateur()->getRepo()->findOneBy(['code' => $code])) return $user; // si on le trouve alors c'est OK if ($this->isActif()) { $ldapUser = $this->mapperPeople->findOneByNoIndividu($code); if ($ldapUser) { $login = $this->getPeopleAttribute($ldapUser, $this->getUtilisateurLogin()); return $this->getUtilisateur($login, $autoInsert); } } return null; } public function getCodeFromLogin(string $login): ?string { $code = null; $u = $this->getUtilisateur($login); if ($u) { $code = $u->getCode(); } if (!$code && $this->isActif()) { $ldapUser = $this->mapperPeople->findOneByUsername($login); $code = $this->getPeopleAttribute($ldapUser, $this->getUtilisateurCode()); } return $code; } /** * @return Utilisateur */ Loading module/Application/src/Application/Controller/IntervenantController.php +13 −1 Changes for module/Application/src/Application/Controller/IntervenantController.php: 13 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ use Application\Service\Traits\RegleStructureValidationServiceAwareTrait; use Application\Service\Traits\SourceServiceAwareTrait; use Application\Service\Traits\StatutIntervenantServiceAwareTrait; use Application\Service\Traits\TypeVolumeHoraireServiceAwareTrait; use Application\Service\Traits\UtilisateurServiceAwareTrait; use Application\Service\Traits\ValidationServiceAwareTrait; use Application\Service\Traits\WorkflowServiceAwareTrait; use UnicaenApp\Traits\SessionContainerTrait; Loading Loading @@ -58,7 +59,7 @@ class IntervenantController extends AbstractController use RegleStructureValidationFormAwareTrait; use StatutIntervenantServiceAwareTrait; use SourceServiceAwareTrait; use UtilisateurServiceAwareTrait; public function indexAction() Loading Loading @@ -316,6 +317,17 @@ class IntervenantController extends AbstractController if ((!$form->isReadOnly()) && $form->isValid()) { try { $form->protection($intervenant); if ($form->get('login')->getValue() && $form->get('password')->getValue()) { $nom = $intervenant->getNomUsuel(); $prenom = $intervenant->getPrenom(); $dateNaissance = $intervenant->getDateNaissance(); $login = $form->get('login')->getValue(); $password = $form->get('password')->getValue(); $utilisateur = $this->getServiceUtilisateur()->creerUtilisateur($nom, $prenom, $dateNaissance, $login, $password); $utilisateur->setCode($intervenant->getCode()); $this->getServiceUtilisateur()->save($utilisateur); $intervenant->setUtilisateurCode($utilisateur->getCode()); } $this->getServiceIntervenant()->save($intervenant); $this->getServiceWorkflow()->calculerTableauxBord([], $intervenant); $form->get('id')->setValue($intervenant->getId()); // transmet le nouvel ID Loading module/Application/src/Application/Form/Intervenant/EditionForm.php +100 −4 Changes for module/Application/src/Application/Form/Intervenant/EditionForm.php: 100 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Application\Form\Intervenant; use Application\Connecteur\Traits\LdapConnecteurAwareTrait; use Application\Entity\Db\Civilite; use Application\Entity\Db\Discipline; use Application\Entity\Db\Grade; Loading @@ -18,6 +19,8 @@ use Application\Service\Traits\GradeServiceAwareTrait; use Application\Service\Traits\SourceServiceAwareTrait; use Application\Service\Traits\StatutIntervenantServiceAwareTrait; use Application\Service\Traits\StructureServiceAwareTrait; use Application\Service\Traits\UtilisateurServiceAwareTrait; use UnicaenApp\Form\Element\SearchAndSelect; use UnicaenApp\Util; use UnicaenImport\Entity\Db\Source; use UnicaenImport\Service\Traits\SchemaServiceAwareTrait; Loading Loading @@ -67,7 +70,7 @@ class EditionForm extends AbstractForm public function init() { $hydrator = new GenericHydrator($this->getServiceSource()->getEntityManager(), $this->hydratorElements); $hydrator = new EditionFormHydrator($this->getServiceSource()->getEntityManager(), $this->hydratorElements); $this->setHydrator($hydrator); $this->setAttribute('action', $this->getCurrentUrl()); $this->setAttribute('class', 'form-intervenant-edition no-intranavigation'); Loading Loading @@ -203,12 +206,43 @@ class EditionForm extends AbstractForm ], ]); $utilisateur = new SearchAndSelect('utilisateur'); $utilisateur->setRequired(false) ->setSelectionRequired(false) ->setAutocompleteSource( $this->getUrl('recherche', ['action' => 'utilisateurFind']) ) ->setLabel("Utilisateur") ->setAttributes(['title' => "Saisissez le nom suivi éventuellement du prénom (2 lettres au moins)"]); $this->add($utilisateur); $this->add([ 'name' => 'login', 'type' => 'Text', 'options' => [ 'label' => 'Login', ], ]); $this->add([ 'name' => 'password', 'type' => 'Password', 'options' => [ 'label' => 'Mot de passe', ], ]); $this->add([ 'name' => 'utilisateurCode', 'name' => 'prenom', 'type' => 'Text', 'options' => [ 'label' => 'Identifiant LDAP éventuel (' . \AppConfig::get('ldap', 'utilisateurCode', 'supannEmpId') . ')', 'label' => 'Prénom <span class="text-danger">*</span>', 'label_options' => ['disable_html_escape' => true], ], ]); $this->add([ Loading Loading @@ -407,10 +441,72 @@ class EditionForm extends AbstractForm 'discipline' => ['required' => false], 'grade' => ['required' => false], 'code' => ['required' => true], 'utilisateurCode' => ['required' => false], 'utilisateur' => ['required' => false], 'login' => ['required' => false], 'password' => ['required' => false], 'source' => ['required' => false], 'sourceCode' => ['required' => false], 'montantIndemniteFc' => ['required' => false], ]; } } class EditionFormHydrator extends GenericHydrator { use UtilisateurServiceAwareTrait; use LdapConnecteurAwareTrait; protected $noGenericParse = ['utilisateur', 'creerUtilisateur']; /** * @param array $data * @param \Application\Entity\Db\Intervenant $object * * @return object */ public function hydrate(array $data, $object) { parent::hydrate($data, $object); $login = isset($data['utilisateur']['id']) ? $data['utilisateur']['id'] : null; if ($login) { $code = $this->getConnecteurLdap()->getCodeFromLogin($login); } else { $code = null; } $object->setUtilisateurCode($code); } /** * @param \Application\Entity\Db\Intervenant $object * * @return array */ public function extract($object) { $res = parent::extract($object); $res['creerUtilisateur'] = !$object->getId() && !\AppConfig::get('cas', 'actif'); if ($code = $object->getUtilisateurCode()) { $utilisateur = $this->getConnecteurLdap()->getUtilisateurFromCode($code, false); if ($utilisateur) { $res['utilisateur'] = [ 'id' => $utilisateur->getUsername(), 'label' => (string)$utilisateur, ]; } } return $res; } } No newline at end of file Loading
code/test2.php +2 −18 Changes for code/test2.php: 2 added lines, 18 removed lines. Original line number Diff line number Diff line Loading @@ -8,21 +8,5 @@ * @var $viewFile string */ /** * @var $si \Application\Service\IntervenantService */ $si = $container->get(\Application\Service\IntervenantService::class); $routeParams = [ 'code:OSE5ea29a39d99a0', '51954', '51965', '39778', '45xc', ]; foreach ($routeParams as $routeParam) { $i = $si->getByRouteParam($routeParam); var_dump($routeParam . ' = ' . ($i ? $i->getId() . ':' : '- NULL -') . $i); } $sql = 'update intervenant set utilisateur_code = \'dd\' where id = 196998;'; $container->get(\Application\Constants::BDD)->getConnection()->execute($sql); No newline at end of file
data/ddl/trigger/INTERVENANT_CK.sql +12 −0 Changes for data/ddl/trigger/INTERVENANT_CK.sql: 12 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -36,4 +36,16 @@ BEGIN IF cs > 0 THEN raise_application_error(-20101, 'Un intervenant ne peut pas avoir deux fois le même statut le même année'); END IF; -- On ne peut pas assicoer un même login à plusieurs intervenants SELECT COUNT(*) INTO cs FROM INTERVENANT WHERE id <> :NEW.id AND histo_destruction IS NULL AND code <> :NEW.code AND annee_id = :NEW.annee_id AND utilisateur_code = :NEW.utilisateur_code ; IF cs > 0 THEN raise_application_error(-20101, 'L''utilisateur est déjà utilisé pour un autre intervenant. Merci d''en choisir un autre.'); END IF; END; No newline at end of file
module/Application/src/Application/Connecteur/LdapConnecteur.php +56 −3 Changes for module/Application/src/Application/Connecteur/LdapConnecteur.php: 56 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -98,6 +98,13 @@ class LdapConnecteur extends AbstractService public function isActif(): bool { return \AppConfig::get('ldap', 'actif', true); } /** * @param string $critere * Loading @@ -106,7 +113,7 @@ class LdapConnecteur extends AbstractService public function rechercheUtilisateurs($critere) { $result = []; if (($username = $critere) && \AppConfig::get('ldap', 'actif', true)) { if (($username = $critere) && $this->isActif()) { $foundUsers = $this->mapperPeople->findAllByNameOrUsername($username, $this->getUtilisateurLogin(), $this->getUtilisateurFiltre()); /* @var $foundUsers People[] */ Loading Loading @@ -155,7 +162,6 @@ class LdapConnecteur extends AbstractService /** * Enregistre un people dans la BDD et retourne l'enregistrement correspondant. S'il existe déjà alors il est simplement * retourné... Loading @@ -165,7 +171,7 @@ class LdapConnecteur extends AbstractService * * @return Utilisateur */ public function getUtilisateur($login, $autoInsert = true) public function getUtilisateur(string $login, bool $autoInsert = true): ?Utilisateur { if ($user = $this->getServiceUtilisateur()->getRepo()->findOneBy(['username' => $login])) return $user; // si on le trouve alors c'est OK if ($user = $this->mapperUser->findByUsername($login)) return $user; // si on le trouve alors c'est OK Loading @@ -190,6 +196,53 @@ class LdapConnecteur extends AbstractService /** * Enregistre un people dans la BDD et retourne l'enregistrement correspondant. S'il existe déjà alors il est simplement * retourné... * * @param string $login * @param boolean $autoInsert * * @return Utilisateur */ public function getUtilisateurFromCode(string $code, bool $autoInsert = true): ?Utilisateur { if ($user = $this->getServiceUtilisateur()->getRepo()->findOneBy(['code' => $code])) return $user; // si on le trouve alors c'est OK if ($this->isActif()) { $ldapUser = $this->mapperPeople->findOneByNoIndividu($code); if ($ldapUser) { $login = $this->getPeopleAttribute($ldapUser, $this->getUtilisateurLogin()); return $this->getUtilisateur($login, $autoInsert); } } return null; } public function getCodeFromLogin(string $login): ?string { $code = null; $u = $this->getUtilisateur($login); if ($u) { $code = $u->getCode(); } if (!$code && $this->isActif()) { $ldapUser = $this->mapperPeople->findOneByUsername($login); $code = $this->getPeopleAttribute($ldapUser, $this->getUtilisateurCode()); } return $code; } /** * @return Utilisateur */ Loading
module/Application/src/Application/Controller/IntervenantController.php +13 −1 Changes for module/Application/src/Application/Controller/IntervenantController.php: 13 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ use Application\Service\Traits\RegleStructureValidationServiceAwareTrait; use Application\Service\Traits\SourceServiceAwareTrait; use Application\Service\Traits\StatutIntervenantServiceAwareTrait; use Application\Service\Traits\TypeVolumeHoraireServiceAwareTrait; use Application\Service\Traits\UtilisateurServiceAwareTrait; use Application\Service\Traits\ValidationServiceAwareTrait; use Application\Service\Traits\WorkflowServiceAwareTrait; use UnicaenApp\Traits\SessionContainerTrait; Loading Loading @@ -58,7 +59,7 @@ class IntervenantController extends AbstractController use RegleStructureValidationFormAwareTrait; use StatutIntervenantServiceAwareTrait; use SourceServiceAwareTrait; use UtilisateurServiceAwareTrait; public function indexAction() Loading Loading @@ -316,6 +317,17 @@ class IntervenantController extends AbstractController if ((!$form->isReadOnly()) && $form->isValid()) { try { $form->protection($intervenant); if ($form->get('login')->getValue() && $form->get('password')->getValue()) { $nom = $intervenant->getNomUsuel(); $prenom = $intervenant->getPrenom(); $dateNaissance = $intervenant->getDateNaissance(); $login = $form->get('login')->getValue(); $password = $form->get('password')->getValue(); $utilisateur = $this->getServiceUtilisateur()->creerUtilisateur($nom, $prenom, $dateNaissance, $login, $password); $utilisateur->setCode($intervenant->getCode()); $this->getServiceUtilisateur()->save($utilisateur); $intervenant->setUtilisateurCode($utilisateur->getCode()); } $this->getServiceIntervenant()->save($intervenant); $this->getServiceWorkflow()->calculerTableauxBord([], $intervenant); $form->get('id')->setValue($intervenant->getId()); // transmet le nouvel ID Loading
module/Application/src/Application/Form/Intervenant/EditionForm.php +100 −4 Changes for module/Application/src/Application/Form/Intervenant/EditionForm.php: 100 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Application\Form\Intervenant; use Application\Connecteur\Traits\LdapConnecteurAwareTrait; use Application\Entity\Db\Civilite; use Application\Entity\Db\Discipline; use Application\Entity\Db\Grade; Loading @@ -18,6 +19,8 @@ use Application\Service\Traits\GradeServiceAwareTrait; use Application\Service\Traits\SourceServiceAwareTrait; use Application\Service\Traits\StatutIntervenantServiceAwareTrait; use Application\Service\Traits\StructureServiceAwareTrait; use Application\Service\Traits\UtilisateurServiceAwareTrait; use UnicaenApp\Form\Element\SearchAndSelect; use UnicaenApp\Util; use UnicaenImport\Entity\Db\Source; use UnicaenImport\Service\Traits\SchemaServiceAwareTrait; Loading Loading @@ -67,7 +70,7 @@ class EditionForm extends AbstractForm public function init() { $hydrator = new GenericHydrator($this->getServiceSource()->getEntityManager(), $this->hydratorElements); $hydrator = new EditionFormHydrator($this->getServiceSource()->getEntityManager(), $this->hydratorElements); $this->setHydrator($hydrator); $this->setAttribute('action', $this->getCurrentUrl()); $this->setAttribute('class', 'form-intervenant-edition no-intranavigation'); Loading Loading @@ -203,12 +206,43 @@ class EditionForm extends AbstractForm ], ]); $utilisateur = new SearchAndSelect('utilisateur'); $utilisateur->setRequired(false) ->setSelectionRequired(false) ->setAutocompleteSource( $this->getUrl('recherche', ['action' => 'utilisateurFind']) ) ->setLabel("Utilisateur") ->setAttributes(['title' => "Saisissez le nom suivi éventuellement du prénom (2 lettres au moins)"]); $this->add($utilisateur); $this->add([ 'name' => 'login', 'type' => 'Text', 'options' => [ 'label' => 'Login', ], ]); $this->add([ 'name' => 'password', 'type' => 'Password', 'options' => [ 'label' => 'Mot de passe', ], ]); $this->add([ 'name' => 'utilisateurCode', 'name' => 'prenom', 'type' => 'Text', 'options' => [ 'label' => 'Identifiant LDAP éventuel (' . \AppConfig::get('ldap', 'utilisateurCode', 'supannEmpId') . ')', 'label' => 'Prénom <span class="text-danger">*</span>', 'label_options' => ['disable_html_escape' => true], ], ]); $this->add([ Loading Loading @@ -407,10 +441,72 @@ class EditionForm extends AbstractForm 'discipline' => ['required' => false], 'grade' => ['required' => false], 'code' => ['required' => true], 'utilisateurCode' => ['required' => false], 'utilisateur' => ['required' => false], 'login' => ['required' => false], 'password' => ['required' => false], 'source' => ['required' => false], 'sourceCode' => ['required' => false], 'montantIndemniteFc' => ['required' => false], ]; } } class EditionFormHydrator extends GenericHydrator { use UtilisateurServiceAwareTrait; use LdapConnecteurAwareTrait; protected $noGenericParse = ['utilisateur', 'creerUtilisateur']; /** * @param array $data * @param \Application\Entity\Db\Intervenant $object * * @return object */ public function hydrate(array $data, $object) { parent::hydrate($data, $object); $login = isset($data['utilisateur']['id']) ? $data['utilisateur']['id'] : null; if ($login) { $code = $this->getConnecteurLdap()->getCodeFromLogin($login); } else { $code = null; } $object->setUtilisateurCode($code); } /** * @param \Application\Entity\Db\Intervenant $object * * @return array */ public function extract($object) { $res = parent::extract($object); $res['creerUtilisateur'] = !$object->getId() && !\AppConfig::get('cas', 'actif'); if ($code = $object->getUtilisateurCode()) { $utilisateur = $this->getConnecteurLdap()->getUtilisateurFromCode($code, false); if ($utilisateur) { $res['utilisateur'] = [ 'id' => $utilisateur->getUsername(), 'label' => (string)$utilisateur, ]; } } return $res; } } No newline at end of file