This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 73429c6b2a fix(dashboard): show correct roles for dashboard access
dropdown (#21549)
73429c6b2a is described below
commit 73429c6b2a63edc5a119eceafebdae2bc7431cd4
Author: Mayur <[email protected]>
AuthorDate: Mon Sep 26 19:53:38 2022 +0530
fix(dashboard): show correct roles for dashboard access dropdown (#21549)
---
.../PropertiesModal/PropertiesModal.test.tsx | 179 +++++++++++++++++----
.../dashboard/components/PropertiesModal/index.tsx | 4 +-
2 files changed, 149 insertions(+), 34 deletions(-)
diff --git
a/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx
b/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx
index bffe9f3de6..8b09a57d54 100644
---
a/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx
+++
b/superset-frontend/src/dashboard/components/PropertiesModal/PropertiesModal.test.tsx
@@ -38,7 +38,7 @@ spyColorSchemeControlWrapper.mockImplementation(
);
fetchMock.get(
- 'http://localhost/api/v1/dashboard/related/roles?q=(filter:%27%27)',
+
'http://localhost/api/v1/dashboard/related/roles?q=(filter:%27%27,page:0,page_size:100)',
{
body: {
count: 6,
@@ -46,26 +46,32 @@ fetchMock.get(
{
text: 'Admin',
value: 1,
+ extra: {},
},
{
text: 'Alpha',
value: 3,
+ extra: {},
},
{
text: 'Gamma',
value: 4,
+ extra: {},
},
{
text: 'granter',
value: 5,
+ extra: {},
},
{
text: 'Public',
value: 2,
+ extra: {},
},
{
text: 'sql_lab',
value: 6,
+ extra: {},
},
],
},
@@ -73,7 +79,7 @@ fetchMock.get(
);
fetchMock.get(
- 'http://localhost/api/v1/dashboard/related/owners?q=(filter:%27%27)',
+
'http://localhost/api/v1/dashboard/related/owners?q=(filter:%27%27,page:0,page_size:100)',
{
body: {
count: 1,
@@ -81,45 +87,53 @@ fetchMock.get(
{
text: 'Superset Admin',
value: 1,
+ extra: { active: true },
+ },
+ {
+ text: 'Inactive Admin',
+ value: 2,
+ extra: { active: false },
},
],
},
},
);
+const dashboardInfo = {
+ certified_by: 'John Doe',
+ certification_details: 'Sample certification',
+ changed_by: null,
+ changed_by_name: '',
+ changed_by_url: '',
+ changed_on: '2021-03-30T19:30:14.020942',
+ charts: [
+ 'Vaccine Candidates per Country & Stage',
+ 'Vaccine Candidates per Country',
+ 'Vaccine Candidates per Country',
+ 'Vaccine Candidates per Approach & Stage',
+ 'Vaccine Candidates per Phase',
+ 'Vaccine Candidates per Phase',
+ 'Vaccine Candidates per Country & Stage',
+ 'Filtering Vaccines',
+ ],
+ css: '',
+ dashboard_title: 'COVID Vaccine Dashboard',
+ id: 26,
+ metadata: mockedJsonMetadata,
+ owners: [],
+ position_json:
+ '{"CHART-63bEuxjDMJ": {"children": [], "id": "CHART-63bEuxjDMJ", "meta":
{"chartId": 369, "height": 76, "sliceName": "Vaccine Candidates per Country",
"sliceNameOverride": "Map of Vaccine Candidates", "uuid":
"ddc91df6-fb40-4826-bdca-16b85af1c024", "width": 7}, "parents": ["ROOT_ID",
"TABS-wUKya7eQ0Z", "TAB-BCIJF4NvgQ", "ROW-zvw7luvEL"], "type": "CHART"},
"CHART-F-fkth0Dnv": {"children": [], "id": "CHART-F-fkth0Dnv", "meta":
{"chartId": 314, "height": 76, "sliceName": "Vaccine Candid [...]
+ published: false,
+ roles: [],
+ slug: null,
+ thumbnail_url:
+ '/api/v1/dashboard/26/thumbnail/b24805e98d90116da8c0974d24f5c533/',
+ url: '/superset/dashboard/26/',
+};
+
fetchMock.get('glob:*/api/v1/dashboard/26', {
body: {
- result: {
- certified_by: 'John Doe',
- certification_details: 'Sample certification',
- changed_by: null,
- changed_by_name: '',
- changed_by_url: '',
- changed_on: '2021-03-30T19:30:14.020942',
- charts: [
- 'Vaccine Candidates per Country & Stage',
- 'Vaccine Candidates per Country',
- 'Vaccine Candidates per Country',
- 'Vaccine Candidates per Approach & Stage',
- 'Vaccine Candidates per Phase',
- 'Vaccine Candidates per Phase',
- 'Vaccine Candidates per Country & Stage',
- 'Filtering Vaccines',
- ],
- css: '',
- dashboard_title: 'COVID Vaccine Dashboard',
- id: 26,
- json_metadata: mockedJsonMetadata,
- owners: [],
- position_json:
- '{"CHART-63bEuxjDMJ": {"children": [], "id": "CHART-63bEuxjDMJ",
"meta": {"chartId": 369, "height": 76, "sliceName": "Vaccine Candidates per
Country", "sliceNameOverride": "Map of Vaccine Candidates", "uuid":
"ddc91df6-fb40-4826-bdca-16b85af1c024", "width": 7}, "parents": ["ROOT_ID",
"TABS-wUKya7eQ0Z", "TAB-BCIJF4NvgQ", "ROW-zvw7luvEL"], "type": "CHART"},
"CHART-F-fkth0Dnv": {"children": [], "id": "CHART-F-fkth0Dnv", "meta":
{"chartId": 314, "height": 76, "sliceName": "Vaccine Ca [...]
- published: false,
- roles: [],
- slug: null,
- thumbnail_url:
- '/api/v1/dashboard/26/thumbnail/b24805e98d90116da8c0974d24f5c533/',
- url: '/superset/dashboard/26/',
- },
+ result: { ...dashboardInfo, json_metadata: mockedJsonMetadata },
},
});
@@ -347,3 +361,102 @@ test('Empty "Certified by" should clear "Certification
details"', async () => {
screen.getByRole('textbox', { name: 'Certification details' }),
).toHaveValue('');
});
+
+test('should show all roles', async () => {
+ spyIsFeatureEnabled.mockReturnValue(true);
+
+ const props = createProps();
+ const propsWithDashboardIndo = { ...props, dashboardInfo };
+
+ const open = () => waitFor(() => userEvent.click(getSelect()));
+ const getSelect = () =>
+ screen.getByRole('combobox', { name: SupersetCore.t('Roles') });
+
+ const getElementsByClassName = (className: string) =>
+ document.querySelectorAll(className)! as NodeListOf<HTMLElement>;
+
+ const findAllSelectOptions = () =>
+ waitFor(() => getElementsByClassName('.ant-select-item-option-content'));
+
+ render(<PropertiesModal {...propsWithDashboardIndo} />, {
+ useRedux: true,
+ });
+
+ expect(screen.getAllByRole('combobox')).toHaveLength(2);
+ expect(
+ screen.getByRole('combobox', { name: SupersetCore.t('Roles') }),
+ ).toBeInTheDocument();
+
+ await open();
+
+ const options = await findAllSelectOptions();
+
+ expect(options).toHaveLength(6);
+ expect(options[0]).toHaveTextContent('Admin');
+});
+
+test('should show active owners with dashboard rbac', async () => {
+ spyIsFeatureEnabled.mockReturnValue(true);
+
+ const props = createProps();
+ const propsWithDashboardIndo = { ...props, dashboardInfo };
+
+ const open = () => waitFor(() => userEvent.click(getSelect()));
+ const getSelect = () =>
+ screen.getByRole('combobox', { name: SupersetCore.t('Owners') });
+
+ const getElementsByClassName = (className: string) =>
+ document.querySelectorAll(className)! as NodeListOf<HTMLElement>;
+
+ const findAllSelectOptions = () =>
+ waitFor(() => getElementsByClassName('.ant-select-item-option-content'));
+
+ render(<PropertiesModal {...propsWithDashboardIndo} />, {
+ useRedux: true,
+ });
+
+ expect(screen.getAllByRole('combobox')).toHaveLength(2);
+ expect(
+ screen.getByRole('combobox', { name: SupersetCore.t('Owners') }),
+ ).toBeInTheDocument();
+
+ await open();
+
+ const options = await findAllSelectOptions();
+
+ expect(options).toHaveLength(1);
+ expect(options[0]).toHaveTextContent('Superset Admin');
+});
+
+test('should show active owners without dashboard rbac', async () => {
+ spyIsFeatureEnabled.mockReturnValue(false);
+
+ const props = createProps();
+ const propsWithDashboardIndo = { ...props, dashboardInfo };
+
+ const open = () => waitFor(() => userEvent.click(getSelect()));
+ const getSelect = () =>
+ screen.getByRole('combobox', { name: SupersetCore.t('Owners') });
+
+ const getElementsByClassName = (className: string) =>
+ document.querySelectorAll(className)! as NodeListOf<HTMLElement>;
+
+ const findAllSelectOptions = () =>
+ waitFor(() => getElementsByClassName('.ant-select-item-option-content'));
+
+ render(<PropertiesModal {...propsWithDashboardIndo} />, {
+ useRedux: true,
+ });
+
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
+ expect(
+ screen.getByRole('combobox', { name: SupersetCore.t('Owners') }),
+ ).toBeInTheDocument();
+
+ await open();
+
+ const options = await findAllSelectOptions();
+
+ expect(options).toHaveLength(1);
+ expect(options[0]).toHaveTextContent('Superset Admin');
+});
diff --git
a/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
b/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
index f015612d2a..302931a38c 100644
--- a/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
+++ b/superset-frontend/src/dashboard/components/PropertiesModal/index.tsx
@@ -133,7 +133,9 @@ const PropertiesModal = ({
endpoint: `/api/v1/dashboard/related/${accessType}?q=${query}`,
}).then(response => ({
data: response.json.result
- .filter((item: { extra: { active: boolean } }) => item.extra.active)
+ .filter((item: { extra: { active: boolean } }) =>
+ item.extra.active !== undefined ? item.extra.active : true,
+ )
.map((item: { value: number; text: string }) => ({
value: item.value,
label: item.text,