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

Showing with 30 additions and 20 deletions
+30 -20
...@@ -38,6 +38,7 @@ class Attribute ...@@ -38,6 +38,7 @@ class Attribute
private $required; private $required;
/* \brief Should this attribute be saved into the LDAP */ /* \brief Should this attribute be saved into the LDAP */
private $inLdap = TRUE; private $inLdap = TRUE;
/* \brief Should this attribute be unique /* \brief Should this attribute be unique
* FALSE -> no unicity check * FALSE -> no unicity check
* one -> unicity check in the same base -> broken right now because of object ous * one -> unicity check in the same base -> broken right now because of object ous
...@@ -47,6 +48,10 @@ class Attribute ...@@ -47,6 +48,10 @@ class Attribute
*/ */
private $unique = FALSE; 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 */ /* \brief Prefix for the html id */
protected $htmlid_prefix = ''; protected $htmlid_prefix = '';
/* \brief Should this attribute be shown */ /* \brief Should this attribute be shown */
...@@ -124,13 +129,14 @@ class Attribute ...@@ -124,13 +129,14 @@ class Attribute
return $this->visible; return $this->visible;
} }
function setUnique ($unique) function setUnique ($unique, $filter = NULL)
{ {
if ($unique === TRUE) { if ($unique === TRUE) {
$this->unique = 'one'; $this->unique = 'one';
} else { } else {
$this->unique = $unique; $this->unique = $unique;
} }
$this->uniqueFilter = $filter;
} }
function getUnique () function getUnique ()
...@@ -458,25 +464,29 @@ class Attribute ...@@ -458,25 +464,29 @@ class Attribute
$filter = '('.$this->getLdapName().'='.ldap_escape_f($value).')'; $filter = '('.$this->getLdapName().'='.ldap_escape_f($value).')';
} }
$infos = pluglist::pluginInfos(get_class($this->plugin)); $infos = pluglist::pluginInfos(get_class($this->plugin));
$filters = array_map( if ($this->uniqueFilter === NULL) {
function ($key, $ot) $filters = array_map(
{ function ($key, $ot)
if (!is_numeric($key)) { {
$ot = $key; if (!is_numeric($key)) {
} $ot = $key;
try { }
$oinfos = objects::infos($ot); try {
return $oinfos['filter']; $oinfos = objects::infos($ot);
} catch (NonExistingObjectTypeException $e) { return $oinfos['filter'];
return ''; } catch (NonExistingObjectTypeException $e) {
} return '';
}, }
array_keys($infos['plObjectType']), },
array_values($infos['plObjectType']) array_keys($infos['plObjectType']),
); array_values($infos['plObjectType'])
$pluginFilter = $this->plugin->getObjectClassFilter(); );
if (!empty($pluginFilter)) { $pluginFilter = $this->plugin->getObjectClassFilter();
$filters[] = $pluginFilter; if (!empty($pluginFilter)) {
$filters[] = $pluginFilter;
}
} else {
$filters = array($this->uniqueFilter);
} }
$filter = '(&'.$filter.implode($filters).')'; $filter = '(&'.$filter.implode($filters).')';
$ldap->search($filter, array($this->getLdapName())); $ldap->search($filter, array($this->getLdapName()));
......
  • bmortier @bmortier

    mentioned in issue #1769 (closed)

    By Côme Chilliet on 2017-09-02T15:37:45 (imported from GitLab)

    ·

    mentioned in issue #1769 (closed)

    By Côme Chilliet on 2017-09-02T15:37:45 (imported from GitLab)

    Toggle commit list
Supports Markdown
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