Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution][Bulk actions]- Fix bulk actions data views behavior #138448

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,36 @@ describe('ruleParamsModifier', () => {
expect(editedRuleParams).toHaveProperty('dataViewId', undefined);
});

test('should set dataViewId to undefined if overwrite_data_views=true on delete_index_patterns action', () => {
const editedRuleParams = ruleParamsModifier(
{ dataViewId: 'test-data-view', index: ['test-*', 'index'] } as RuleAlertType['params'],
[
{
type: BulkActionEditType.delete_index_patterns,
value: ['index'],
overwrite_data_views: true,
},
]
);
expect(editedRuleParams).toHaveProperty('dataViewId', undefined);
expect(editedRuleParams).toHaveProperty('index', ['test-*']);
});

test('should set dataViewId to undefined and index to undefined if overwrite_data_views=true on delete_index_patterns action and rule had no index patterns to begin with', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

const editedRuleParams = ruleParamsModifier(
{ dataViewId: 'test-data-view', index: undefined } as RuleAlertType['params'],
[
{
type: BulkActionEditType.delete_index_patterns,
value: ['index'],
overwrite_data_views: true,
},
]
);
expect(editedRuleParams).toHaveProperty('dataViewId', undefined);
expect(editedRuleParams).toHaveProperty('index', undefined);
});

test('should throw error on adding index pattern if rule is of machine learning type', () => {
expect(() =>
ruleParamsModifier({ type: 'machine_learning' } as RuleAlertType['params'], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const applyBulkActionEditToRuleParams = (
"Index patterns can't be added. Machine learning rule doesn't have index patterns property"
);

if (ruleParams.dataViewId != null && !action.overwrite_data_views) {
break;
}

if (action.overwrite_data_views) {
ruleParams.dataViewId = undefined;
}
Expand All @@ -48,6 +52,14 @@ const applyBulkActionEditToRuleParams = (
"Index patterns can't be deleted. Machine learning rule doesn't have index patterns property"
);

if (ruleParams.dataViewId != null && !action.overwrite_data_views) {
break;
}

if (action.overwrite_data_views) {
ruleParams.dataViewId = undefined;
}

if (ruleParams.index) {
ruleParams.index = deleteItemsFromArray(ruleParams.index, action.value);
}
Expand All @@ -59,6 +71,10 @@ const applyBulkActionEditToRuleParams = (
"Index patterns can't be overwritten. Machine learning rule doesn't have index patterns property"
);

if (ruleParams.dataViewId != null && !action.overwrite_data_views) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe encapsulate this in a declarative helper? e.g.

Suggested change
if (ruleParams.dataViewId != null && !action.overwrite_data_views) {
if (actionNotValid(action, ruleParams)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽 I think there's a different helper method @banderror had suggested we could use. Can definitely cleanup/revisit post 8.4.

break;
}

if (action.overwrite_data_views) {
ruleParams.dataViewId = undefined;
}
Expand Down
Loading