Skip to content

Commit 07e1a1c

Browse files
committed
take into account which features available in the active space
1 parent a6989b5 commit 07e1a1c

File tree

29 files changed

+1228
-1009
lines changed

29 files changed

+1228
-1009
lines changed

examples/alerting_example/server/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class AlertingExamplePlugin implements Plugin<void, void, AlertingExample
4444
defaultMessage: 'Alerts Example',
4545
}),
4646
app: [],
47+
alerting: [alwaysFiringAlert.id, peopleInSpaceAlert.id, INDEX_THRESHOLD_ID],
4748
privileges: {
4849
all: {
4950
alerting: {

x-pack/plugins/alerting_builtins/server/feature.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const BUILT_IN_ALERTS_FEATURE = {
1515
}),
1616
icon: 'bell',
1717
app: [],
18+
alerting: [IndexThreshold],
1819
privileges: {
1920
all: {
2021
app: [],

x-pack/plugins/alerts/server/alerts_client_factory.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const alertsClientFactoryParams: jest.Mocked<AlertsClientFactoryOpts> = {
3737
taskManager: taskManagerMock.start(),
3838
alertTypeRegistry: alertTypeRegistryMock.create(),
3939
getSpaceId: jest.fn(),
40+
getSpace: jest.fn(),
4041
spaceIdToNamespace: jest.fn(),
4142
encryptedSavedObjectsClient: encryptedSavedObjectsMock.createClient(),
4243
actions: actionsMock.createStart(),
@@ -98,6 +99,7 @@ test('creates an alerts client with proper constructor arguments when security i
9899
alertTypeRegistry: alertsClientFactoryParams.alertTypeRegistry,
99100
features: alertsClientFactoryParams.features,
100101
auditLogger: expect.any(AlertsAuthorizationAuditLogger),
102+
getSpace: expect.any(Function),
101103
});
102104

103105
expect(AlertsAuthorizationAuditLogger).toHaveBeenCalledWith(logger);
@@ -146,6 +148,7 @@ test('creates an alerts client with proper constructor arguments', async () => {
146148
alertTypeRegistry: alertsClientFactoryParams.alertTypeRegistry,
147149
features: alertsClientFactoryParams.features,
148150
auditLogger: expect.any(AlertsAuthorizationAuditLogger),
151+
getSpace: expect.any(Function),
149152
});
150153

151154
expect(jest.requireMock('./alerts_client').AlertsClient).toHaveBeenCalledWith({

x-pack/plugins/alerts/server/alerts_client_factory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import { TaskManagerStartContract } from '../../task_manager/server';
1515
import { PluginStartContract as FeaturesPluginStart } from '../../features/server';
1616
import { AlertsAuthorization } from './authorization/alerts_authorization';
1717
import { AlertsAuthorizationAuditLogger } from './authorization/audit_logger';
18+
import { Space } from '../../spaces/server';
1819

1920
export interface AlertsClientFactoryOpts {
2021
logger: Logger;
2122
taskManager: TaskManagerStartContract;
2223
alertTypeRegistry: AlertTypeRegistry;
2324
securityPluginSetup?: SecurityPluginSetup;
2425
getSpaceId: (request: KibanaRequest) => string | undefined;
26+
getSpace: (request: KibanaRequest) => Promise<Space | undefined>;
2527
spaceIdToNamespace: SpaceIdToNamespaceFunction;
2628
encryptedSavedObjectsClient: EncryptedSavedObjectsClient;
2729
actions: ActionsPluginStartContract;
@@ -35,6 +37,7 @@ export class AlertsClientFactory {
3537
private alertTypeRegistry!: AlertTypeRegistry;
3638
private securityPluginSetup?: SecurityPluginSetup;
3739
private getSpaceId!: (request: KibanaRequest) => string | undefined;
40+
private getSpace!: (request: KibanaRequest) => Promise<Space | undefined>;
3841
private spaceIdToNamespace!: SpaceIdToNamespaceFunction;
3942
private encryptedSavedObjectsClient!: EncryptedSavedObjectsClient;
4043
private actions!: ActionsPluginStartContract;
@@ -47,6 +50,7 @@ export class AlertsClientFactory {
4750
this.isInitialized = true;
4851
this.logger = options.logger;
4952
this.getSpaceId = options.getSpaceId;
53+
this.getSpace = options.getSpace;
5054
this.taskManager = options.taskManager;
5155
this.alertTypeRegistry = options.alertTypeRegistry;
5256
this.securityPluginSetup = options.securityPluginSetup;
@@ -63,6 +67,7 @@ export class AlertsClientFactory {
6367
authorization: securityPluginSetup?.authz,
6468
securityLicense: securityPluginSetup?.license,
6569
request,
70+
getSpace: this.getSpace,
6671
alertTypeRegistry: this.alertTypeRegistry,
6772
features: features!,
6873
auditLogger: new AlertsAuthorizationAuditLogger(

0 commit comments

Comments
 (0)