forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(report): Fix permission check for set up email report on charts/d…
…ashboards. Fixes apache#21559 (apache#21561) Co-authored-by: Rui Zhao <[email protected]> (cherry picked from commit 7f971b4)
- Loading branch information
1 parent
9e907be
commit b1c9adb
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: { | ||
|
@@ -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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters