From 8756c9089ea765454cebcb8ab76fffddb86f916a 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 --- .../components/Header/Header.test.tsx | 27 +++++++++++++++++++ .../src/dashboard/components/Header/index.jsx | 2 +- .../components/ExploreChartHeader/index.jsx | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 9e285f1c66af1..b8034bf92457d 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(); + }); }); diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx index f8ca74b8e9713..1fb26eb0cc914 100644 --- a/superset-frontend/src/dashboard/components/Header/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/index.jsx @@ -435,7 +435,7 @@ class Header extends React.PureComponent { return false; } const { user } = this.props; - if (!user) { + if (!user?.userId) { // this is in the case that there is an anonymous user. return false; } diff --git a/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx b/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx index 008ff0a5950cf..be713614a4178 100644 --- a/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx +++ b/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx @@ -227,7 +227,7 @@ export class ExploreChartHeader extends React.PureComponent { return false; } const { user } = this.props; - if (!user) { + if (!user?.userId) { // this is in the case that there is an anonymous user. return false; }