Skip to content

Commit

Permalink
[MGMTEX] Fix action data override when adding a second action (elasti…
Browse files Browse the repository at this point in the history
…c#181604)

## Summary

We were overwriting the `actionTypeId` of the first action in the
"create connector" callback. The value assigned was the `actionTypeId`
of the newly created action, meaning that we would have converted the
first action to be the same as the second one. This fix changes the
`actionTypeId` not for the first option but for all current
`activeActionItem.indices`.

Previously, we did add that override to fix a bug related to the slack
connector elastic#155722. Its test
should cover us from breaking it back again. I did test it manually just
in case and it seems to be working still. Feel free to test it too.

Also, if you are wondering why `activeActionItems.indices` is an array
of numbers. The user might be using the same connector in more than one
action and then delete the connector. In case this happens, and the user
clicks on "edit rule", they will be able to restore both actions by just
creating the connector once. In order to be able to restore all affected
actions, their index is being stored as a number[]. More info here
elastic#86838

Closes elastic#181407

---------

Co-authored-by: Antonio <[email protected]>
  • Loading branch information
jcger and adcoelho authored Apr 25, 2024
1 parent 1be60eb commit 60c6cdb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ export const ActionForm = ({
// TODO: fix in https://github.com/elastic/kibana/issues/155993
// actionTypes with subtypes need to be updated in case they switched to a
// subtype that is not the default one
actions[0].actionTypeId = savedAction.actionTypeId;
activeActionItem.indices.forEach((index: number) => {
actions[index].actionTypeId = savedAction.actionTypeId;
});
connectors.push(savedAction);
const indicesToUpdate = activeActionItem.indices || [];
indicesToUpdate.forEach((index: number) => setActionIdByIndex(savedAction.id, index));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,53 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

await discardNewRuleCreation();
});

it('should not do a type override when adding a second action', async () => {
// create a new rule
const ruleName = generateUniqueKey();
await rules.common.defineIndexThresholdAlert(ruleName);

// add server log action
await testSubjects.click('.server-log-alerting-ActionTypeSelectOption');
expect(
await find.existsByCssSelector(
'[data-test-subj="comboBoxSearchInput"][value="Serverlog#xyz"]'
)
).to.eql(true);
expect(
await find.existsByCssSelector(
'[data-test-subj="comboBoxSearchInput"][value="webhook-test"]'
)
).to.eql(false);

// click on add new action
await testSubjects.click('addAlertActionButton');
await find.existsByCssSelector('[data-test-subj="Serverlog#xyz"]');

// create webhook connector
await testSubjects.click('.webhook-alerting-ActionTypeSelectOption');
await testSubjects.click('createActionConnectorButton-1');
await testSubjects.setValue('nameInput', 'webhook-test');
await testSubjects.setValue('webhookUrlText', 'https://test.test');
await testSubjects.setValue('webhookUserInput', 'fakeuser');
await testSubjects.setValue('webhookPasswordInput', 'fakepassword');
await testSubjects.click('saveActionButtonModal');

// checking the new one first to avoid flakiness. If the value is checked before the new one is added
// it might return a false positive
expect(
await find.existsByCssSelector(
'[data-test-subj="comboBoxSearchInput"][value="webhook-test"]'
)
).to.eql(true);
// If it was overridden, the value would change to be empty
expect(
await find.existsByCssSelector(
'[data-test-subj="comboBoxSearchInput"][value="Serverlog#xyz"]'
)
).to.eql(true);

await deleteConnectorByName('webhook-test');
});
});
};

0 comments on commit 60c6cdb

Please sign in to comment.