From 805d4096c0ae400e6bab078c0861a1d6f7096912 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 18:50:37 -0700 Subject: [PATCH] Hide create data source routes when data_source.manageableBy is none (#7298) (#7378) --- changelogs/fragments/7298.yml | 2 ++ .../mount_management_section.test.tsx | 33 +++++++++++++++++++ .../mount_management_section.tsx | 20 +++++++---- 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/7298.yml diff --git a/changelogs/fragments/7298.yml b/changelogs/fragments/7298.yml new file mode 100644 index 000000000000..ebe63d4ffe08 --- /dev/null +++ b/changelogs/fragments/7298.yml @@ -0,0 +1,2 @@ +feat: +- Disable certain routes when data_source.manageableBy is none ([#7298](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7298)) \ No newline at end of file diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.test.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.test.tsx index 7c4e7d812c6d..4b7bd3ab5c8b 100644 --- a/src/plugins/data_source_management/public/management_app/mount_management_section.test.tsx +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.test.tsx @@ -119,4 +119,37 @@ describe('mountManagementSection', () => { expect(route.prop('path')).not.toEqual(['/:id']); }); }); + + it('renders CreateDataSourcePanel when canManageDataSource is true', async () => { + const mockGetStartServices: StartServicesAccessor = jest + .fn() + .mockResolvedValue([ + { + chrome: { docTitle: { reset: jest.fn() } }, + application: { capabilities: { dataSource: { canManage: false } } }, + savedObjects: {}, + uiSettings: {}, + notifications: {}, + overlays: {}, + http: {}, + docLinks: {}, + }, + ]); + + await mountManagementSection(mockGetStartServices, mockParams, mockAuthMethodsRegistry, true); + const wrapper = shallow( + + + + + + + + + + + ); + + expect(wrapper.find(Route)).toHaveLength(2); + }); }); diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx index 15de75088b48..ec7f7f53fe42 100644 --- a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx @@ -49,20 +49,26 @@ export async function mountManagementSection( authenticationMethodRegistry: authMethodsRegistry, }; + const canManageDataSource = !!application.capabilities?.dataSource?.canManage; + const content = ( - - - - {featureFlagStatus && ( + {canManageDataSource && ( + + + + )} + {featureFlagStatus && canManageDataSource && ( )} - - - + {canManageDataSource && ( + + + + )} {featureFlagStatus && (