diff --git a/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts b/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts index 83f90b68a99b1..d6fb8d415e57f 100644 --- a/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts +++ b/x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts @@ -750,6 +750,8 @@ describe('AlertingAuthorization', () => { name: 'myOtherAppAlertType', producer: 'alerts', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const myAppAlertType: RegistryRuleType = { actionGroups: [], @@ -762,6 +764,8 @@ describe('AlertingAuthorization', () => { name: 'myAppAlertType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const mySecondAppAlertType: RegistryRuleType = { actionGroups: [], @@ -774,6 +778,8 @@ describe('AlertingAuthorization', () => { name: 'mySecondAppAlertType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const setOfAlertTypes = new Set([myAppAlertType, myOtherAppAlertType, mySecondAppAlertType]); test('omits filter when there is no authorization api', async () => { @@ -1145,6 +1151,8 @@ describe('AlertingAuthorization', () => { name: 'myOtherAppAlertType', producer: 'myOtherApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const myAppAlertType: RegistryRuleType = { actionGroups: [], @@ -1157,6 +1165,8 @@ describe('AlertingAuthorization', () => { name: 'myAppAlertType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const setOfAlertTypes = new Set([myAppAlertType, myOtherAppAlertType]); beforeEach(() => { @@ -1188,75 +1198,79 @@ describe('AlertingAuthorization', () => { AlertingAuthorizationEntity.Rule ) ).resolves.toMatchInlineSnapshot(` - Set { - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "alerts": Object { - "all": true, - "read": true, - }, - "myApp": Object { - "all": true, - "read": true, - }, - "myAppWithSubFeature": Object { - "all": true, - "read": true, - }, - "myOtherApp": Object { - "all": true, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myAppAlertType", - "producer": "myApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "alerts": Object { - "all": true, - "read": true, - }, - "myApp": Object { - "all": true, - "read": true, - }, - "myAppWithSubFeature": Object { - "all": true, - "read": true, - }, - "myOtherApp": Object { - "all": true, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myOtherAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myOtherAppAlertType", - "producer": "myOtherApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - } - `); + Set { + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "alerts": Object { + "all": true, + "read": true, + }, + "myApp": Object { + "all": true, + "read": true, + }, + "myAppWithSubFeature": Object { + "all": true, + "read": true, + }, + "myOtherApp": Object { + "all": true, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myAppAlertType", + "producer": "myApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "alerts": Object { + "all": true, + "read": true, + }, + "myApp": Object { + "all": true, + "read": true, + }, + "myAppWithSubFeature": Object { + "all": true, + "read": true, + }, + "myOtherApp": Object { + "all": true, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myOtherAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myOtherAppAlertType", + "producer": "myOtherApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + } + `); }); test('augments a list of types with consumers under which the operation is authorized', async () => { @@ -1312,59 +1326,63 @@ describe('AlertingAuthorization', () => { AlertingAuthorizationEntity.Rule ) ).resolves.toMatchInlineSnapshot(` - Set { - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "myApp": Object { - "all": true, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myOtherAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myOtherAppAlertType", - "producer": "myOtherApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "alerts": Object { - "all": true, - "read": true, - }, - "myApp": Object { - "all": true, - "read": true, - }, - "myOtherApp": Object { - "all": true, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myAppAlertType", - "producer": "myApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - } - `); + Set { + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "myApp": Object { + "all": true, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myOtherAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myOtherAppAlertType", + "producer": "myOtherApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "alerts": Object { + "all": true, + "read": true, + }, + "myApp": Object { + "all": true, + "read": true, + }, + "myOtherApp": Object { + "all": true, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myAppAlertType", + "producer": "myApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + } + `); }); test('authorizes user under the `alerts` consumer when they are authorized by the producer', async () => { @@ -1407,34 +1425,36 @@ describe('AlertingAuthorization', () => { AlertingAuthorizationEntity.Alert ) ).resolves.toMatchInlineSnapshot(` - Set { - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "alerts": Object { - "all": true, - "read": true, - }, - "myApp": Object { - "all": true, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myAppAlertType", - "producer": "myApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - } - `); + Set { + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "alerts": Object { + "all": true, + "read": true, + }, + "myApp": Object { + "all": true, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myAppAlertType", + "producer": "myApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + } + `); }); test('augments a list of types with consumers under which multiple operations are authorized', async () => { @@ -1511,67 +1531,71 @@ describe('AlertingAuthorization', () => { AlertingAuthorizationEntity.Alert ) ).resolves.toMatchInlineSnapshot(` - Set { - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "alerts": Object { - "all": false, - "read": true, - }, - "myApp": Object { - "all": true, - "read": true, - }, - "myOtherApp": Object { - "all": false, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myOtherAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myOtherAppAlertType", - "producer": "myOtherApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "alerts": Object { - "all": false, - "read": true, - }, - "myApp": Object { - "all": false, - "read": true, - }, - "myOtherApp": Object { - "all": false, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myAppAlertType", - "producer": "myApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - } - `); + Set { + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "alerts": Object { + "all": false, + "read": true, + }, + "myApp": Object { + "all": true, + "read": true, + }, + "myOtherApp": Object { + "all": false, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myOtherAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myOtherAppAlertType", + "producer": "myOtherApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "alerts": Object { + "all": false, + "read": true, + }, + "myApp": Object { + "all": false, + "read": true, + }, + "myOtherApp": Object { + "all": false, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myAppAlertType", + "producer": "myApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + } + `); }); test('omits types which have no consumers under which the operation is authorized', async () => { @@ -1627,38 +1651,40 @@ describe('AlertingAuthorization', () => { AlertingAuthorizationEntity.Alert ) ).resolves.toMatchInlineSnapshot(` - Set { - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "alerts": Object { - "all": true, - "read": true, - }, - "myApp": Object { - "all": true, - "read": true, - }, - "myOtherApp": Object { - "all": true, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myOtherAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myOtherAppAlertType", - "producer": "myOtherApp", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, - } - `); + Set { + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "alerts": Object { + "all": true, + "read": true, + }, + "myApp": Object { + "all": true, + "read": true, + }, + "myOtherApp": Object { + "all": true, + "read": true, + }, + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myOtherAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myOtherAppAlertType", + "producer": "myOtherApp", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + } + `); }); }); @@ -1674,6 +1700,8 @@ describe('AlertingAuthorization', () => { producer: 'alerts', enabledInLicense: true, isExportable: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const myAppAlertType: RegistryRuleType = { actionGroups: [], @@ -1686,6 +1714,8 @@ describe('AlertingAuthorization', () => { producer: 'myApp', enabledInLicense: true, isExportable: true, + hasAlertsMappings: true, + hasFieldsForAAD: true, }; const mySecondAppAlertType: RegistryRuleType = { actionGroups: [], @@ -1698,6 +1728,8 @@ describe('AlertingAuthorization', () => { producer: 'myApp', enabledInLicense: true, isExportable: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const setOfAlertTypes = new Set([myAppAlertType, myOtherAppAlertType, mySecondAppAlertType]); beforeEach(() => { @@ -1738,34 +1770,36 @@ describe('AlertingAuthorization', () => { AlertingAuthorizationEntity.Alert ) ).resolves.toMatchInlineSnapshot(` - Object { - "authorizedRuleTypes": Set { - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "myApp": Object { - "all": false, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myOtherAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myOtherAppAlertType", - "producer": "alerts", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, + Object { + "authorizedRuleTypes": Set { + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "myApp": Object { + "all": false, + "read": true, }, - "hasAllRequested": false, - "username": "some-user", - } - `); + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myOtherAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myOtherAppAlertType", + "producer": "alerts", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + }, + "hasAllRequested": false, + "username": "some-user", + } + `); }); test('it returns all authorized if user has read, get and update alert privileges', async () => { @@ -1811,34 +1845,36 @@ describe('AlertingAuthorization', () => { AlertingAuthorizationEntity.Alert ) ).resolves.toMatchInlineSnapshot(` - Object { - "authorizedRuleTypes": Set { - Object { - "actionGroups": Array [], - "actionVariables": undefined, - "authorizedConsumers": Object { - "myApp": Object { - "all": true, - "read": true, - }, - }, - "defaultActionGroupId": "default", - "enabledInLicense": true, - "id": "myOtherAppAlertType", - "isExportable": true, - "minimumLicenseRequired": "basic", - "name": "myOtherAppAlertType", - "producer": "alerts", - "recoveryActionGroup": Object { - "id": "recovered", - "name": "Recovered", - }, - }, + Object { + "authorizedRuleTypes": Set { + Object { + "actionGroups": Array [], + "actionVariables": undefined, + "authorizedConsumers": Object { + "myApp": Object { + "all": true, + "read": true, }, - "hasAllRequested": false, - "username": "some-user", - } - `); + }, + "defaultActionGroupId": "default", + "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, + "id": "myOtherAppAlertType", + "isExportable": true, + "minimumLicenseRequired": "basic", + "name": "myOtherAppAlertType", + "producer": "alerts", + "recoveryActionGroup": Object { + "id": "recovered", + "name": "Recovered", + }, + }, + }, + "hasAllRequested": false, + "username": "some-user", + } + `); }); }); }); diff --git a/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts b/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts index 4eb901173bc89..051972b944261 100644 --- a/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts +++ b/x-pack/plugins/alerting/server/authorization/alerting_authorization.ts @@ -71,8 +71,6 @@ interface HasPrivileges { type AuthorizedConsumers = Record; export interface RegistryAlertTypeWithAuth extends RegistryRuleType { authorizedConsumers: AuthorizedConsumers; - hasAlertsMappings?: boolean; - hasFieldsForAAD?: boolean; } type IsAuthorizedAtProducerLevel = boolean; @@ -371,7 +369,7 @@ export class AlertingAuthorization { const ruleTypesWithAuthorization = Array.from( this.augmentWithAuthorizedConsumers(ruleTypes, {}) ); - const ruleTypesAuthorized: Map = new Map(); + const ruleTypesAuthorized: Map = new Map(); // map from privilege to ruleType which we can refer back to when analyzing the result // of checkPrivileges const privilegeToRuleType = new Map< @@ -386,9 +384,7 @@ export class AlertingAuthorization { const ruleTypeAuth = ruleTypesWithAuthorization.find((rtwa) => rtwa.id === ruleTypeId); if (ruleTypeAuth) { if (!ruleTypesAuthorized.has(ruleTypeId)) { - const { authorizedConsumers, hasAlertsMappings, hasFieldsForAAD, ...ruleType } = - ruleTypeAuth; - ruleTypesAuthorized.set(ruleTypeId, ruleType); + ruleTypesAuthorized.set(ruleTypeId, ruleTypeAuth); } for (const operation of operations) { privilegeToRuleType.set( diff --git a/x-pack/plugins/alerting/server/authorization/alerting_authorization_kuery.test.ts b/x-pack/plugins/alerting/server/authorization/alerting_authorization_kuery.test.ts index 5013f2fbe1552..c9e129085c3c0 100644 --- a/x-pack/plugins/alerting/server/authorization/alerting_authorization_kuery.test.ts +++ b/x-pack/plugins/alerting/server/authorization/alerting_authorization_kuery.test.ts @@ -32,6 +32,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -67,6 +69,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myOtherApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -105,6 +109,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, { actionGroups: [], @@ -122,6 +128,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, { actionGroups: [], @@ -139,6 +147,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -177,6 +187,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, { actionGroups: [], @@ -194,6 +206,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -233,6 +247,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, { actionGroups: [], @@ -250,6 +266,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -283,6 +301,8 @@ describe('asKqlFiltersByRuleTypeAndConsumer', () => { isExportable: true, authorizedConsumers: {}, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -317,6 +337,8 @@ describe('asEsDslFiltersByRuleTypeAndConsumer', () => { myApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -379,6 +401,8 @@ describe('asEsDslFiltersByRuleTypeAndConsumer', () => { myOtherApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -449,6 +473,8 @@ describe('asEsDslFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, { actionGroups: [], @@ -466,6 +492,8 @@ describe('asEsDslFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, { actionGroups: [], @@ -483,6 +511,8 @@ describe('asEsDslFiltersByRuleTypeAndConsumer', () => { myAppWithSubFeature: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { @@ -646,6 +676,8 @@ describe('asEsDslFiltersByRuleTypeAndConsumer', () => { isExportable: true, authorizedConsumers: {}, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]), { diff --git a/x-pack/plugins/alerting/server/routes/health.test.ts b/x-pack/plugins/alerting/server/routes/health.test.ts index 236d38d836bc1..b1c562ada8717 100644 --- a/x-pack/plugins/alerting/server/routes/health.test.ts +++ b/x-pack/plugins/alerting/server/routes/health.test.ts @@ -49,6 +49,8 @@ const ruleTypes = [ enabledInLicense: true, minimumScheduleInterval: '1m', defaultScheduleInterval: '10m', + hasAlertsMappings: false, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; diff --git a/x-pack/plugins/alerting/server/routes/legacy/health.test.ts b/x-pack/plugins/alerting/server/routes/legacy/health.test.ts index 19279e7dfb77a..9946f659a0744 100644 --- a/x-pack/plugins/alerting/server/routes/legacy/health.test.ts +++ b/x-pack/plugins/alerting/server/routes/legacy/health.test.ts @@ -53,6 +53,8 @@ const ruleTypes = [ producer: 'test', enabledInLicense: true, defaultScheduleInterval: '10m', + hasAlertsMappings: false, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; diff --git a/x-pack/plugins/alerting/server/routes/legacy/list_alert_types.test.ts b/x-pack/plugins/alerting/server/routes/legacy/list_alert_types.test.ts index e2c6a66cf0ab1..7262f42319c1f 100644 --- a/x-pack/plugins/alerting/server/routes/legacy/list_alert_types.test.ts +++ b/x-pack/plugins/alerting/server/routes/legacy/list_alert_types.test.ts @@ -62,6 +62,8 @@ describe('listAlertTypesRoute', () => { }, producer: 'test', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; rulesClient.listRuleTypes.mockResolvedValueOnce(new Set(listTypes)); @@ -85,6 +87,8 @@ describe('listAlertTypesRoute', () => { "authorizedConsumers": Object {}, "defaultActionGroupId": "default", "enabledInLicense": true, + "hasAlertsMappings": false, + "hasFieldsForAAD": false, "id": "1", "isExportable": true, "minimumLicenseRequired": "basic", @@ -137,6 +141,8 @@ describe('listAlertTypesRoute', () => { }, producer: 'alerts', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; @@ -190,6 +196,8 @@ describe('listAlertTypesRoute', () => { }, producer: 'alerts', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; diff --git a/x-pack/plugins/alerting/server/routes/rule_types.test.ts b/x-pack/plugins/alerting/server/routes/rule_types.test.ts index 4629293b36e10..2dab9284bb5ac 100644 --- a/x-pack/plugins/alerting/server/routes/rule_types.test.ts +++ b/x-pack/plugins/alerting/server/routes/rule_types.test.ts @@ -61,6 +61,7 @@ describe('ruleTypesRoute', () => { defaultScheduleInterval: '10m', doesSetRecoveryContext: false, hasAlertsMappings: true, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; const expectedResult: Array> = [ @@ -169,6 +170,8 @@ describe('ruleTypesRoute', () => { }, producer: 'alerts', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; @@ -222,6 +225,8 @@ describe('ruleTypesRoute', () => { }, producer: 'alerts', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, } as RegistryAlertTypeWithAuth, ]; diff --git a/x-pack/plugins/alerting/server/rule_type_registry.ts b/x-pack/plugins/alerting/server/rule_type_registry.ts index 57bf39ff50496..61600bf2b0955 100644 --- a/x-pack/plugins/alerting/server/rule_type_registry.ts +++ b/x-pack/plugins/alerting/server/rule_type_registry.ts @@ -67,6 +67,8 @@ export interface RegistryRuleType > { id: string; enabledInLicense: boolean; + hasFieldsForAAD: boolean; + hasAlertsMappings: boolean; } /** @@ -362,26 +364,28 @@ export class RuleTypeRegistry { } public list(): Set { - return new Set( - Array.from(this.ruleTypes).map( - ([ - id, - { - name, - actionGroups, - recoveryActionGroup, - defaultActionGroupId, - actionVariables, - producer, - minimumLicenseRequired, - isExportable, - ruleTaskTimeout, - defaultScheduleInterval, - doesSetRecoveryContext, - alerts, - fieldsForAAD, - }, - ]: [string, UntypedNormalizedRuleType]) => ({ + const mapRuleTypes: Array<[string, UntypedNormalizedRuleType]> = Array.from(this.ruleTypes); + const tempRegistryRuleType = mapRuleTypes.map( + ([ + id, + { + name, + actionGroups, + recoveryActionGroup, + defaultActionGroupId, + actionVariables, + producer, + minimumLicenseRequired, + isExportable, + ruleTaskTimeout, + defaultScheduleInterval, + doesSetRecoveryContext, + alerts, + fieldsForAAD, + }, + ]) => { + // KEEP the type here to be safe if not the map is ignoring it for some reason + const ruleType: RegistryRuleType = { id, name, actionGroups, @@ -402,9 +406,11 @@ export class RuleTypeRegistry { hasFieldsForAAD: Boolean(fieldsForAAD), hasAlertsMappings: !!alerts, ...(alerts ? { alerts } : {}), - }) - ) + }; + return ruleType; + } ); + return new Set(tempRegistryRuleType); } public getAllTypes(): string[] { diff --git a/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts index 1ae5dc7832bec..c45e74da45999 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/aggregate.test.ts @@ -74,6 +74,8 @@ describe('aggregate()', () => { name: 'myType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]); beforeEach(() => { @@ -156,6 +158,8 @@ describe('aggregate()', () => { myApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]) ); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts index 8475b7317af76..4b1a6fc2eba8c 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/find.test.ts @@ -82,6 +82,8 @@ describe('find()', () => { name: 'myType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]); beforeEach(() => { @@ -142,6 +144,8 @@ describe('find()', () => { myApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]) ); @@ -453,6 +457,8 @@ describe('find()', () => { name: 'myType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]) ); @@ -659,6 +665,8 @@ describe('find()', () => { name: 'myType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]) ); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/get_tags.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/get_tags.test.ts index bf50cc5550955..1f0c4f405f2c2 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/get_tags.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/get_tags.test.ts @@ -61,6 +61,8 @@ const listedTypes = new Set([ name: 'myType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]); @@ -112,6 +114,8 @@ describe('getTags()', () => { myApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]) ); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/list_rule_types.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/list_rule_types.test.ts index 4e41d6d4d4066..9c8c78f2753f4 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/list_rule_types.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/list_rule_types.test.ts @@ -67,6 +67,8 @@ describe('listRuleTypes', () => { name: 'alertingAlertType', producer: 'alerts', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const myAppAlertType: RegistryRuleType = { actionGroups: [], @@ -79,6 +81,8 @@ describe('listRuleTypes', () => { name: 'myAppAlertType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }; const setOfAlertTypes = new Set([myAppAlertType, alertingAlertType]); @@ -121,6 +125,8 @@ describe('listRuleTypes', () => { name: 'myType', producer: 'myApp', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, { id: 'myOtherType', @@ -132,6 +138,8 @@ describe('listRuleTypes', () => { recoveryActionGroup: RecoveredActionGroup, producer: 'alerts', enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]); beforeEach(() => { @@ -153,6 +161,8 @@ describe('listRuleTypes', () => { myApp: { read: true, all: true }, }, enabledInLicense: true, + hasAlertsMappings: false, + hasFieldsForAAD: false, }, ]); authorization.filterByRuleTypeAuthorization.mockResolvedValue(authorizedTypes);