From fcbc2db71bf5552f60b1158f12ab8de67248f69b Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 28 Mar 2018 17:47:48 +0200 Subject: [PATCH] IcingaObject: resolve groups for flattened objects refs #1449 --- application/forms/IcingaHostForm.php | 11 +---------- library/Director/Objects/IcingaObject.php | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index 72aace22..9426221b 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -253,16 +253,7 @@ class IcingaHostForm extends DirectorObjectForm protected function getInheritedGroups() { if ($this->hasObject()) { - $parents = $this->object->imports()->getObjects(); - /** @var IcingaHost $parent */ - foreach (array_reverse($parents) as $parent) { - $inherited = $parent->getGroups(); - if (! empty($inherited)) { - return $inherited; - } - } - - return []; + return $this->object->getInheritedGroups(); } else { return []; } diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 9a2a27c3..c3bfbd73 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -773,7 +773,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } /** - * @return IcingaObjectGroups[] + * @return IcingaObjectGroups */ public function groups() { @@ -1010,6 +1010,20 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this->groups()->listGroupNames(); } + public function getInheritedGroups() + { + $parents = $this->imports()->getObjects(); + /** @var IcingaObject $parent */ + foreach (array_reverse($parents) as $parent) { + $inherited = $parent->getGroups(); + if (! empty($inherited)) { + return $inherited; + } + } + + return []; + } + public function setGroups($groups) { $this->groups()->set($groups); @@ -2558,7 +2572,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer if ($this->supportsGroups()) { // TODO: resolve - $props['groups'] = $this->groups()->listGroupNames(); + $groups = $this->groups()->listGroupNames(); + if ($resolved && empty($groups)) { + $groups = $this->getInheritedGroups(); + } + + $props['groups'] = $groups; } foreach ($this->loadAllMultiRelations() as $key => $rel) {