Skip to content

Commit

Permalink
Allow cloning service sets in Director Branches
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 22, 2024
1 parent 853b6ce commit 4d2bb89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 16 additions & 3 deletions application/forms/IcingaCloneObjectForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public function setup()
{
$isBranch = $this->branch && $this->branch->isBranch();
$branchOnly = $this->object->get('id') === null;
if ($isBranch && $this->object instanceof IcingaObject && $this->object->isTemplate()) {
if (
$isBranch
&& $this->object instanceof IcingaObject
&& ($this->object->isTemplate() && ! $this->object instanceof IcingaServiceSet)
) {
$this->addHtml(Hint::error($this->translate(
'Templates cannot be cloned in Configuration Branches'
)));
Expand Down Expand Up @@ -146,7 +150,11 @@ public function onSuccess()
$object->getObjectName()
);

if ($object->isTemplate() && $this->branch && $this->branch->isBranch()) {
if (
$this->branch
&& $this->branch->isBranch()
&& ($object->isTemplate() && ! ($object instanceof IcingaServiceSet))
) {
throw new IcingaException('Cloning templates is not available for Branches');
}

Expand Down Expand Up @@ -211,8 +219,13 @@ public function onSuccess()
if ($new instanceof IcingaHost) {
$clone->set('host_id', $newId);
} elseif ($new instanceof IcingaServiceSet) {
$clone->set('service_set_id', $newId);
if ($this->branch && $this->branch->isBranch()) {
$clone->set('service_set', $newName);
} else {
$clone->set('service_set_id', $newId);
}
}

$store->store($clone);
}

Expand Down
12 changes: 7 additions & 5 deletions library/Director/Web/Controller/ObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ public function cloneAction()
$this->addTitle($this->translate('Clone: %s'), $object->getObjectName())
->addBackToObjectLink();

if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Templates'))) {
return;
}
if (! ($object instanceof IcingaServiceSet)) {
if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Templates'))) {
return;
}

if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Apply Rules'))) {
return;
if ($object->isTemplate() && $this->showNotInBranch($this->translate('Cloning Apply Rules'))) {
return;
}
}

$form = IcingaCloneObjectForm::load()
Expand Down

0 comments on commit 4d2bb89

Please sign in to comment.