Skip to content

Commit

Permalink
RedundancygroupController: Remove query execute() call
Browse files Browse the repository at this point in the history
RedundancygroupController: Add class property for group summary

RedundancygroupController: Apply missing restrictions in `fetchNodes()` method

rg: Use $this->httpNotFound instead

rg: remove superfluous searchbar param
  • Loading branch information
sukhwinder33445 committed Nov 19, 2024
1 parent f94daec commit fd88926
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions application/controllers/RedundancygroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class RedundancygroupController extends Controller
/** @var RedundancyGroup */
protected $group;

/** @var RedundancyGroupSummary */
protected $groupSummary;

public function init(): void
{
// in case of quick actions, param id is not given
Expand All @@ -61,7 +64,7 @@ protected function loadGroup(): void
$this->group = $query->first();

if ($this->group === null) {
throw new NotFoundError($this->translate('Redundancy Group not found'));
$this->httpNotFound($this->translate('Redundancy Group not found'));
}

$this->setTitleTab($this->getRequest()->getActionName());
Expand All @@ -72,20 +75,18 @@ protected function loadGroup(): void

$this->applyRestrictions($summary);

$this->addControl(new RedundancyGroupHeader($this->group, $summary->first()));
$this->groupSummary = $summary->first();

$this->addControl(new RedundancyGroupHeader($this->group, $this->groupSummary));
}

public function indexAction(): void
{
$this->loadGroup();
$summary = RedundancyGroupSummary::on($this->getDb())
->filter(Filter::equal('id', $this->groupId));

$this->filter($summary);

// The base filter is required to fetch the correct objects for MultiselectQuickActions::isGrantedOnType() check
$this->addControl(
(new MultiselectQuickActions('dependency_node', $summary->first()))
(new MultiselectQuickActions('dependency_node', $this->groupSummary))
->setBaseFilter(Filter::equal('child.redundancy_group.id', $this->groupId))
->setAllowToProcessCheckResults(false)
->setColumnPrefix('nodes')
Expand Down Expand Up @@ -115,7 +116,6 @@ public function membersAction(): void

$searchBar = $this->createSearchBar(
$nodesQuery,
Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]),
[
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
Expand Down Expand Up @@ -145,7 +145,7 @@ public function membersAction(): void
$this->addControl($searchBar);

$this->addContent(
(new DependencyNodeList($nodesQuery->execute()))
(new DependencyNodeList($nodesQuery))
->setViewMode($viewModeSwitcher->getViewMode())
);

Expand Down Expand Up @@ -176,7 +176,6 @@ public function childrenAction(): void

$searchBar = $this->createSearchBar(
$nodesQuery,
Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId]),
[
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
Expand Down Expand Up @@ -209,7 +208,7 @@ public function childrenAction(): void
$this->addControl($searchBar);

$this->addContent(
(new DependencyNodeList($nodesQuery->execute()))
(new DependencyNodeList($nodesQuery))
->setViewMode($viewModeSwitcher->getViewMode())
);

Expand Down Expand Up @@ -301,7 +300,7 @@ private function fetchNodes(bool $fetchParents = false): Query
$fetchParents ? 'child' : 'parent'
);

return DependencyNode::on($this->getDb())
$query = DependencyNode::on($this->getDb())
->with([
'host',
'host.state',
Expand All @@ -311,6 +310,10 @@ private function fetchNodes(bool $fetchParents = false): Query
'service.host.state'
])
->filter(Filter::equal($filterColumn, $this->groupId));

$this->applyRestrictions($query);

return $query;
}

protected function fetchCommandTargets()
Expand Down

0 comments on commit fd88926

Please sign in to comment.