Skip to content

Commit

Permalink
ChannelForm: Disable delete button if a contact has the channel as de…
Browse files Browse the repository at this point in the history
…fault_channel
  • Loading branch information
sukhwinder33445 committed Jul 11, 2024
1 parent 2bf142a commit 54c6408
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions application/forms/ChannelForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,14 +114,18 @@ 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::equal('channel_id', $this->channelId))
->first();
}

/** @var FormSubmitElement $deleteButton */
$deleteButton = $this->createElement(
'submit',
Expand Down

0 comments on commit 54c6408

Please sign in to comment.