From a2f294fea2340f26c5388625bfb5bb70f0406ac9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 30 Nov 2020 10:17:44 +0100 Subject: [PATCH] IcingaCloneObjectForm: explicit baseUrl fixes #1894 --- .../controllers/ScheduledDowntimeController.php | 2 ++ application/forms/IcingaCloneObjectForm.php | 11 ++++++++++- doc/82-Changelog.md | 1 + .../Director/Web/Controller/ObjectController.php | 14 +++++++++++--- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/application/controllers/ScheduledDowntimeController.php b/application/controllers/ScheduledDowntimeController.php index 65ba2572..481a811d 100644 --- a/application/controllers/ScheduledDowntimeController.php +++ b/application/controllers/ScheduledDowntimeController.php @@ -9,6 +9,8 @@ use Icinga\Module\Director\Web\Table\IcingaScheduledDowntimeRangeTable; class ScheduledDowntimeController extends ObjectController { + protected $objectBaseUrl = 'director/scheduled-downtime'; + public function rangesAction() { /** @var IcingaScheduledDowntime $object */ diff --git a/application/forms/IcingaCloneObjectForm.php b/application/forms/IcingaCloneObjectForm.php index be3a187e..eac7985d 100644 --- a/application/forms/IcingaCloneObjectForm.php +++ b/application/forms/IcingaCloneObjectForm.php @@ -15,6 +15,8 @@ class IcingaCloneObjectForm extends DirectorForm /** @var IcingaObject */ protected $object; + protected $baseObjectUrl; + public function setup() { $name = $this->object->getObjectName(); @@ -93,6 +95,13 @@ class IcingaCloneObjectForm extends DirectorForm ); } + public function setObjectBaseUrl($url) + { + $this->baseObjectUrl = $url; + + return $this; + } + public function onSuccess() { $object = $this->object; @@ -195,7 +204,7 @@ class IcingaCloneObjectForm extends DirectorForm ); } else { $this->setSuccessUrl( - 'director/' . strtolower($type), + $this->baseObjectUrl ?: 'director/' . strtolower($type), $new->getUrlParams() ); } diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 95bc8ca2..5999c63e 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -18,6 +18,7 @@ next (will be 1.8.0) * FIX: Inherited values in sets (arrays) are now shown (#1310) * FIX: Column layout broke with Web 2.8, has been fixed (#2065) * FIX: filter suggestion gave wrong values for DataList fields (#1918) +* FIX: clone-related scheduled downtime links have been fixes (#1894) * FEATURE: Data Fields can now be grouped into categories (#1969) * FEATURE: Inspect is now available for Packages, Stages and Files (#1995) * FEATURE: Allow to disable the Director frontend / UI (#2007) diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 2a4e0303..d851fe92 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -3,7 +3,6 @@ namespace Icinga\Module\Director\Web\Controller; use gipfl\Web\Widget\Hint; -use ipl\Html\Html; use Icinga\Exception\IcingaException; use Icinga\Exception\InvalidPropertyException; use Icinga\Exception\NotFoundError; @@ -46,6 +45,9 @@ abstract class ObjectController extends ActionController protected $type; + /** @var string|null */ + protected $objectBaseUrl; + public function init() { parent::init(); @@ -165,6 +167,7 @@ abstract class ObjectController extends ActionController $object = $this->requireObject(); $form = IcingaCloneObjectForm::load() ->setObject($object) + ->setObjectBaseUrl($this->getObjectBaseUrl()) ->handleRequest(); if ($object->isExternal()) { @@ -315,7 +318,7 @@ abstract class ObjectController extends ActionController { $this->actions()->add(Link::create( $this->translate('Clone'), - 'director/' . $this->getType() .'/clone', + $this->getObjectBaseUrl() . '/clone', $this->object->getUrlParams(), array('class' => 'icon-paste') )); @@ -518,7 +521,7 @@ abstract class ObjectController extends ActionController $this->actions()->add(Link::create( $this->translate('back'), - 'director/' . strtolower($this->getType()), + $this->getObjectBaseUrl(), $params, ['class' => 'icon-left-big'] )); @@ -555,6 +558,11 @@ abstract class ObjectController extends ActionController return $form; } + protected function getObjectBaseUrl() + { + return $this->objectBaseUrl ?: 'director/' . strtolower($this->getType()); + } + protected function hasBasketSupport() { return $this->object->isTemplate() || $this->object->isGroup();