Skip to content

Commit

Permalink
fix(dashboard): don't show report modal for anonymous user (#17106)
Browse files Browse the repository at this point in the history
* Added sunburst echart

* fix(dashboard):Hide reports modal for anonymous users

* Address comments

* Make prettier happy

Co-authored-by: Mayur <mayurp@kpmg.com>
  • Loading branch information
2 people authored and AAfghahi committed Jan 10, 2022
1 parent e4ce83a commit 70ebf0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ export default function HeaderReportActionsDropDown({
any,
UserWithPermissionsAndRoles
>(state => state.user || state.explore?.user);
const [
currentReportDeleting,
setCurrentReportDeleting,
] = useState<AlertObject | null>(null);
const [currentReportDeleting, setCurrentReportDeleting] =
useState<AlertObject | null>(null);
const theme = useTheme();
const [showModal, setShowModal] = useState<boolean>(false);
const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
Expand All @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions superset-frontend/src/dashboard/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 70ebf0a

Please sign in to comment.