From 06362d1df26f3779b59abe25817e81b3f1b46063 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Tue, 23 Apr 2024 17:03:09 +0200 Subject: [PATCH] Fix escalation condition and recipient removal --- .../EscalationCondition.php | 35 +++++-------------- .../EscalationRecipient.php | 8 +++++ application/forms/EventRuleConfigForm.php | 4 +-- .../ItemList/EscalationRecipientListItem.php | 4 +-- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/application/forms/EventRuleConfigElements/EscalationCondition.php b/application/forms/EventRuleConfigElements/EscalationCondition.php index 75fe3dc6c..7716c425c 100644 --- a/application/forms/EventRuleConfigElements/EscalationCondition.php +++ b/application/forms/EventRuleConfigElements/EscalationCondition.php @@ -83,7 +83,6 @@ protected function assemble(): void for ($i = 1; $i <= $conditionCount; $i++) { $colName = 'column_' . $i; $opName = 'operator_' . $i; - $typeName = 'type_' . $i; $valName = 'val_' . $i; $col = $this->createElement( @@ -133,18 +132,6 @@ protected function assemble(): void ] ); - if ( - $this->getPopulatedValue($typeName) !== 'incident_severity' - && $this->getPopulatedValue($valName) !== null - ) { - $this->clearPopulatedValue($typeName); - $this->clearPopulatedValue($valName); - } - - $this->addElement('hidden', $typeName, [ - 'value' => 'incident_severity' - ]); - break; case 'incident_age': $val = $this->createElement( @@ -173,18 +160,6 @@ protected function assemble(): void ] ); - if ( - $this->getPopulatedValue($typeName) !== 'incident_age' - && $this->getPopulatedValue($valName) !== null - ) { - $this->clearPopulatedValue($typeName); - $this->clearPopulatedValue($valName); - } - - $this->addElement('hidden', $typeName, [ - 'value' => 'incident_age' - ]); - break; default: $val = $this->createElement('text', $valName, [ @@ -221,7 +196,7 @@ protected function assemble(): void $this->conditions[$nextCount]->conditionType->setName('column_' . $n); $this->conditions[$nextCount]->operator->setName('operator_' . $n); $this->conditions[$nextCount]->conditionVal->setName('val_' . $n); - if ($conditionCount === 1) { + if ($conditionCount === 1 && ! $this->allowZeroConditions) { $this->conditions[$nextCount]->removeButton = null; } elseif ($this->conditions[$nextCount]->removeButton) { $this->conditions[$nextCount]->removeButton->setValue((string) $n); @@ -290,9 +265,17 @@ public function getCondition(): string $filter = Filter::any(); /** @var int $count */ $count = $this->getValue('condition-count'); + $removePosition = $this->getValue('remove'); + if ($removePosition) { + $count += 1; + } if ($count > 0) { // if count is 0, loop runs in reverse direction foreach (range(1, $count) as $count) { + if ($count === (int) $removePosition) { + continue; + } + $chosenType = $this->getValue('column_' . $count, 'placeholder'); $filterStr = $chosenType diff --git a/application/forms/EventRuleConfigElements/EscalationRecipient.php b/application/forms/EventRuleConfigElements/EscalationRecipient.php index 7f4312556..ba171dadf 100644 --- a/application/forms/EventRuleConfigElements/EscalationRecipient.php +++ b/application/forms/EventRuleConfigElements/EscalationRecipient.php @@ -219,9 +219,17 @@ public function getRecipients(): array { /** @var int $count */ $count = $this->getValue('recipient-count'); + $removePosition = $this->getValue('remove'); + if ($removePosition) { + $count += 1; + } $values = []; for ($i = 1; $i <= $count; $i++) { + if ($i === (int) $removePosition) { + continue; + } + $value = []; $value['channel_id'] = $this->getValue('val_' . $i); $value['id'] = $this->getValue('id_' . $i); diff --git a/application/forms/EventRuleConfigForm.php b/application/forms/EventRuleConfigForm.php index 51979799e..01462c04d 100644 --- a/application/forms/EventRuleConfigForm.php +++ b/application/forms/EventRuleConfigForm.php @@ -250,7 +250,7 @@ protected function assemble(): void if ($noZeroEscalationConditions === true) { foreach ($escalations as $escalation) { - $escalation->getCondition() + $escalation->condition ->setAllowZeroConditions(true); } @@ -258,7 +258,7 @@ protected function assemble(): void ->setValue(null); } elseif ($zeroConditionEscalation) { $escalations[$zeroConditionEscalation] - ->getCondition() + ->condition ->setAllowZeroConditions(true); } diff --git a/library/Notifications/Widget/ItemList/EscalationRecipientListItem.php b/library/Notifications/Widget/ItemList/EscalationRecipientListItem.php index 11cd078f7..58779783f 100644 --- a/library/Notifications/Widget/ItemList/EscalationRecipientListItem.php +++ b/library/Notifications/Widget/ItemList/EscalationRecipientListItem.php @@ -24,11 +24,11 @@ class EscalationRecipientListItem extends BaseHtmlElement public $channel; public function __construct( - BaseFormElement $reipient, + BaseFormElement $recipient, BaseFormElement $channel, ?SubmitButtonElement $removeButton ) { - $this->recipient = $reipient; + $this->recipient = $recipient; $this->channel = $channel; $this->removeButton = $removeButton; }