From d0a3d36f66da9565eefe923618057c011eaa801b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Tue, 24 Jan 2017 14:21:03 +0100 Subject: [PATCH] Fixes #5311 Reserved department names are now computed from object types directly --- include/class_tests.inc | 28 ++++++++----------- .../admin/departments/class_department.inc | 6 ++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/class_tests.inc b/include/class_tests.inc index a968bd4b0..d4cf1f7c1 100644 --- a/include/class_tests.inc +++ b/include/class_tests.inc @@ -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)); } diff --git a/plugins/admin/departments/class_department.inc b/plugins/admin/departments/class_department.inc index ba60d4281..510c431a9 100644 --- a/plugins/admin/departments/class_department.inc +++ b/plugins/admin/departments/class_department.inc @@ -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; -- GitLab