From 70ebf0a6d2035348d9905bdcfad9d3d83d466d1f Mon Sep 17 00:00:00 2001 From: Mayur Date: Thu, 11 Nov 2021 16:20:12 +0530 Subject: [PATCH] fix(dashboard): don't show report modal for anonymous user (#17106) * Added sunburst echart * fix(dashboard):Hide reports modal for anonymous users * Address comments * Make prettier happy Co-authored-by: Mayur --- .../HeaderReportActionsDropdown/index.tsx | 8 +++--- .../components/Header/Header.test.tsx | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx index c85262f6c6126..f558010ecd9fd 100644 --- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx +++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx @@ -60,10 +60,8 @@ export default function HeaderReportActionsDropDown({ any, UserWithPermissionsAndRoles >(state => state.user || state.explore?.user); - const [ - currentReportDeleting, - setCurrentReportDeleting, - ] = useState(null); + const [currentReportDeleting, setCurrentReportDeleting] = + useState(null); const theme = useTheme(); const [showModal, setShowModal] = useState(false); const toggleActiveKey = async (data: AlertObject, checked: boolean) => { @@ -81,7 +79,7 @@ export default function HeaderReportActionsDropDown({ if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) { return false; } - if (!user) { + if (!user?.userId) { // this is in the case that there is an anonymous user. return false; } diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 6773b0c1af2ec..29f2a7c6ededa 100644 --- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx @@ -465,4 +465,31 @@ describe('Email Report Modal', () => { // BLOCKER: I cannot get report to populate, as its data is handled through redux expect.anything(); }); + + it('Should render report header', async () => { + const mockedProps = createProps(); + render(setup(mockedProps)); + expect( + screen.getByRole('button', { name: 'Schedule email report' }), + ).toBeInTheDocument(); + }); + + it('Should not render report header even with menu access for anonymous user', async () => { + const mockedProps = createProps(); + const anonymousUserProps = { + ...mockedProps, + user: { + roles: { + Public: [['menu_access', 'Manage']], + }, + permissions: { + datasource_access: ['[examples].[birth_names](id:2)'], + }, + }, + }; + render(setup(anonymousUserProps)); + expect( + screen.queryByRole('button', { name: 'Schedule email report' }), + ).not.toBeInTheDocument(); + }); });