[ResponseOps] Fix editing alerts filter for multi-consumer rule types on serverless (#206848)

## Summary

Fixes #206845

Removes a check to see if a rule has a valid consumer before allowing
alerts filters to be edited in the rule form. This was breaking editing
rules on serverless.

With all relevant rule types having added alerts-as-data functionality,
this check is no longer necessary.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Zacqary Adam Xeper 2025-01-22 11:53:31 -06:00 committed by GitHub
parent b73cb8a31c
commit d6b6fdc9f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 50 deletions

View file

@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { AlertConsumers, ES_QUERY_ID } from '@kbn/rule-data-utils';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { RuleTypeWithDescription } from '../common/types';
import { hasFieldsForAad } from './has_fields_for_aad';
@ -49,30 +49,4 @@ describe('hasFieldsForAad', () => {
expect(hasFields).toBeTruthy();
});
test('should return true if it is a multi-consumer rule and valid consumer contains it', () => {
const hasFields = hasFieldsForAad({
ruleType: {
hasFieldsForAAD: true,
id: ES_QUERY_ID,
} as RuleTypeWithDescription,
consumer: 'stackAlerts',
validConsumers: ['stackAlerts'],
});
expect(hasFields).toBeTruthy();
});
test('should return false if it is a multi-consumer rule and valid consumer does not contain it', () => {
const hasFields = hasFieldsForAad({
ruleType: {
hasFieldsForAAD: true,
id: ES_QUERY_ID,
} as RuleTypeWithDescription,
consumer: 'stackAlerts',
validConsumers: ['logs'],
});
expect(hasFields).toBeFalsy();
});
});

View file

@ -9,7 +9,6 @@
import { AlertConsumers, RuleCreationValidConsumer } from '@kbn/rule-data-utils';
import { RuleTypeWithDescription } from '../common/types';
import { DEFAULT_VALID_CONSUMERS, MULTI_CONSUMER_RULE_TYPE_IDS } from '../constants';
export const hasFieldsForAad = ({
ruleType,
@ -26,11 +25,5 @@ export const hasFieldsForAad = ({
ruleType.hasAlertsMappings
: false;
if (MULTI_CONSUMER_RULE_TYPE_IDS.includes(ruleType.id)) {
return !!(
(validConsumers || DEFAULT_VALID_CONSUMERS).includes(consumer as RuleCreationValidConsumer) &&
hasAlertHasData
);
}
return !!hasAlertHasData;
};

View file

@ -671,23 +671,8 @@ export const RuleForm = ({
selectedRuleType.hasAlertsMappings
: false;
if (MULTI_CONSUMER_RULE_TYPE_IDS.includes(rule?.ruleTypeId ?? '')) {
// Use selectedConsumer when creating a new rule, existing rule consumer when editing
const ruleConsumer = initialSelectedConsumer ? selectedConsumer : rule.consumer;
return (
(validConsumers || VALID_CONSUMERS).includes(ruleConsumer as RuleCreationValidConsumer) &&
hasAlertHasData
);
}
return hasAlertHasData;
}, [
rule?.ruleTypeId,
initialSelectedConsumer,
rule.consumer,
selectedConsumer,
selectedRuleType,
validConsumers,
]);
}, [selectedRuleType]);
const ruleTypeDetails = (
<>