Skip to content

Commit 9eea87d

Browse files
authored
ObjectSuggestions: Make CustomVar suggestion sources adjustable (#1100)
The `ObjectSuggestions` instance with `DependencyNode` as the model can only retrieve custom variables for `Host, Service, Hostgroup and Servicegroup`. Other relations are not defined and lead to an error.
2 parents b52c219 + 2e0ed59 commit 9eea87d

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

application/controllers/RedundancygroupController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public function completeAction(): void
230230
$suggestions = (new ObjectSuggestions())
231231
->setModel(DependencyNode::class)
232232
->setBaseFilter(Filter::equal("$column.redundancy_group.id", $this->groupId))
233+
->onlyWithCustomVarSources(['host', 'service', 'hostgroup', 'servicegroup'])
233234
->forRequest($this->getServerRequest());
234235

235236
$this->getDocument()->add($suggestions);

library/Icingadb/Model/Hostgroup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public function getDefaultSort()
7171
public function createBehaviors(Behaviors $behaviors)
7272
{
7373
$behaviors->add(new ReRoute([
74-
'servicegroup' => 'service.servicegroup'
74+
'servicegroup' => 'service.servicegroup',
75+
'parent' => 'host.from.to',
76+
'child' => 'host.to.from'
7577
]));
7678

7779
$behaviors->add(new Binary([

library/Icingadb/Model/Servicegroup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public function createBehaviors(Behaviors $behaviors)
7272
{
7373
$behaviors->add(new ReRoute([
7474
'host' => 'service.host',
75-
'hostgroup' => 'service.hostgroup'
75+
'hostgroup' => 'service.hostgroup',
76+
'parent' => 'service.from.to',
77+
'child' => 'service.to.from'
7678
]));
7779

7880
$behaviors->add(new Binary([

library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,18 @@ protected static function collectRelations(Resolver $resolver, Model $subject, a
419419
}
420420
}
421421
}
422+
423+
/**
424+
* Reduce {@see $customVarSources} to only given relations to fetch variables from
425+
*
426+
* @param string[] $relations
427+
*
428+
* @return $this
429+
*/
430+
public function onlyWithCustomVarSources(array $relations): self
431+
{
432+
$this->customVarSources = array_intersect_key($this->customVarSources, array_flip($relations));
433+
434+
return $this;
435+
}
422436
}

0 commit comments

Comments
 (0)