IcingaCloneObjectForm: do not clone templates...

...in branches. Reason: fields
This commit is contained in:
Thomas Gelf 2021-08-25 11:28:51 +02:00
parent dfdec95358
commit bdd9e2b1e5
2 changed files with 20 additions and 0 deletions

View file

@ -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;

View file

@ -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();