Unverified Commit f76a4aaa authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(objects) Fix problems with template search

issue #5993
Showing with 40 additions and 15 deletions
+40 -15
......@@ -65,18 +65,22 @@ class objects
$attrsAcls = [];
if ($attrs === NULL) {
$attrs = [];
foreach ($types as $type) {
$infos = static::infos($type);
if ($infos['mainAttr']) {
$attrs[] = $infos['mainAttr'];
if ($templateSearch) {
$attrs = 'cn';
} else {
$attrs = [];
foreach ($types as $type) {
$infos = static::infos($type);
if ($infos['mainAttr']) {
$attrs[] = $infos['mainAttr'];
}
}
$attrs = array_unique($attrs);
if (count($attrs) == 1) {
$attrs = $attrs[0];
} elseif (count($attrs) == 0) {
$attrs = ['dn' => 'raw'];
}
}
$attrs = array_unique($attrs);
if (count($attrs) == 1) {
$attrs = $attrs[0];
} elseif (count($attrs) == 0) {
$attrs = ['dn' => 'raw'];
}
} elseif ($checkAcl) {
if (is_array($attrs)) {
......@@ -100,13 +104,13 @@ class objects
if (is_array($attrs)) {
$search_attrs = array_keys($attrs);
if ($templateSearch) {
$search_attrs[] = 'fdTemplateField';
$search_attrs[] = 'cn';
}
} else {
$search_attrs = [$attrs];
}
if ($templateSearch) {
$search_attrs[] = 'fdTemplateField';
$search_attrs[] = 'cn';
}
try {
$ldap = static::search($types, $search_attrs, $ou, $filter, $checkAcl, $scope, $templateSearch, $partialFilterAcls, $sizeLimit);
......@@ -171,6 +175,27 @@ class objects
if (count($result[$key]) === 0) {
unset($result[$key]);
}
} elseif ($templateSearch) {
if ($attrs == 'cn') {
if (
isset($fetched_attrs['cn']) &&
(!$checkAcl || (strpos($ui->get_permissions($key, $tplAcl, 'template_cn'), 'r') !== FALSE))
) {
$result[$key] = $fetched_attrs['cn'][0];
}
} else {
if (isset($attrsAcls[$attrs]) &&
(strpos($ui->get_permissions($key, $attrsAcls[$attrs][0], $attrsAcls[$attrs][1]), 'r') === FALSE)) {
continue;
}
foreach ($fetched_attrs['fdTemplateField'] as $templateField) {
list($attr, $value) = explode(':', $templateField, 2);
if ($attrs == $attr) {
$result[$key] = $value;
break;
}
}
}
} elseif (isset($fetched_attrs[$attrs])) {
if (isset($attrsAcls[$attrs]) &&
(strpos($ui->get_permissions($key, $attrsAcls[$attrs][0], $attrsAcls[$attrs][1]), 'r') === FALSE)) {
......
  • SonarQube analysis reported 1 issue

    • :warning: 1 major

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. :warning: This function "ls" has 158 lines, which is greater than the 150 lines authorized. Split it into smaller functions. :blue_book:

    By Ghost User on 2019-05-28T15:12:40 (imported from GitLab)

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