From 13dfe35d6655c22cae033b464817b12a709fee03 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Thu, 24 Jul 2025 19:45:54 +0200 Subject: [PATCH] Disable deployment link if there is an active deployment --- application/forms/DeploymentLinkForm.php | 18 +++++++++++++++--- .../Web/Controller/ObjectController.php | 7 ++++++- public/css/module.less | 10 ++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/application/forms/DeploymentLinkForm.php b/application/forms/DeploymentLinkForm.php index b5d9b033..27832752 100644 --- a/application/forms/DeploymentLinkForm.php +++ b/application/forms/DeploymentLinkForm.php @@ -6,6 +6,7 @@ use Icinga\Authentication\Auth; use Icinga\Exception\IcingaException; use Icinga\Module\Director\Auth\Permission; use Icinga\Module\Director\Core\DeploymentApiInterface; +use Icinga\Module\Director\Dashboard\Dashlet\DeploymentDashlet; use Icinga\Module\Director\Db; use Icinga\Module\Director\Deployment\DeploymentInfo; use Icinga\Module\Director\IcingaConfig\IcingaConfig; @@ -83,8 +84,9 @@ class DeploymentLinkForm extends DirectorForm ); } - $this->setAttrib('class', 'gipfl-inline-form'); + $this->setAttrib('class', ['gipfl-inline-form', 'deployment-link-form']); $this->addHtml(Icon::create('wrench')); + try { // As this is shown for single objects, ignore errors caused by an // unreachable core @@ -92,11 +94,21 @@ class DeploymentLinkForm extends DirectorForm } catch (\Exception $e) { $target = '_next'; } - $this->addSubmitButton($this->translate('Deploy'), [ + + $lastDeploymentPending = (new DeploymentDashlet($this->db))->lastDeploymentPending(); + $deployButtonAttributes = [ 'class' => 'link-button icon-wrench', 'title' => $msg, 'data-base-target' => $target, - ]); + ]; + if ($lastDeploymentPending) { + $deployButtonAttributes['disabled'] = 'disabled'; + $deployButtonAttributes['title'] = $this->translate( + 'There is an active deployment, please wait until it is finished' + ); + } + + $this->addSubmitButton($this->translate('Deploy'), $deployButtonAttributes); } protected function canDeploy() diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 88e38a45..f8dcb63b 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -7,6 +7,7 @@ use Icinga\Exception\IcingaException; use Icinga\Exception\InvalidPropertyException; use Icinga\Exception\NotFoundError; use Icinga\Exception\ProgrammingError; +use Icinga\Module\Director\Dashboard\Dashlet\DeploymentDashlet; use Icinga\Module\Director\Data\Db\DbObjectTypeRegistry; use Icinga\Module\Director\Db\Branch\Branch; use Icinga\Module\Director\Db\Branch\BranchedObject; @@ -617,7 +618,11 @@ abstract class ObjectController extends ActionController $info, $this->Auth(), $this->api() - )->handleRequest() + ) + ->callOnSuccess(function (DeploymentLinkForm $form) { + $this->getResponse()->setHeader('X-Icinga-Extra-Updates', join(',', ['#col1'])); + }) + ->handleRequest() ); } } diff --git a/public/css/module.less b/public/css/module.less index 51c4ec25..89712577 100644 --- a/public/css/module.less +++ b/public/css/module.less @@ -1527,6 +1527,16 @@ input[type=submit].icon-button { } } +form.deployment-link-form { + input[type=submit] { + &:disabled { + background-color: unset; + color: @disabled-gray; + cursor: default; + } + } +} + .breadcrumb { > .critical a { color: @text-color-inverted; background: @color-critical; } > .critical.handled a { color: @text-color-inverted; background: @color-critical-handled; }