Skip to content

Commit 632bb5b

Browse files
committed
trigger validation_answer notifications only when answered
1 parent 874bff8 commit 632bb5b

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/CommonITILValidation.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,12 @@ public function post_updateItem($history = true)
539539

540540
// -- notifications
541541
if (
542-
count($this->updates)
542+
in_array('status', $this->updates)
543+
&& (int) $this->fields["status"] !== self::WAITING
543544
&& $donotif
544545
) {
545-
$options = ['validation_id' => $this->fields["id"],
546+
$options = [
547+
'validation_id' => $this->fields["id"],
546548
'validation_status' => $this->fields["status"],
547549
];
548550
NotificationEvent::raiseEvent('validation_answer', $this->getItem(), $options, $this);

tests/src/CommonITILValidationTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use NotificationEventMailing;
4343
use NotificationTargetCommonITILObject;
4444
use PHPUnit\Framework\Attributes\DataProvider;
45+
use QueuedNotification;
4546
use Rule;
4647
use RuleCommonITILObject;
4748
use RuntimeException;
@@ -1624,4 +1625,40 @@ public function testNotificationValidatorSubstitutes()
16241625
// Substitute timerange expired
16251626
$this->assertEmpty($notification_target->target);
16261627
}
1628+
1629+
public function testValidationAnswerNotification(): void
1630+
{
1631+
global $CFG_GLPI;
1632+
1633+
$this->login();
1634+
$itil = $this->createItem($this->getITILClassname(), [
1635+
'name' => 'Test Notification Recipients',
1636+
'content' => 'Test Notification Recipients',
1637+
]);
1638+
$validation = $this->createItem($this->getValidationClassname(), [
1639+
$itil::getForeignKeyField() => $itil->getID(),
1640+
'itemtype_target' => 'User',
1641+
'items_id_target' => $_SESSION['glpiID'],
1642+
]);
1643+
$queued_notification = new QueuedNotification();
1644+
1645+
$CFG_GLPI["use_notifications"] = true;
1646+
$CFG_GLPI['notifications_mailing'] = true;
1647+
1648+
$this->assertEquals(0, countElementsInTable($queued_notification::getTable(), ['event' => 'validation_answer']));
1649+
1650+
// Updating the submission comment should not trigger the validation_answer notification
1651+
$validation->update([
1652+
'id' => $validation->getID(),
1653+
'comment_submission' => 'This is a comment.',
1654+
]);
1655+
$this->assertEquals(0, countElementsInTable($queued_notification::getTable(), ['event' => 'validation_answer']));
1656+
1657+
$validation->update([
1658+
'id' => $validation->getID(),
1659+
'status' => CommonITILValidation::ACCEPTED,
1660+
]);
1661+
// Administrator + Approver
1662+
$this->assertEquals(2, countElementsInTable($queued_notification::getTable(), ['event' => 'validation_answer']));
1663+
}
16271664
}

0 commit comments

Comments
 (0)