diff --git a/application/controllers/ContactsController.php b/application/controllers/ContactsController.php index 7a65f7be3..a58ab5cdf 100644 --- a/application/controllers/ContactsController.php +++ b/application/controllers/ContactsController.php @@ -43,7 +43,7 @@ public function init() public function indexAction() { $contacts = Contact::on($this->db) - ->withColumns('has_email'); + ->withColumns(['has_email', 'has_webhook']); $limitControl = $this->createLimitControl(); $paginationControl = $this->createPaginationControl($contacts); diff --git a/library/Notifications/Common/Icons.php b/library/Notifications/Common/Icons.php index d63fecad2..1ab2f26e8 100644 --- a/library/Notifications/Common/Icons.php +++ b/library/Notifications/Common/Icons.php @@ -41,4 +41,8 @@ private function __construct() public const RULE_MATCHED = 'filter'; public const UNDEFINED = 'notdef'; + + public const EMAIL = 'at'; + + public const WEBHOOK = 'link'; } diff --git a/library/Notifications/Model/Behavior/HasAddress.php b/library/Notifications/Model/Behavior/HasAddress.php index 2e7db3fcf..64a49c22f 100644 --- a/library/Notifications/Model/Behavior/HasAddress.php +++ b/library/Notifications/Model/Behavior/HasAddress.php @@ -30,7 +30,7 @@ public function setQuery(Query $query) public function rewriteColumn($column, ?string $relation = null) { if ($this->isSelectableColumn($column)) { - $type = 'email'; + $type = $column === 'has_email' ? 'email' : 'webhook'; $subQueryRelation = $relation !== null ? $relation . '.contact.contact_address' : 'contact.contact_address'; @@ -53,7 +53,7 @@ public function rewriteColumn($column, ?string $relation = null) public function isSelectableColumn(string $name): bool { - return $name === 'has_email'; + return $name === 'has_email' || $name === 'has_webhook'; } public function rewriteColumnDefinition(ColumnDefinition $def, string $relation): void @@ -61,7 +61,9 @@ public function rewriteColumnDefinition(ColumnDefinition $def, string $relation) $name = $def->getName(); if ($this->isSelectableColumn($name)) { - $def->setLabel(t('Has Email Address')); + $def->setLabel( + $name === 'has_email' ? t('Has Email Address') : t('Has Webhook') + ); } } @@ -70,7 +72,7 @@ public function rewriteCondition(Filter\Condition $condition, $relation = null) $column = substr($condition->getColumn(), strlen($relation)); if ($this->isSelectableColumn($column)) { - $type = 'email'; + $type = $column === 'has_email' ? 'email' : 'webhook'; $subQuery = $this->query->createSubQuery(new ContactAddress(), $relation) ->limit(1) diff --git a/library/Notifications/Widget/ItemList/ContactListItem.php b/library/Notifications/Widget/ItemList/ContactListItem.php index e80d6026d..ae6a11384 100644 --- a/library/Notifications/Widget/ItemList/ContactListItem.php +++ b/library/Notifications/Widget/ItemList/ContactListItem.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Notifications\Widget\ItemList; +use Icinga\Module\Notifications\Common\Icons; use Icinga\Module\Notifications\Model\Contact; use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; @@ -45,7 +46,11 @@ protected function assembleFooter(BaseHtmlElement $footer): void $contactIcons = new HtmlElement('div', Attributes::create(['class' => 'contact-icons'])); if (isset($this->item->has_email) && $this->item->has_email) { - $contactIcons->addHtml(new Icon('at')); + $contactIcons->addHtml(new Icon(Icons::EMAIL)); + } + + if (isset($this->item->has_webhook) && $this->item->has_webhook) { + $contactIcons->addHtml(new Icon(Icons::WEBHOOK)); } $footer->addHtml($contactIcons);