diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 1d795755..8c676986 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -207,12 +207,7 @@ class HostController extends ObjectController $host = $this->getHostObject(); $this->addTitle($this->translate('Services: %s'), $host->getObjectName()); $branch = $this->getBranch(); - if ($branch->isBranch() && $host->get('id') === null) { - $this->content()->add(Hint::info( - $this->translate('Managing services on new Hosts is possible only after they have been merged.') - )); - return; - } + $hostHasBeenCreatedInBranch = $branch->isBranch() && $host->get('id'); $content = $this->content(); $table = (new ObjectsTableService($this->db()))->setAuth($this->Auth())->setHost($host) ->setTitle($this->translate('Individual Service objects')); @@ -242,7 +237,9 @@ class HostController extends ObjectController } } - $this->addHostServiceSetTables($host); + if (! $hostHasBeenCreatedInBranch) { + $this->addHostServiceSetTables($host); + } foreach ($parents as $parent) { $this->addHostServiceSetTables($parent, $host); } @@ -356,6 +353,9 @@ class HostController extends ObjectController if ($affectedHost === null) { $affectedHost = $host; } + if ($host->get('id') === null) { + return; + } $query = $db->getDbAdapter()->select() ->from( diff --git a/library/Director/Web/Table/IcingaHostAppliedServicesTable.php b/library/Director/Web/Table/IcingaHostAppliedServicesTable.php index 297b672e..10f07f45 100644 --- a/library/Director/Web/Table/IcingaHostAppliedServicesTable.php +++ b/library/Director/Web/Table/IcingaHostAppliedServicesTable.php @@ -179,6 +179,7 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable protected function fetchAllApplyRules() { $db = $this->db; + $hostId = $this->host->get('id'); $query = $db->select()->from( ['s' => 'icinga_service'], [ @@ -187,14 +188,17 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable 'assign_filter' => 's.assign_filter', 'apply_for' => 's.apply_for', 'disabled' => 's.disabled', - 'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END", + 'blacklisted' => $hostId ? "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END" : "('n')", ] - )->joinLeft( - ['hsb' => 'icinga_host_service_blacklist'], - $db->quoteInto('s.id = hsb.service_id AND hsb.host_id = ?', $this->host->get('id')), - [] )->where('object_type = ? AND assign_filter IS NOT NULL', 'apply') ->order('s.object_name'); + if ($hostId) { + $query->joinLeft( + ['hsb' => 'icinga_host_service_blacklist'], + $db->quoteInto('s.id = hsb.service_id AND hsb.host_id = ?', $hostId), + [] + ); + } return $db->fetchAll($query); }