mirror of
https://github.com/apache/superset.git
synced 2024-09-11 16:19:43 -04:00
fix(report): Fix permission check for set up email report on charts/dashboards. Fixes #21559 (#21561)
Co-authored-by: Rui Zhao <zhaorui@dropbox.com>
This commit is contained in:
parent
0dda5fe1cf
commit
7f971b4103
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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] =
|
||||
|
Loading…
Reference in New Issue
Block a user