From c3b1f0289f88b6aa382ad14d7784c0952523bce9 Mon Sep 17 00:00:00 2001 From: Alexandre Cases Date: Tue, 14 Jun 2016 11:25:45 +0200 Subject: [PATCH] Version: 2.4.3.11 --- README-LABINVENT.md | 13 +++---------- src/Controller/UsersController.php | 42 ++++++++++-------------------------------- src/Model/Table/LdapConnectionsTable.php | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- src/Template/Layout/default.ctp | 2 +- src/Template/Materiels/index.ctp | 2 +- 5 files changed, 63 insertions(+), 45 deletions(-) diff --git a/README-LABINVENT.md b/README-LABINVENT.md index dda0782..233cf48 100755 --- a/README-LABINVENT.md +++ b/README-LABINVENT.md @@ -50,17 +50,10 @@ Logiciel testé et validé sur les configurations suivantes : VERSION ACTUELLE -Date: 13/06/2016 -Version: 2.4.3.10 - -!!! Modification BD !!! - -Ajout de tous les attributs faisant partie des demandes de la version 2.04 dans la base de données -+ Ajout de ces attributs dans les modèles et les fixtures. - - -Demande (terminé) : https://projects.irap.omp.eu/issues/3799 +Date: 14/06/2016 +Version: 2.4.3.11 +Bugfixes et refactoring getMailFromLDAP & getLoginFromLdap Version majeure en cours (2.5): https://projects.irap.omp.eu/versions/99 diff --git a/src/Controller/UsersController.php b/src/Controller/UsersController.php index 276c5c1..4839673 100755 --- a/src/Controller/UsersController.php +++ b/src/Controller/UsersController.php @@ -182,47 +182,25 @@ class UsersController extends AppController // called from Javascript (Ajax) public function getLdapLogin($userName) { - $ldapConnection = TableRegistry::get('LdapConnections'); - $u = $ldapConnection->getAllLdapUsers(); - - for($i = 0; $i < $ldapConnection->getNbUsers(); $i++) { - - //if (!empty($u[$i][$this->request->session()->read('authType')][0])) { - if ($userName == $u[$i]['givenname'][0].' '.$u[$i]['sn'][0]) { - $this->set ( 'login', $u[$i][$this->request->session()->read('authType')][0] ); - } - //} + $u = TableRegistry::get('LdapConnections')->getListLoginUsers(); + + if(isset($u[$userName])) { + $this->set ('login', $u[$userName]); } - + $this->viewBuilder()->layout = 'ajax'; } // called from Javascript (Ajax) public function getLdapEmail($userName) { - $ldapConnection = TableRegistry::get('LdapConnections'); - $u = $ldapConnection->getAllLdapUsers(); - if (isset($u[0]['mailperso'])) { - $typeMail = 'mailperso'; + $u = TableRegistry::get('LdapConnections')->getListEmailUsers(); + + if(isset($u[$userName])) { + $this->set ('email', $u[$userName]); } else { - $typeMail = 'mail'; - } - - for($i = 0; $i < $ldapConnection->getNbUsers(); $i++) { - - //if (!empty($u[$i][$this->request->session()->read('authType')][0])) { - - if ($userName == $u[$i]['givenname'][0].' '.$u[$i]['sn'][0]) { - if (isset($u[$i][$typeMail][0]) && filter_var($u[$i][$typeMail][0], FILTER_VALIDATE_EMAIL)) { - $this->set ('email', $u[$i][$typeMail][0] ); - } else { - $this->set ('email', ' '); - } - } - //} - - + $this->set ('email', ' '); } $this->viewBuilder()->layout = 'ajax'; diff --git a/src/Model/Table/LdapConnectionsTable.php b/src/Model/Table/LdapConnectionsTable.php index a092ef1..fd84227 100755 --- a/src/Model/Table/LdapConnectionsTable.php +++ b/src/Model/Table/LdapConnectionsTable.php @@ -147,7 +147,7 @@ class LdapConnectionsTable extends AppTable { if ($this->USE_LDAP) { $ldapConnection = ldap_connect($this->host, $this->port); ldap_set_option($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, 3); - $results = ldap_search($ldapConnection, $this->baseDn, $this->authenticationType . '=' . $userName); + $results = ldap_search($ldapConnection, $this->baseDn, '('.$this->authenticationType . '=' . $userName.')'); return ldap_get_entries($ldapConnection, $results); } else return array($this->getFakeLdapUser($userName)); @@ -192,6 +192,53 @@ class LdapConnectionsTable extends AppTable { } /** + * Return a list of login ofUsers with key = username & value = login + */ + public function getListLoginUsers() { + $u = $this->getAllLdapUsers(); + $utilisateurs= []; + + if($this->USE_LDAP) { + for($i = 0; $i < $u['count']; $i++) { + $utilisateurs[$u[$i]['givenname'][0].' '.$u[$i]['sn'][0]] = $u[$i][$this->authenticationType][0]; + } + } + else { + for($i = 0; $i < sizeof($u)-1; $i++) { + $utilisateurs[$u[$i]['givenname'][0].' '.$u[$i]['sn'][0]] = $u[$i][$this->authenticationType][0]; + } + } + + return $utilisateurs; + } + + /** + * Return a list of mail of Users with key = username & value = mail + */ + public function getListEmailUsers() { + $u = $this->getAllLdapUsers(); + $utilisateurs= []; + + if($this->USE_LDAP) { + for($i = 0; $i < $u['count']; $i++) { + if(isset($u[$i]['mail'][0])) { + $utilisateurs[$u[$i]['givenname'][0].' '.$u[$i]['sn'][0]] = $u[$i]['mail'][0]; + } + else { + $utilisateurs[$u[$i]['givenname'][0].' '.$u[$i]['sn'][0]] = 'N/A'; + } + } + } + else { + for($i = 0; $i < sizeof($u)-1; $i++) { + $utilisateurs[$u[$i]['givenname'][0].' '.$u[$i]['sn'][0]] = $u[$i]['mail'][0]; + } + } + + return $utilisateurs; + } + + /** * Return size of list users */ public function getNbUsers() { diff --git a/src/Template/Layout/default.ctp b/src/Template/Layout/default.ctp index ee6c927..611a083 100755 --- a/src/Template/Layout/default.ctp +++ b/src/Template/Layout/default.ctp @@ -94,7 +94,7 @@ $cakeDescription = 'Labinvent 2.0'; - VERSION 2.4.3.10 (13/06/2016) + VERSION 2.4.3.11 (14/06/2016) diff --git a/src/Template/Materiels/index.ctp b/src/Template/Materiels/index.ctp index 4fed186..4a68bc4 100755 --- a/src/Template/Materiels/index.ctp +++ b/src/Template/Materiels/index.ctp @@ -189,7 +189,7 @@ if (isset ( $STATUS )) { 'confirm' => 'Êtes-vous sur de vouloir faire une demande d\'archive '.$materiel->designation.' ?']); } - else if (h($materiel->status) == 'TOBEARCHIVED' && $role != 'Responsable'){ + else if (h($materiel->status) == 'TOBEARCHIVED' && !in_array($role, ['Responsable', 'Super Administrateur'])){ echo $this->Html->link('', ['action' => 'statusArchived', $materiel->id], ['title' => 'Sortir de l\'inventaire', 'style' => 'margin: 0 2px', 'escape' => false, -- libgit2 0.21.2