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

Fixes #5395 Improved templates search to avoid mixing ogroup and posixGroup templates

parent 6c2e02af
......@@ -125,7 +125,7 @@ class objects
return $ldap->count();
}
private static function search ($types, $search_attrs, $ou = NULL, $filter = '', $scope = 'subtree')
private static function search ($types, $search_attrs, $ou = NULL, $filter = '', $scope = 'subtree', $templateSearch = FALSE)
{
global $config;
......@@ -162,6 +162,16 @@ class objects
}
$filter = '(&'.$filter.'(|'.implode($typeFilters).'))';
}
if ($templateSearch) {
$templateFilterObject = new ldapFilter(
'&',
array(
new ldapFilterLeaf('objectClass', '=', 'fdTemplate'),
fdTemplateFilter(ldapFilter::parse($filter)),
)
);
$filter = "$templateFilterObject";
}
$ldap->cd($ou);
$ldap->search($filter, $search_attrs, $scope);
if (!$ldap->success()) {
......@@ -276,7 +286,7 @@ class objects
/* !\brief This method returns a list of all available templates for the given type
*/
static function getTemplates ($type, $requiredPermissions = 'r')
static function getTemplates ($type, $requiredPermissions = 'r', $filter = '')
{
global $config, $ui;
......@@ -286,9 +296,11 @@ class objects
$ldap = $config->get_ldap_link();
foreach ($config->departments as $key => $value) {
// Search all templates from the current dn.
$ldap->cd($infos['ou'].$value);
// We could also adapt object filter to match templates
$ldap->search('(objectClass=fdTemplate)', array('cn'));
try {
$ldap = static::search($type, array('cn'), $infos['ou'].$value, $filter, 'subtree', TRUE);
} catch (NonExistingBranchException $e) {
continue;
}
if ($ldap->count() != 0) {
while ($attrs = $ldap->fetch()) {
$dn = $attrs['dn'];
......
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