diff --git a/CHANGELOG.md b/CHANGELOG.md index 94552f4..2e2381d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Pages rendered with Twig templates instead of PHP `echo` - Make the plugin compatible with the Content Security Policy +### Fixed + +- Alerts of a child entity are displayed on the central page, the helpdesk, the service catalog and above the ticket list + ## [1.15.1] - 2026-11-05 ### Added diff --git a/inc/alert.class.php b/inc/alert.class.php index 2d1176b..d2d2926 100644 --- a/inc/alert.class.php +++ b/inc/alert.class.php @@ -252,7 +252,7 @@ public static function findAllToNotify($params = []) $p['show_hidden_alerts'] = false; $p['show_only_helpdesk_alerts'] = false; $p['show_only_service_catalog_alerts'] = false; - $p['entities_id'] = false; + $p['entities_id'] = ''; foreach ($params as $key => $value) { $p[$key] = $value; } @@ -543,7 +543,7 @@ public static function displayAlerts($params = [], ?string $wrapper = null) $p['show_hidden_alerts'] = false; $p['show_only_helpdesk_alerts'] = false; $p['show_only_service_catalog_alerts'] = false; - $p['entities_id'] = false; + $p['entities_id'] = ''; foreach ($params as $key => $value) { $p[$key] = $value; } @@ -744,7 +744,7 @@ public static function preItemForm($params = []) ) { $item = $params['item']; $itemtype = get_class($item); - $entities_id = $params['item']->fields['entities_id'] ?? false; // false to use current entity + $entities_id = $params['item']->fields['entities_id'] ?? ''; // '' to use current entities self::displayAlerts(['show_only_helpdesk_alerts' => true, 'show_hidden_alerts' => false, 'entities_id' => $entities_id, diff --git a/tests/units/PluginNewsAlertTest.php b/tests/units/PluginNewsAlertTest.php index c911147..db32dc8 100644 --- a/tests/units/PluginNewsAlertTest.php +++ b/tests/units/PluginNewsAlertTest.php @@ -323,6 +323,31 @@ public function testAlertPreviewDisplaysWhetherYouCanEditOrNot(): void $this->assertStringNotContainsString('disabled', $matches[0]); } + public function testFindAllToNotifyUsesActiveChildEntityByDefault(): void + { + $this->login('glpi'); + + $alert = $this->createItem(PluginNewsAlert::class, [ + 'name' => 'Child entity alert', + 'message' => 'Alert in a child entity', + 'type' => 1, + 'size' => 'medium', + 'icon' => 'settings', + 'is_displayed_onlogin' => 0, + 'is_displayed_oncentral' => 1, + 'is_displayed_onhelpdesk' => 1, + 'is_displayed_onservicecatalog' => 1, + 'is_active' => 1, + 'is_recursive' => 0, + 'entities_id' => getItemByTypeName('Entity', '_test_child_1', true), + ]); + + $this->setEntity('_test_child_1', false); + + $alerts_ids = array_column(PluginNewsAlert::findAllToNotify(['show_only_central_alerts' => true]) ?: [], 'id'); + $this->assertContains($alert->getID(), $alerts_ids); + } + public function testUpgradeTurnsColoredCustomAlertsIntoImportantOnes(): void { /** @var \DBmysql $DB */