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 <zhaorui@dropbox.com>
  • Loading branch information
zhaorui2022 and Rui Zhao authored Sep 29, 2022
1 parent 0dda5fe commit 7f971b4
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: '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',
Expand Down Expand Up @@ -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();
});
});
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 7f971b4

Please sign in to comment.