Skip to content

Commit

Permalink
fix filter on kuery node (#142001) (#142025)
Browse files Browse the repository at this point in the history
(cherry picked from commit a8e8f3f)

Co-authored-by: Xavier Mouligneau <xavier.mouligneau@elastic.co>
  • Loading branch information
kibanamachine and XavierM committed Sep 28, 2022
1 parent 0b92a86 commit 1ceb607
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ export class RulesClient {
filter:
(authorizationFilter && filterKueryNode
? nodeBuilder.and([filterKueryNode, authorizationFilter as KueryNode])
: authorizationFilter) ?? options.filter,
: authorizationFilter) ?? filterKueryNode,
fields: fields ? this.includeFieldsRequiredForAuthentication(fields) : fields,
type: 'alert',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('find()', () => {
Array [
Object {
"fields": undefined,
"filter": undefined,
"filter": null,
"sortField": undefined,
"type": "alert",
},
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('find()', () => {
Array [
Object {
"fields": undefined,
"filter": undefined,
"filter": null,
"sortField": undefined,
"type": "alert",
},
Expand Down Expand Up @@ -730,6 +730,8 @@ describe('find()', () => {

expect(unsecuredSavedObjectsClient.find).toHaveBeenCalledWith({
fields: ['tags', 'alertTypeId', 'consumer'],
filter: null,
sortField: undefined,
type: 'alert',
});
expect(ensureRuleTypeIsAuthorized).toHaveBeenCalledWith('myType', 'myApp', 'rule');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { fromKueryExpression } from '@kbn/es-query';
import { Spaces } from '../../scenarios';
import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../common/lib';
import { FtrProviderContext } from '../../../common/ftr_provider_context';
Expand Down Expand Up @@ -198,6 +199,20 @@ const findTestUtils = (
expect(response.body.data[0].params.strValue).to.eql('my b');
});

it('should filter on kueryNode parameters', async () => {
const response = await supertest.get(
`${getUrlPrefix(Spaces.space1.id)}/${
describeType === 'public' ? 'api' : 'internal'
}/alerting/rules/_find?filter=${JSON.stringify(
fromKueryExpression('alert.attributes.params.strValue:"my b"')
)}`
);

expect(response.status).to.eql(200);
expect(response.body.total).to.equal(1);
expect(response.body.data[0].params.strValue).to.eql('my b');
});

it('should sort by parameters', async () => {
const response = await supertest.get(
`${getUrlPrefix(Spaces.space1.id)}/${
Expand Down

0 comments on commit 1ceb607

Please sign in to comment.