Commit e32d514c authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2898 Adding handling of nameAttr

parent 6f2ce708
......@@ -1211,6 +1211,9 @@ class config {
if (!isset($value['mainAttr'])) {
$value['mainAttr'] = 'cn';
}
if (!isset($value['nameAttr'])) {
$value['nameAttr'] = $value['mainAttr'];
}
if (!isset($value['tabClass'])) {
$value['tabClass'] = 'simpleTabs';
}
......
......@@ -184,7 +184,7 @@ class filterLDAP {
$result[] = $attrs;
} else {
// Check entry permission
$obj = $parent->headpage->getObjectTypeInfos($attrs);
$obj = $parent->headpage->getObjectTypeInfos($dn, $attrs);
if (isset($obj['category'])) {
$o = $obj['category']."/".$obj['class'];
if (preg_match("/r/", $ui->get_permissions($dn, $o))) {
......
......@@ -55,7 +55,7 @@ class ldapFilter
function __invoke($array)
{
$stopValue = FALSE;
switch($this->operator) {
switch ($this->operator) {
case '!':
return !$this->subparts[0]($array);
case '|':
......@@ -83,7 +83,7 @@ class ldapFilter
$offset = 0;
$level = 0;
$open;
while(preg_match('/[^\\\\](\\(|\\))/', $filter, $m, PREG_OFFSET_CAPTURE, $offset)) {
while (preg_match('/[^\\\\](\\(|\\))/', $filter, $m, PREG_OFFSET_CAPTURE, $offset)) {
$offset = $m[0][1] + 1;
if ($m[1][0] == '(') {
if ($level == 0) {
......@@ -93,13 +93,13 @@ class ldapFilter
} elseif ($m[1][0] == ')') {
$level--;
if ($level == 0) {
$subfilters[] = ldapFilter::parse(substr($filter, $open+1, $m[0][1] - $open));
$subfilters[] = ldapFilter::parse(substr($filter, $open + 1, $m[0][1] - $open));
}
}
}
return new ldapFilter($filter[0], $subfilters);
} else {
preg_match('/^(.+)('.join('|',ldapFilterLeaf::$operators).')(.+)$/', $filter, $m);
preg_match('/^(.+)('.join('|', ldapFilterLeaf::$operators).')(.+)$/', $filter, $m);
return new ldapFilterLeaf($m[1], $m[2], $m[3]);
}
}
......
......@@ -63,6 +63,8 @@ class listing {
var $scrollPosition = 0;
var $baseSelector;
var $typeCache = array();
/*!
* \brief Create a listing
*
......@@ -99,10 +101,11 @@ class listing {
$this->showFooter = ($config->get_cfg_value("listSummary") == "TRUE");
// Register build in filters
$this->registerElementFilter("objectType", "listing::filterObjectType");
$this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
$this->registerElementFilter("link", "listing::filterLink");
$this->registerElementFilter("actions", "listing::filterActions");
$this->registerElementFilter("objectType", "listing::filterObjectType");
$this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
$this->registerElementFilter("link", "listing::filterLink");
$this->registerElementFilter("nameLink", "listing::filterNameLink");
$this->registerElementFilter("actions", "listing::filterActions");
// Load exporters
foreach (array_keys($class_mapping) as $class) {
......@@ -218,18 +221,17 @@ class listing {
$types = departmentManagement::getDepartmentTypes();
foreach ($types as $type) {
$i = objects::infos($type);
$objectClass = '';
if (preg_match('/objectClass=([^)]+)/', $i['filter'], $m)) {
$objectClass = $m[1];
}
$this->objectTypes[strtoupper($type)] = array(
'label' => $i['name'],
'image' => $i['icon'],
'objectClass' => $objectClass,
'category' => $i['aclCategory'],
'class' => $i['mainTab'],
'filter' => ldapFilter::parse($i['filter'])
'filter' => ldapFilter::parse($i['filter']),
'nameAttr' => $i['nameAttr'],
);
if (!isset($i['nameAttr'])) {
print_r($i);
}
}
$this->categories = array();
if (isset($this->xmlData['definition']['objectType'])) {
......@@ -859,14 +861,18 @@ class listing {
*
* \param string $classes
*/
function getObjectType($attrs)
function getObjectType($dn, $attrs)
{
if (isset($this->typeCache[$dn])) {
return $this->typeCache[$dn];
}
$classes = $attrs['objectClass'];
// Walk thru types and see if there's something matching
foreach ($this->objectTypes as $type => $objectType) {
if (isset($objectType['filter'])) {
if ($objectType['filter']($attrs)) {
return $type;
$this->typeCache[$dn] = $type;
return $this->typeCache[$dn];
} else {
continue;
}
......@@ -898,9 +904,9 @@ class listing {
return NULL;
}
function getObjectTypeInfos($attrs)
function getObjectTypeInfos($dn, $attrs)
{
$type = $this->getObjectType($attrs);
$type = $this->getObjectType($dn, $attrs);
if ($type === NULL) {
return NULL;
}
......@@ -940,9 +946,9 @@ class listing {
$result = " ";
if (($attrs = $this->getEntry($dn)) != NULL) {
$type = $this->getObjectType($attrs);
$type = $this->getObjectType($dn, $attrs);
} else {
$type = $this->getObjectType(array('objectClass' => $classes));
$type = $this->getObjectType($dn, array('objectClass' => $classes));
}
if ($type) {
$this->objectDnMapping[$dn] = $type;
......@@ -1033,7 +1039,7 @@ class listing {
// Handle special types
if ($action['type'] == "copypaste" || $action['type'] == "snapshot") {
$objectType = $this->getObjectTypeInfos($this->entries[$row]);
$objectType = $this->getObjectTypeInfos($dn, $this->entries[$row]);
$category = $class = NULL;
if ($objectType) {
$category = $objectType['category'];
......@@ -1073,6 +1079,16 @@ class listing {
return "<a href='?plug=".$_GET['plug']."&amp;PID=$this->pid&amp;act=department_$row' title='$dn'>$result</a>";
}
/*!
* \brief Filter link with object name
*/
function filterNameLink($row, $dn)
{
$infos = $this->getObjectTypeInfos($dn, $this->entries[$row]);
$attr = $infos['nameAttr'];
return $this->filterLink($row, $dn, "%s", $this->entries[$row][$attr]);
}
/*!
* \brief Filter link
*/
......@@ -1379,9 +1395,9 @@ class listing {
if (isset($action['acl'])) {
if (($attrs = $this->getEntry($dn)) != NULL) {
$otype = $this->getObjectTypeInfos($attrs);
$otype = $this->getObjectTypeInfos($dn, $attrs);
} elseif ($classes) {
$otype = $this->getObjectTypeInfos(array('objectClass' => $classes));
$otype = $this->getObjectTypeInfos($dn, array('objectClass' => $classes));
} else {
$otype = FALSE;
}
......
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