From ea7734e95da6c8658bafd56e057103ad86082db0 Mon Sep 17 00:00:00 2001 From: "paulina.shakirova" Date: Mon, 28 Oct 2024 13:36:47 +0100 Subject: [PATCH 1/3] feat: disable buttons to try sample data or upload a file for a read-only user --- .../__snapshots__/add_data.test.tsx.snap | 144 ++++++++++++++++++ .../components/add_data/add_data.test.tsx | 23 ++- .../components/add_data/add_data.tsx | 4 + 3 files changed, 170 insertions(+), 1 deletion(-) diff --git a/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap b/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap index 9b4ecb856a303..f09fdf5a8ee9f 100644 --- a/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap +++ b/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap @@ -1,5 +1,144 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`AddData disable sample data and upload buttons for a read-only user 1`] = ` +<_EuiPageSection + aria-labelledby="homDataAdd__title" + bottomBorder={true} + className="homDataAdd" + paddingSize="xl" +> + + + +

+ +

+
+ + +

+ +

+
+ + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +`; + exports[`AddData render 1`] = ` <_EuiPageSection aria-labelledby="homDataAdd__title" @@ -47,6 +186,9 @@ exports[`AddData render 1`] = ` "navLinks": Object { "integrations": true, }, + "rulesSettings": Object { + "writeFlappingSettingsUI": true, + }, }, }, } @@ -72,6 +214,7 @@ exports[`AddData render 1`] = ` > @@ -86,6 +229,7 @@ exports[`AddData render 1`] = ` > diff --git a/src/plugins/home/public/application/components/add_data/add_data.test.tsx b/src/plugins/home/public/application/components/add_data/add_data.test.tsx index 83ae07a4dabaf..e2620a3d9d55a 100644 --- a/src/plugins/home/public/application/components/add_data/add_data.test.tsx +++ b/src/plugins/home/public/application/components/add_data/add_data.test.tsx @@ -29,7 +29,17 @@ beforeEach(() => { }); const applicationStartMock = { - capabilities: { navLinks: { integrations: true } }, + capabilities: { + navLinks: { integrations: true }, + rulesSettings: { writeFlappingSettingsUI: true }, + }, +} as unknown as ApplicationStart; + +const applicationStartMockRestricted = { + capabilities: { + navLinks: { integrations: true }, + rulesSettings: { writeFlappingSettingsUI: false }, + }, } as unknown as ApplicationStart; const addBasePathMock = jest.fn((path: string) => (path ? path : 'path')); @@ -46,4 +56,15 @@ describe('AddData', () => { ); expect(component).toMatchSnapshot(); }); + test('disable sample data and upload buttons for a read-only user', () => { + const component = shallowWithIntl( + + ); + expect(component).toMatchSnapshot(); + }); }); diff --git a/src/plugins/home/public/application/components/add_data/add_data.tsx b/src/plugins/home/public/application/components/add_data/add_data.tsx index 5a041c4879915..2a11034f4a5d0 100644 --- a/src/plugins/home/public/application/components/add_data/add_data.tsx +++ b/src/plugins/home/public/application/components/add_data/add_data.tsx @@ -38,6 +38,8 @@ interface Props { export const AddData: FC = ({ addBasePath, application, isDarkMode, isCloudEnabled }) => { const { trackUiMetric, guidedOnboardingService } = getServices(); const canAccessIntegrations = application.capabilities.navLinks.integrations; + const onlyReadAccess = !application.capabilities.rulesSettings.writeFlappingSettingsUI; + if (canAccessIntegrations) { return ( = ({ addBasePath, application, isDarkMode, isClo data-test-subj="addSampleData" href={addBasePath('#/tutorial_directory/sampleData')} iconType="documents" + disabled={onlyReadAccess} > = ({ addBasePath, application, isDarkMode, isClo data-test-subj="uploadFile" href={addBasePath('#/tutorial_directory/fileDataViz')} iconType="importAction" + disabled={onlyReadAccess} > Date: Mon, 28 Oct 2024 17:00:03 +0100 Subject: [PATCH 2/3] switch to using application.capabilities.roles.save --- .../add_data/__snapshots__/add_data.test.tsx.snap | 8 ++++---- .../application/components/add_data/add_data.test.tsx | 4 ++-- .../public/application/components/add_data/add_data.tsx | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap b/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap index f09fdf5a8ee9f..d48fdc9450537 100644 --- a/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap +++ b/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap @@ -47,8 +47,8 @@ exports[`AddData disable sample data and upload buttons for a read-only user 1`] "navLinks": Object { "integrations": true, }, - "rulesSettings": Object { - "writeFlappingSettingsUI": false, + "roles": Object { + "save": false, }, }, }, @@ -186,8 +186,8 @@ exports[`AddData render 1`] = ` "navLinks": Object { "integrations": true, }, - "rulesSettings": Object { - "writeFlappingSettingsUI": true, + "roles": Object { + "save": true, }, }, }, diff --git a/src/plugins/home/public/application/components/add_data/add_data.test.tsx b/src/plugins/home/public/application/components/add_data/add_data.test.tsx index e2620a3d9d55a..8afb7a521044f 100644 --- a/src/plugins/home/public/application/components/add_data/add_data.test.tsx +++ b/src/plugins/home/public/application/components/add_data/add_data.test.tsx @@ -31,14 +31,14 @@ beforeEach(() => { const applicationStartMock = { capabilities: { navLinks: { integrations: true }, - rulesSettings: { writeFlappingSettingsUI: true }, + roles: { save: true }, }, } as unknown as ApplicationStart; const applicationStartMockRestricted = { capabilities: { navLinks: { integrations: true }, - rulesSettings: { writeFlappingSettingsUI: false }, + roles: { save: false }, }, } as unknown as ApplicationStart; diff --git a/src/plugins/home/public/application/components/add_data/add_data.tsx b/src/plugins/home/public/application/components/add_data/add_data.tsx index 2a11034f4a5d0..f88e1368204c9 100644 --- a/src/plugins/home/public/application/components/add_data/add_data.tsx +++ b/src/plugins/home/public/application/components/add_data/add_data.tsx @@ -38,7 +38,7 @@ interface Props { export const AddData: FC = ({ addBasePath, application, isDarkMode, isCloudEnabled }) => { const { trackUiMetric, guidedOnboardingService } = getServices(); const canAccessIntegrations = application.capabilities.navLinks.integrations; - const onlyReadAccess = !application.capabilities.rulesSettings.writeFlappingSettingsUI; + const onlyReadAccess = !application.capabilities.roles.save; if (canAccessIntegrations) { return ( From d60626e0cb8006f8b14d1934a1a0def08dc9ab5a Mon Sep 17 00:00:00 2001 From: "paulina.shakirova" Date: Mon, 28 Oct 2024 17:30:41 +0100 Subject: [PATCH 3/3] replace to use savedObjectsManagement --- .../add_data/__snapshots__/add_data.test.tsx.snap | 8 ++++---- .../application/components/add_data/add_data.test.tsx | 4 ++-- .../public/application/components/add_data/add_data.tsx | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap b/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap index d48fdc9450537..0a3a83813bf52 100644 --- a/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap +++ b/src/plugins/home/public/application/components/add_data/__snapshots__/add_data.test.tsx.snap @@ -47,8 +47,8 @@ exports[`AddData disable sample data and upload buttons for a read-only user 1`] "navLinks": Object { "integrations": true, }, - "roles": Object { - "save": false, + "savedObjectsManagement": Object { + "edit": false, }, }, }, @@ -186,8 +186,8 @@ exports[`AddData render 1`] = ` "navLinks": Object { "integrations": true, }, - "roles": Object { - "save": true, + "savedObjectsManagement": Object { + "edit": true, }, }, }, diff --git a/src/plugins/home/public/application/components/add_data/add_data.test.tsx b/src/plugins/home/public/application/components/add_data/add_data.test.tsx index 8afb7a521044f..8631cb520640b 100644 --- a/src/plugins/home/public/application/components/add_data/add_data.test.tsx +++ b/src/plugins/home/public/application/components/add_data/add_data.test.tsx @@ -31,14 +31,14 @@ beforeEach(() => { const applicationStartMock = { capabilities: { navLinks: { integrations: true }, - roles: { save: true }, + savedObjectsManagement: { edit: true }, }, } as unknown as ApplicationStart; const applicationStartMockRestricted = { capabilities: { navLinks: { integrations: true }, - roles: { save: false }, + savedObjectsManagement: { edit: false }, }, } as unknown as ApplicationStart; diff --git a/src/plugins/home/public/application/components/add_data/add_data.tsx b/src/plugins/home/public/application/components/add_data/add_data.tsx index f88e1368204c9..81b7bd411fc2a 100644 --- a/src/plugins/home/public/application/components/add_data/add_data.tsx +++ b/src/plugins/home/public/application/components/add_data/add_data.tsx @@ -38,7 +38,7 @@ interface Props { export const AddData: FC = ({ addBasePath, application, isDarkMode, isCloudEnabled }) => { const { trackUiMetric, guidedOnboardingService } = getServices(); const canAccessIntegrations = application.capabilities.navLinks.integrations; - const onlyReadAccess = !application.capabilities.roles.save; + const onlyReadAccess = !application.capabilities.savedObjectsManagement.edit; if (canAccessIntegrations) { return (