From e1c327f239acfe5fa0d784e8e7bfac5b614025d4 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 11 Jul 2024 12:51:46 +0200 Subject: [PATCH] ChannelForm: Disable delete button if a contact has the channel as default --- application/forms/ChannelForm.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/application/forms/ChannelForm.php b/application/forms/ChannelForm.php index f7ccbc27..63a81211 100644 --- a/application/forms/ChannelForm.php +++ b/application/forms/ChannelForm.php @@ -7,6 +7,7 @@ use Icinga\Exception\Http\HttpNotFoundException; use Icinga\Module\Notifications\Model\Channel; use Icinga\Module\Notifications\Model\AvailableChannelType; +use Icinga\Module\Notifications\Model\Contact; use Icinga\Module\Notifications\Model\RuleEscalationRecipient; use Icinga\Web\Session; use ipl\Html\Contract\FormSubmitElement; @@ -113,14 +114,21 @@ protected function assemble() ); if ($this->channelId !== null) { - $isInUse = RuleEscalationRecipient::on($this->db) + $isInUse = Contact::on($this->db) ->columns('1') - ->filter(Filter::any( - Filter::equal('channel_id', $this->channelId), - Filter::equal('contact.default_channel_id', $this->channelId) - )) + ->filter(Filter::equal('default_channel_id', $this->channelId)) ->first(); + if ($isInUse === null) { + $isInUse = RuleEscalationRecipient::on($this->db) + ->columns('1') + ->filter(Filter::any( + Filter::equal('channel_id', $this->channelId), + Filter::equal('contact.default_channel_id', $this->channelId) + )) + ->first(); + } + /** @var FormSubmitElement $deleteButton */ $deleteButton = $this->createElement( 'submit',