diff --git a/inc/field/ldapselectfield.class.php b/inc/field/ldapselectfield.class.php index adc3c1caa..e6e983a84 100644 --- a/inc/field/ldapselectfield.class.php +++ b/inc/field/ldapselectfield.class.php @@ -39,7 +39,6 @@ use RuleRightParameter; use Glpi\Application\View\TemplateRenderer; use PluginFormcreatorAbstractField; -use Toolbox; class LdapselectField extends SelectField { @@ -187,53 +186,17 @@ public function prepareQuestionInputForSave($input) { } $ldap_values['ldap_attribute'] = $input['ldap_attribute'] ?? ($ldap_values['ldap_attribute'] ?? null); - $attribute = []; if (isset($ldap_values['ldap_attribute'])) { $ldap_dropdown = RuleRightParameter::getById((int) $ldap_values['ldap_attribute']); if (!($ldap_dropdown instanceof RuleRightParameter)) { return []; } - $attribute = [$ldap_dropdown->fields['value']]; } if (isset($input['ldap_filter'])) { $input['ldap_filter'] = html_entity_decode($input['ldap_filter']); } $ldap_values['ldap_filter'] = $input['ldap_filter'] ?? ($ldap_values['ldap_filter'] ?? ''); - set_error_handler([self::class, 'ldapErrorHandler'], E_WARNING); - - try { - $cookie = ''; - $ds = $config_ldap->connect(); - if ($ds === false) { - Session::addMessageAfterRedirect(__('Connection to the directory failed.', 'formcreator'), false, ERROR); - } - ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); - if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) { - $controls = [ - [ - 'oid' => LDAP_CONTROL_PAGEDRESULTS, - 'iscritical' => true, - 'value' => [ - 'size' => $config_ldap->fields['pagesize'], - 'cookie' => $cookie - ] - ] - ]; - $result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute, 0, -1, -1, LDAP_DEREF_NEVER, $controls); - ldap_parse_result($ds, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls); - $cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? ''; - } else { - $result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute); - } - ldap_get_entries($ds, $result); - } catch (Exception $e) { - restore_error_handler(); - trigger_error($e->getMessage(), E_USER_WARNING); - Session::addMessageAfterRedirect(__('Cannot recover LDAP informations!', 'formcreator'), false, ERROR); - } - - restore_error_handler(); $input['values'] = json_encode($ldap_values, JSON_UNESCAPED_UNICODE); unset($input['ldap_auth']); diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php index d0692588a..57ab493cd 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php @@ -157,14 +157,14 @@ public function providerPrepareQuestionInputForSave() { ]), 'input' => [ 'ldap_auth' => $authLdap->getID(), - 'ldap_filter' => 'по', // Some cyrillic sample + 'ldap_filter' => 'по', 'ldap_attribute' => '1', ], 'expected' => [ 'values' => json_encode([ 'ldap_auth' => $authLdap->getID(), + 'ldap_attribute' => '1', 'ldap_filter' => 'по', - 'ldap_attribute' => '', ], JSON_UNESCAPED_UNICODE), ] ], @@ -180,14 +180,6 @@ public function providerPrepareQuestionInputForSave() { * @return void */ public function testPrepareQuestionInputForSave(\PluginFormcreatorQuestion $question, array $input, array $expected) { - // Make the form private - $question = $this->getQuestion([ - 'ldap_auth' => $input['ldap_auth'], - 'fieldtype' => 'ldapselect', - 'ldap_filter' => '', - 'ldap_attribute' => '', - ]); - $instance = $this->newTestedInstance($question); $output = $instance->prepareQuestionInputForSave($input);