diff --git a/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.test.tsx b/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.test.tsx index d978bd2bb8..af524a6b1e 100644 --- a/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.test.tsx +++ b/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.test.tsx @@ -49,6 +49,39 @@ const stateWithOnlyUser = { reports: {}, }; +const stateWithNonAdminUser = { + user: { + email: 'nonadmin@test.com', + firstName: 'nonadmin', + isActive: true, + lastName: 'nonadmin', + permissions: {}, + createdOn: '2022-01-12T10:17:37.801361', + roles: { + Gamme: [['no_menu_access', 'Manage']], + OtherRole: [['menu_access', 'Manage']], + }, + userId: 1, + username: 'nonadmin', + }, + reports: {}, +}; + +const stateWithNonMenuAccessOnManage = { + user: { + email: 'nonaccess@test.com', + firstName: 'nonaccess', + isActive: true, + lastName: 'nonaccess', + permissions: {}, + createdOn: '2022-01-12T10:17:37.801361', + roles: { Gamma: [['no_menu_access', 'Manage']] }, + userId: 1, + username: 'nonaccess', + }, + reports: {}, +}; + const stateWithUserAndReport = { user: { email: 'admin@test.com', @@ -193,4 +226,32 @@ describe('Header Report Dropdown', () => { }); expect(screen.getByText('Set up an email report')).toBeInTheDocument(); }); + + it('renders Schedule Email Reports as long as user has permission through any role', () => { + let mockedProps = createProps(); + mockedProps = { + ...mockedProps, + useTextMenu: true, + isDropdownVisible: true, + }; + act(() => { + setup(mockedProps, stateWithNonAdminUser); + }); + expect(screen.getByText('Set up an email report')).toBeInTheDocument(); + }); + + it('do not render Schedule Email Reports if user no permission', () => { + let mockedProps = createProps(); + mockedProps = { + ...mockedProps, + useTextMenu: true, + isDropdownVisible: true, + }; + act(() => { + setup(mockedProps, stateWithNonMenuAccessOnManage); + }); + expect( + screen.queryByText('Set up an email report'), + ).not.toBeInTheDocument(); + }); }); diff --git a/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx index 368b5bbde0..92388f9f8a 100644 --- a/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx +++ b/superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx @@ -120,7 +120,7 @@ export default function HeaderReportDropDown({ perms => perms[0] === 'menu_access' && perms[1] === 'Manage', ), ); - return permissions[0].length > 0; + return permissions.some(permission => permission.length > 0); }; const [currentReportDeleting, setCurrentReportDeleting] =