diff --git a/application/forms/IcingaCloneObjectForm.php b/application/forms/IcingaCloneObjectForm.php index eac7985d..0315cf84 100644 --- a/application/forms/IcingaCloneObjectForm.php +++ b/application/forms/IcingaCloneObjectForm.php @@ -2,8 +2,10 @@ namespace Icinga\Module\Director\Forms; +use gipfl\Web\Widget\Hint; use Icinga\Exception\IcingaException; use Icinga\Module\Director\Acl; +use Icinga\Module\Director\Db\Branch\Branch; use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaService; @@ -17,8 +19,18 @@ class IcingaCloneObjectForm extends DirectorForm protected $baseObjectUrl; + /** @var Branch */ + protected $branch; + public function setup() { + if ($this->branch->isBranch() && $this->object instanceof IcingaObject && $this->object->isTemplate()) { + $this->addHtml(Hint::error($this->translate( + 'Templates cannot be cloned in Configuration Branches' + ))); + $this->submitLabel = false; + return; + } $name = $this->object->getObjectName(); $this->addElement('text', 'new_object_name', array( 'label' => $this->translate('New name'), @@ -95,6 +107,13 @@ class IcingaCloneObjectForm extends DirectorForm ); } + public function setBranch(Branch $branch) + { + $this->branch = $branch; + + return $this; + } + public function setObjectBaseUrl($url) { $this->baseObjectUrl = $url; diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index a25e1afd..f133feda 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -174,6 +174,7 @@ abstract class ObjectController extends ActionController $this->assertTypePermission(); $object = $this->requireObject(); $form = IcingaCloneObjectForm::load() + ->setBranch($this->getBranch()) ->setObject($object) ->setObjectBaseUrl($this->getObjectBaseUrl()) ->handleRequest();