IcingaObject: resolve groups for flattened objects

refs #1449
This commit is contained in:
Thomas Gelf 2018-03-28 17:47:48 +02:00
parent d35c6858a1
commit fcbc2db71b
2 changed files with 22 additions and 12 deletions

View File

@ -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 [];
}

View File

@ -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) {