From 457539bfd4ed344454473b555d513ceef8eb906e Mon Sep 17 00:00:00 2001 From: David Cui <53581635+davidcui-amzn@users.noreply.github.com> Date: Mon, 10 May 2021 10:30:42 -0700 Subject: [PATCH] Use output_only Parameter for notebook reports (#32) Signed-off-by: David Cui --- .../report_settings_helpers.tsx | 6 ++-- server/model/backendModel.ts | 2 +- .../utils/__tests__/validationHelper.test.ts | 35 +++++++++++++++++++ server/utils/validationHelper.ts | 9 +++-- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/public/components/report_definitions/report_settings/report_settings_helpers.tsx b/public/components/report_definitions/report_settings/report_settings_helpers.tsx index e3ff2a80..9056623a 100644 --- a/public/components/report_definitions/report_settings/report_settings_helpers.tsx +++ b/public/components/report_definitions/report_settings/report_settings_helpers.tsx @@ -120,19 +120,19 @@ export const getNotebooksBaseUrlCreate = ( if (!fromInContext) { baseUrl = location.pathname + location.hash; } else { - baseUrl = '/app/notebooks-dashboards#/'; + baseUrl = '/app/notebooks-dashboards?view=output_only#/'; } if (edit) { return baseUrl.replace( `reports-dashboards#/edit/${editDefinitionId}`, - 'notebooks-dashboards#/' + 'notebooks-dashboards?view=output_only#/' ); } else if (fromInContext) { return baseUrl; } return baseUrl.replace( 'reports-dashboards#/create', - 'notebooks-dashboards#/' + 'notebooks-dashboards?view=output_only#/' ); } diff --git a/server/model/backendModel.ts b/server/model/backendModel.ts index 674eaf74..49dcf530 100644 --- a/server/model/backendModel.ts +++ b/server/model/backendModel.ts @@ -168,5 +168,5 @@ export const URL_PREFIX_DICT = { [BACKEND_REPORT_SOURCE.dashboard]: '/app/dashboards#/view/', [BACKEND_REPORT_SOURCE.savedSearch]: '/app/discover#/view/', [BACKEND_REPORT_SOURCE.visualization]: '/app/visualize#/edit/', - [BACKEND_REPORT_SOURCE.notebook]: '/app/notebooks-dashboards#/' + [BACKEND_REPORT_SOURCE.notebook]: '/app/notebooks-dashboards?view=output_only#/' }; diff --git a/server/utils/__tests__/validationHelper.test.ts b/server/utils/__tests__/validationHelper.test.ts index 106ed301..f8ce7a97 100644 --- a/server/utils/__tests__/validationHelper.test.ts +++ b/server/utils/__tests__/validationHelper.test.ts @@ -65,6 +65,31 @@ const createReportInput: ReportSchemaType = { report_definition: createReportDefinitionInput, }; +const createReportDefinitionNotebookInput: ReportDefinitionSchemaType = { + report_params: { + report_name: 'test notebooks report', + report_source: REPORT_TYPE.notebook, + description: 'Hi this is your Notebook on demand', + core_params: { + base_url: `/app/notebooks-dashboards?view=output_only#/${SAMPLE_SAVED_OBJECT_ID}`, + window_width: 1300, + window_height: 900, + report_format: FORMAT.pdf, + time_duration: 'PT5M', + origin: 'http://localhost:5601', + }, + }, + delivery: { + delivery_type: DELIVERY_TYPE.opensearchDashboardsUser, + delivery_params: { + opensearch_dashboards_recipients: [], + }, + }, + trigger: { + trigger_type: TRIGGER_TYPE.onDemand, + }, +} + describe('test input validation', () => { test('create report with correct saved object id', async () => { const savedObjectIds = [`dashboard:${SAMPLE_SAVED_OBJECT_ID}`]; @@ -93,6 +118,16 @@ describe('test input validation', () => { expect(report).toBeDefined(); }); + test('create notebook report definition with correct base url format', async () => { + const savedObjectIds = [`notebook:${SAMPLE_SAVED_OBJECT_ID}`]; + const client = mockOpenSearchClient(savedObjectIds); + const report = await validateReportDefinition( + client, + createReportDefinitionNotebookInput + ); + expect(report).toBeDefined(); + }); + test('create report definition with non-exist saved object id', async () => { const savedObjectIds = ['dashboard:fake-id']; const client = mockOpenSearchClient(savedObjectIds); diff --git a/server/utils/validationHelper.ts b/server/utils/validationHelper.ts index 937ce150..387f9d0a 100644 --- a/server/utils/validationHelper.ts +++ b/server/utils/validationHelper.ts @@ -36,12 +36,15 @@ import { import { REPORT_TYPE } from '../../server/routes/utils/constants'; export const isValidRelativeUrl = (relativeUrl: string) => { - const normalizedRelativeUrl = path.posix.normalize(relativeUrl); + let normalizedRelativeUrl = relativeUrl + if (!relativeUrl.includes('notebooks-dashboards')) { + normalizedRelativeUrl = path.posix.normalize(relativeUrl); + } + // check pattern // ODFE pattern: /app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g // AES pattern: /_plugin/kibana/app/dashboards#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g const isValid = regexRelativeUrl.test(normalizedRelativeUrl); - return isValid; }; @@ -52,7 +55,7 @@ export const isValidRelativeUrl = (relativeUrl: string) => { export const regexDuration = /^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/; export const regexEmailAddress = /\S+@\S+\.\S+/; export const regexReportName = /^[\w\-\s\(\)\[\]\,\_\-+]+$/; -export const regexRelativeUrl = /^\/(_plugin\/kibana\/app|app)\/(dashboards|visualize|discover|notebooks-dashboards)(\?security_tenant=.+|)#\/(view\/|edit\/)?[^\/]+$/; +export const regexRelativeUrl = /^\/(_plugin\/kibana\/app|app)\/(dashboards|visualize|discover|notebooks-dashboards\?view=output_only)(\?security_tenant=.+|)#\/(view\/|edit\/)?[^\/]+$/; export const validateReport = async ( client: ILegacyScopedClusterClient,