Skip to content

Commit

Permalink
fix(report): Fix permission check for set up email report on charts/d…
Browse files Browse the repository at this point in the history
…ashboards. Fixes apache#21559 (apache#21561)

Co-authored-by: Rui Zhao <[email protected]>
(cherry picked from commit 7f971b4)
  • Loading branch information
zhaorui2022 authored and eschutho committed Oct 18, 2022
1 parent 9e907be commit b1c9adb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@ const stateWithOnlyUser = {
reports: {},
};

const stateWithNonAdminUser = {
user: {
email: '[email protected]',
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: '[email protected]',
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 = {
explore: {
user: {
Expand Down Expand Up @@ -195,4 +228,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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down

0 comments on commit b1c9adb

Please sign in to comment.