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
  • Loading branch information
sukhwinder33445 committed Jul 11, 2024
1 parent 2bf142a commit e1c327f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 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,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',
Expand Down

0 comments on commit e1c327f

Please sign in to comment.