diff --git a/dashboards-reports/public/components/main/report_definition_details/report_definition_details.tsx b/dashboards-reports/public/components/main/report_definition_details/report_definition_details.tsx index a0a111f7..88a4fe93 100644 --- a/dashboards-reports/public/components/main/report_definition_details/report_definition_details.tsx +++ b/dashboards-reports/public/components/main/report_definition_details/report_definition_details.tsx @@ -315,8 +315,10 @@ export function ReportDefinitionDetails(props) { trigger_params: triggerParams, } = trigger; const { - delivery_type: deliveryType, - delivery_params: deliveryParams, + configIds: configIds, + title: title, + textDescription: textDescription, + htmlDescription: htmlDescription } = delivery; const { core_params: { @@ -357,17 +359,11 @@ export function ReportDefinitionDetails(props) { scheduleDetails: triggerParams ? humanReadableScheduleDetails(data.report_definition.trigger) : `\u2014`, - channel: deliveryType, status: reportDefinition.status, - opensearchDashboardsRecipients: deliveryParams.opensearch_dashboards_recipients - ? deliveryParams.opensearch_dashboards_recipients - : `\u2014`, - emailRecipients: - deliveryType === 'Channel' ? deliveryParams.recipients : `\u2014`, - emailSubject: - deliveryType === 'Channel' ? deliveryParams.title : `\u2014`, - emailBody: - deliveryType === 'Channel' ? deliveryParams.textDescription : `\u2014`, + configIds: configIds, + title: title, + textDescription: textDescription, + htmlDescription: htmlDescription }; return reportDefinitionDetails; }; diff --git a/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx b/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx index a8841cda..c0a35ed7 100644 --- a/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx +++ b/dashboards-reports/public/components/report_definitions/create/create_report_definition.tsx @@ -72,8 +72,10 @@ interface triggerType { } interface deliveryType { - delivery_type: string; - delivery_params: any; + configIds: Array; + title: string; + textDescription: string; + htmlDescription: string; } export interface TriggerParamsType { @@ -122,8 +124,10 @@ export function CreateReport(props) { }, }, delivery: { - delivery_type: '', - delivery_params: {}, + configIds: [], + title: '', + textDescription: '', + htmlDescription: '' }, trigger: { trigger_type: '', diff --git a/dashboards-reports/public/components/report_definitions/delivery/delivery.tsx b/dashboards-reports/public/components/report_definitions/delivery/delivery.tsx index 155f33a2..c83aa9fd 100644 --- a/dashboards-reports/public/components/report_definitions/delivery/delivery.tsx +++ b/dashboards-reports/public/components/report_definitions/delivery/delivery.tsx @@ -77,8 +77,10 @@ export function ReportDelivery(props: ReportDeliveryProps) { const defaultCreateDeliveryParams = () => { reportDefinitionRequest.delivery = { - delivery_type: DELIVERY_TYPE_OPTIONS[0].id, - delivery_params: { opensearch_dashboards_recipients: [] }, + configIds: [], + title: '', + textDescription: '', + htmlDescription: '' }; }; diff --git a/dashboards-reports/server/model/backendModel.ts b/dashboards-reports/server/model/backendModel.ts index 49dcf530..ababb662 100644 --- a/dashboards-reports/server/model/backendModel.ts +++ b/dashboards-reports/server/model/backendModel.ts @@ -92,12 +92,10 @@ export type IntervalType = { }; export type DeliveryType = { - recipients: string[]; - deliveryFormat: BACKEND_DELIVERY_FORMAT; + configIds: string[]; title: string; textDescription: string; htmlDescription?: string; - channelIds?: string[]; }; export enum BACKEND_DELIVERY_FORMAT { diff --git a/dashboards-reports/server/model/index.ts b/dashboards-reports/server/model/index.ts index d03c9925..782aac7e 100644 --- a/dashboards-reports/server/model/index.ts +++ b/dashboards-reports/server/model/index.ts @@ -187,16 +187,10 @@ export const triggerSchema = schema.object({ }); export const deliverySchema = schema.object({ - delivery_type: schema.oneOf([ - schema.literal(DELIVERY_TYPE.opensearchDashboardsUser), - schema.literal(DELIVERY_TYPE.channel), - ]), - delivery_params: schema.conditional( - schema.siblingRef('delivery_type'), - DELIVERY_TYPE.opensearchDashboardsUser, - opensearchDashboardsUserSchema, - channelSchema - ), + configIds: schema.arrayOf(schema.string()), + title: schema.string(), + textDescription: schema.string(), + htmlDescription: schema.string() }); export const reportParamsSchema = schema.object({ diff --git a/dashboards-reports/server/routes/reportDefinition.ts b/dashboards-reports/server/routes/reportDefinition.ts index a753eddc..c4e0d2c4 100644 --- a/dashboards-reports/server/routes/reportDefinition.ts +++ b/dashboards-reports/server/routes/reportDefinition.ts @@ -181,13 +181,11 @@ export default function (router: IRouter, accessInfo: AccessInfoType) { fromIndex: number; maxItems: number; }; - try { // @ts-ignore const opensearchReportsClient: ILegacyScopedClusterClient = context.reporting_plugin.opensearchReportsClient.asScoped( request ); - const opensearchResp = await opensearchReportsClient.callAsCurrentUser( 'opensearch_reports.getReportDefinitions', { @@ -195,12 +193,10 @@ export default function (router: IRouter, accessInfo: AccessInfoType) { maxItems: maxItems || DEFAULT_MAX_SIZE, } ); - const reportDefinitionsList = backendToUiReportDefinitionsList( opensearchResp.reportDefinitionDetailsList, basePath ); - return response.ok({ body: { data: reportDefinitionsList, diff --git a/dashboards-reports/server/routes/utils/__tests__/savedSearchReportHelper.test.ts b/dashboards-reports/server/routes/utils/__tests__/savedSearchReportHelper.test.ts index 26600fff..6d3b7377 100644 --- a/dashboards-reports/server/routes/utils/__tests__/savedSearchReportHelper.test.ts +++ b/dashboards-reports/server/routes/utils/__tests__/savedSearchReportHelper.test.ts @@ -51,10 +51,10 @@ const input = { }, }, delivery: { - delivery_type: 'OpenSearch Dashboards user', - delivery_params: { - opensearch_dashboards_recipients: [], - }, + configIds: [], + title: 'title', + textDescription: 'text description', + htmlDescription: 'html description' }, trigger: { trigger_type: 'On demand', diff --git a/dashboards-reports/server/routes/utils/__tests__/visualReportHelper.test.ts b/dashboards-reports/server/routes/utils/__tests__/visualReportHelper.test.ts index 6bf6dc6e..e4bda647 100644 --- a/dashboards-reports/server/routes/utils/__tests__/visualReportHelper.test.ts +++ b/dashboards-reports/server/routes/utils/__tests__/visualReportHelper.test.ts @@ -59,10 +59,10 @@ const input = { }, }, delivery: { - delivery_type: 'OpenSearch Dashboards user', - delivery_params: { - opensearch_dashboards_recipients: [], - }, + configIds: [], + title: 'title', + textDescription: 'text description', + htmlDescription: 'html description' }, trigger: { trigger_type: 'On demand', diff --git a/dashboards-reports/server/routes/utils/converters/__tests__/backendToUi.test.ts b/dashboards-reports/server/routes/utils/converters/__tests__/backendToUi.test.ts index 426777c2..895695d4 100644 --- a/dashboards-reports/server/routes/utils/converters/__tests__/backendToUi.test.ts +++ b/dashboards-reports/server/routes/utils/converters/__tests__/backendToUi.test.ts @@ -72,13 +72,11 @@ const input: BackendReportInstanceType = { }, }, delivery: { - recipients: ['szhongna@amazon.com'], - deliveryFormat: BACKEND_DELIVERY_FORMAT.embedded, title: 'test email subject', textDescription: '- test\n- optional\n- message', htmlDescription: '', - channelIds: [], + configIds: [], }, }, }, @@ -129,15 +127,11 @@ const output = { }, }, delivery: { - delivery_type: 'Channel', - delivery_params: { - recipients: ['szhongna@amazon.com'], - title: 'test email subject', - textDescription: '- test\n- optional\n- message', - htmlDescription: - '', - channelIds: [], - }, + title: 'test email subject', + textDescription: '- test\n- optional\n- message', + htmlDescription: + '', + configIds: [], }, time_created: 1605056426053, last_updated: 1605056426053, diff --git a/dashboards-reports/server/routes/utils/converters/backendToUi.ts b/dashboards-reports/server/routes/utils/converters/backendToUi.ts index 1799dcce..32c261cb 100644 --- a/dashboards-reports/server/routes/utils/converters/backendToUi.ts +++ b/dashboards-reports/server/routes/utils/converters/backendToUi.ts @@ -139,7 +139,6 @@ export const backendToUiReportDefinition = ( const baseUrl = getBaseUrl(sourceType, sourceId); const reportSource = getUiReportSource(sourceType); - let uiReportDefinition: ReportDefinitionSchemaType = { report_params: { report_name: name, @@ -175,7 +174,6 @@ export const backendToUiReportDefinition = ( last_updated: lastUpdatedTimeMs, status: getUiReportDefinitionStatus(isEnabled), }; - // validate to assign default values to some fields for UI model uiReportDefinition = reportDefinitionSchema.validate(uiReportDefinition); uiReportDefinition.report_params.core_params.base_url = @@ -370,20 +368,17 @@ const getUiDeliveryParams = ( delivery: DeliveryType | undefined ): DeliverySchemaType => { const opensearchDashboardsUserDeliveryParams = { - delivery_type: DELIVERY_TYPE.opensearchDashboardsUser, - delivery_params: { - opensearch_dashboards_recipients: [], - }, + configIds: [], + title: '', + textDescription: '', + htmlDescription: '' }; let params: any; if (delivery) { - const { deliveryFormat, ...rest } = delivery; + const { ...rest } = delivery; params = { - delivery_type: DELIVERY_TYPE.channel, - delivery_params: { - ...rest, - }, + ...rest }; } else { params = opensearchDashboardsUserDeliveryParams; diff --git a/dashboards-reports/server/utils/__tests__/validationHelper.test.ts b/dashboards-reports/server/utils/__tests__/validationHelper.test.ts index f8ce7a97..41ce3b49 100644 --- a/dashboards-reports/server/utils/__tests__/validationHelper.test.ts +++ b/dashboards-reports/server/utils/__tests__/validationHelper.test.ts @@ -49,10 +49,10 @@ const createReportDefinitionInput: ReportDefinitionSchemaType = { }, }, delivery: { - delivery_type: DELIVERY_TYPE.opensearchDashboardsUser, - delivery_params: { - opensearch_dashboards_recipients: [], - }, + configIds: [], + title: 'title', + textDescription: 'text description', + htmlDescription: 'html description' }, trigger: { trigger_type: TRIGGER_TYPE.onDemand, @@ -80,10 +80,10 @@ const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = { }, }, delivery: { - delivery_type: DELIVERY_TYPE.opensearchDashboardsUser, - delivery_params: { - opensearch_dashboards_recipients: [], - }, + configIds: [], + title: 'title', + textDescription: 'text description', + htmlDescription: 'html description' }, trigger: { trigger_type: TRIGGER_TYPE.onDemand, diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt index 881a2e4c..9ae412c1 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt @@ -381,15 +381,12 @@ internal data class ReportDefinition( * Report definition delivery data class */ internal data class Delivery( - val recipients: List, - val deliveryFormat: DeliveryFormat, val title: String, val textDescription: String, val htmlDescription: String?, - val channelIds: List + val configIds: List ) : ToXContentObject { internal companion object { - private const val RECIPIENTS_TAG = "recipients" private const val DELIVERY_FORMAT_TAG = "deliveryFormat" private const val TITLE_TAG = "title" private const val TEXT_DESCRIPTION_TAG = "textDescription" @@ -403,34 +400,29 @@ internal data class ReportDefinition( */ fun parse(parser: XContentParser): Delivery { var recipients: List = listOf() - var deliveryFormat: DeliveryFormat? = null var title: String? = null var textDescription: String? = null var htmlDescription: String? = null - var channelIds: List = listOf() + var configIds: List = listOf() XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser) while (XContentParser.Token.END_OBJECT != parser.nextToken()) { val fieldName = parser.currentName() parser.nextToken() when (fieldName) { - RECIPIENTS_TAG -> recipients = parser.stringList() - DELIVERY_FORMAT_TAG -> deliveryFormat = DeliveryFormat.valueOf(parser.text()) TITLE_TAG -> title = parser.text() TEXT_DESCRIPTION_TAG -> textDescription = parser.text() HTML_DESCRIPTION_TAG -> htmlDescription = parser.textOrNull() - CHANNEL_IDS_TAG -> channelIds = parser.stringList() + CHANNEL_IDS_TAG -> configIds = parser.stringList() else -> log.info("$LOG_PREFIX: Delivery Unknown field $fieldName") } } - deliveryFormat ?: throw IllegalArgumentException("$DELIVERY_FORMAT_TAG field absent") title ?: throw IllegalArgumentException("$TITLE_TAG field absent") textDescription ?: throw IllegalArgumentException("$TEXT_DESCRIPTION_TAG field absent") - return Delivery(recipients, - deliveryFormat, + return Delivery( title, textDescription, htmlDescription, - channelIds) + configIds) } } @@ -440,14 +432,12 @@ internal data class ReportDefinition( override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder { builder!! builder.startObject() - .field(RECIPIENTS_TAG, recipients) - .field(DELIVERY_FORMAT_TAG, deliveryFormat) .field(TITLE_TAG, title) .field(TEXT_DESCRIPTION_TAG, textDescription) if (htmlDescription != null) { builder.field(HTML_DESCRIPTION_TAG, htmlDescription) } - builder.field(CHANNEL_IDS_TAG, channelIds) + builder.field(CHANNEL_IDS_TAG, configIds) builder.endObject() return builder }