Skip to content

Commit

Permalink
Address PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoldevila committed Nov 3, 2022
1 parent d6e46f5 commit 8d026c5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 41 deletions.
20 changes: 17 additions & 3 deletions x-pack/plugins/notifications/server/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@
* 2.0.
*/

import { schema, type TypeOf } from '@kbn/config-schema';
import type { PluginConfigDescriptor } from '@kbn/core/server';
import { configSchema, type ConnectorsEmailConfigType } from './connectors_email_config';

export type NotificationsConfigType = ConnectorsEmailConfigType;
export const configSchema = schema.object(
{
connectors: schema.maybe(
schema.object({
default: schema.maybe(
schema.object({
email: schema.maybe(schema.string()),
})
),
})
),
},
{ defaultValue: {} }
);
export type NotificationsConfigType = TypeOf<typeof configSchema>;

export const config: PluginConfigDescriptor<ConnectorsEmailConfigType> = {
export const config: PluginConfigDescriptor<NotificationsConfigType> = {
schema: configSchema,
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ export class ConnectorsEmailService implements EmailService {
) {}

async sendPlainTextEmail(params: PlainTextEmail): Promise<void> {
const relatedSavedObjects = params.context?.relatedObjects?.length
? params.context!.relatedObjects!.map(({ id, type, spaceId }) => {
return {
id,
type,
namespace: spaceId,
};
})
: undefined;

const actions = params.to.map((to) => ({
id: this.connectorId,
params: {
to: [to],
subject: params.subject,
message: params.message,
},
...(params.context?.relatedObjects?.length && {
relatedSavedObjects: params.context!.relatedObjects!.map(
({ id, type, spaceId: namespace }) => ({ id, type, namespace })
),
}),
relatedSavedObjects,
}));
return await this.actionsClient.bulkEnqueueExecution(this.requesterId, actions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { LicensedEmailService } from './licensed_email_service';
import { ConnectorsEmailService } from './connectors_email_service';
import { PLUGIN_ID } from '../../common';

const MINIMUM_LICENSE = 'platinum';

export interface EmailServiceSetupDeps {
actions?: PluginSetupContract;
licensing?: LicensingPluginSetup;
Expand Down Expand Up @@ -54,6 +56,7 @@ export class EmailServiceProvider
}

this.setupSuccessful = true;
this.setupError = '';
}

public start(plugins: EmailServiceStartDeps): EmailServiceStart {
Expand All @@ -68,7 +71,7 @@ export class EmailServiceProvider
email = new LicensedEmailService(
new ConnectorsEmailService(PLUGIN_ID, emailConnector, unsecuredActionsClient),
licensing.license$,
'platinum',
MINIMUM_LICENSE,
this.logger
);
} catch (err) {
Expand All @@ -79,8 +82,10 @@ export class EmailServiceProvider
return {
isEmailServiceAvailable: () => !!email,
getEmailService: () => {
if (email) return email;
throw new Error(this.setupError);
if (!email) {
throw new Error(this.setupError);
}
return email;
},
};
}
Expand Down

0 comments on commit 8d026c5

Please sign in to comment.