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

Fixes #5311 Reserved department names are now computed from object types directly

parent f4a67113
......@@ -288,25 +288,21 @@ class tests {
*
* \param string $base
*/
public static function is_department_name_reserved($name, $base)
public static function is_department_name_reserved($name)
{
$reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
preg_replace("/ou=(.*),/", "\\1", get_people_ou()),
preg_replace("/ou=(.*),/", "\\1", get_groups_ou()));
$follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles");
/* Check if name is one of the reserved names */
if (in_array_ics($name, $reservedName)) {
return TRUE;
}
/* Check all follow combinations if name is in array && parent base == array_key, return false*/
foreach ($follwedNames as $key => $names) {
if ((in_array_ics($name, $names)) && (preg_match($key, $base))) {
return TRUE;
global $config;
$reservedNames = array();
foreach ($config->data['OBJECTS'] as $type => $infos) {
if (isset($infos['ou'])) {
if ($infos['ou'] != '') {
if (preg_match('/ou=([^,]+),$/', $infos['ou'], $m)) {
$reservedNames[] = $m[1];
}
}
}
}
return FALSE;
return in_array_ics($name, array_unique($reservedNames));
}
......
......@@ -166,8 +166,10 @@ class department extends simplePlugin
$namingAttr = static::$namingAttr;
if (tests::is_department_name_reserved($this->$namingAttr, $this->base)) {
$message[] = msgPool::reserved(_("Name"));
if ($namingAttr == 'ou') {
if (tests::is_department_name_reserved($this->$namingAttr)) {
$message[] = msgPool::reserved(_('Name'));
}
}
return $message;
......
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