Commit 233c3b99 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Fixes #5545 Added a uniqueFilter which will be used for mac addresses

parent 809d7fe2
......@@ -38,6 +38,7 @@ class Attribute
private $required;
/* \brief Should this attribute be saved into the LDAP */
private $inLdap = TRUE;
/* \brief Should this attribute be unique
* FALSE -> no unicity check
* one -> unicity check in the same base -> broken right now because of object ous
......@@ -47,6 +48,10 @@ class Attribute
*/
private $unique = FALSE;
/* \brief Filter to use when checking unicity
* Most of the time this is NULL and filter is computed from plugin objectTypes and objectClasses */
private $uniqueFilter = NULL;
/* \brief Prefix for the html id */
protected $htmlid_prefix = '';
/* \brief Should this attribute be shown */
......@@ -124,13 +129,14 @@ class Attribute
return $this->visible;
}
function setUnique ($unique)
function setUnique ($unique, $filter = NULL)
{
if ($unique === TRUE) {
$this->unique = 'one';
} else {
$this->unique = $unique;
}
$this->uniqueFilter = $filter;
}
function getUnique ()
......@@ -458,25 +464,29 @@ class Attribute
$filter = '('.$this->getLdapName().'='.ldap_escape_f($value).')';
}
$infos = pluglist::pluginInfos(get_class($this->plugin));
$filters = array_map(
function ($key, $ot)
{
if (!is_numeric($key)) {
$ot = $key;
}
try {
$oinfos = objects::infos($ot);
return $oinfos['filter'];
} catch (NonExistingObjectTypeException $e) {
return '';
}
},
array_keys($infos['plObjectType']),
array_values($infos['plObjectType'])
);
$pluginFilter = $this->plugin->getObjectClassFilter();
if (!empty($pluginFilter)) {
$filters[] = $pluginFilter;
if ($this->uniqueFilter === NULL) {
$filters = array_map(
function ($key, $ot)
{
if (!is_numeric($key)) {
$ot = $key;
}
try {
$oinfos = objects::infos($ot);
return $oinfos['filter'];
} catch (NonExistingObjectTypeException $e) {
return '';
}
},
array_keys($infos['plObjectType']),
array_values($infos['plObjectType'])
);
$pluginFilter = $this->plugin->getObjectClassFilter();
if (!empty($pluginFilter)) {
$filters[] = $pluginFilter;
}
} else {
$filters = array($this->uniqueFilter);
}
$filter = '(&'.$filter.implode($filters).')';
$ldap->search($filter, array($this->getLdapName()));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment