mirror of https://github.com/apache/superset.git
fix: roles undefined on public dashboards (#14648)
This commit is contained in:
parent
ba5d66cb0a
commit
884ded0507
|
@ -132,6 +132,13 @@ describe('canUserEditDashboard', () => {
|
|||
it('rejects nonexistent users', () => {
|
||||
expect(canUserEditDashboard(dashboard, null)).toEqual(false);
|
||||
});
|
||||
it('rejects missing roles', () => {
|
||||
// in redux, when there is no user, the user is actually set to an empty object,
|
||||
// so we need to handle missing roles as well as a missing user.s
|
||||
expect(
|
||||
canUserEditDashboard(dashboard, {} as UserWithPermissionsAndRoles),
|
||||
).toEqual(false);
|
||||
});
|
||||
it('rejects "admins" if the admin role does not have edit rights for some reason', () => {
|
||||
expect(
|
||||
canUserEditDashboard(dashboard, {
|
||||
|
|
|
@ -48,6 +48,6 @@ export const canUserEditDashboard = (
|
|||
dashboard: Dashboard,
|
||||
user?: UserWithPermissionsAndRoles | null,
|
||||
) =>
|
||||
!!user &&
|
||||
!!user?.roles &&
|
||||
(isUserAdmin(user) || isUserDashboardOwner(dashboard, user)) &&
|
||||
findPermission('can_write', 'Dashboard', user.roles);
|
||||
|
|
Loading…
Reference in New Issue