mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
fix(database-list): hidden upload file button if no permission (#21216)
This commit is contained in:
parent
8772e2cdb3
commit
0c43190e04
@ -96,7 +96,7 @@ fetchMock.get(
|
|||||||
const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');
|
const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');
|
||||||
const userSelectorMock = jest.spyOn(reactRedux, 'useSelector');
|
const userSelectorMock = jest.spyOn(reactRedux, 'useSelector');
|
||||||
|
|
||||||
describe('DatabaseList', () => {
|
describe('Admin DatabaseList', () => {
|
||||||
useSelectorMock.mockReturnValue({
|
useSelectorMock.mockReturnValue({
|
||||||
CSV_EXTENSIONS: ['csv'],
|
CSV_EXTENSIONS: ['csv'],
|
||||||
EXCEL_EXTENSIONS: ['xls', 'xlsx'],
|
EXCEL_EXTENSIONS: ['xls', 'xlsx'],
|
||||||
@ -212,4 +212,30 @@ describe('DatabaseList', () => {
|
|||||||
`"http://localhost/api/v1/database/?q=(filters:!((col:expose_in_sqllab,opr:eq,value:!t),(col:allow_run_async,opr:eq,value:!f),(col:database_name,opr:ct,value:fooo)),order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`,
|
`"http://localhost/api/v1/database/?q=(filters:!((col:expose_in_sqllab,opr:eq,value:!t),(col:allow_run_async,opr:eq,value:!f),(col:database_name,opr:ct,value:fooo)),order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not render dropdown menu button if user is not admin', () => {
|
||||||
|
userSelectorMock.mockReturnValue({
|
||||||
|
createdOn: '2021-05-27T18:12:38.952304',
|
||||||
|
email: 'alpha@gmail.com',
|
||||||
|
firstName: 'alpha',
|
||||||
|
isActive: true,
|
||||||
|
lastName: 'alpha',
|
||||||
|
permissions: {},
|
||||||
|
roles: {
|
||||||
|
Alpha: [
|
||||||
|
['can_sqllab', 'Superset'],
|
||||||
|
['can_write', 'Dashboard'],
|
||||||
|
['can_write', 'Chart'],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
userId: 2,
|
||||||
|
username: 'alpha',
|
||||||
|
});
|
||||||
|
const newWrapper = mount(
|
||||||
|
<Provider store={store}>
|
||||||
|
<DatabaseList />
|
||||||
|
</Provider>,
|
||||||
|
);
|
||||||
|
expect(newWrapper.find('.dropdown-menu-links')).not.toExist();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -39,6 +39,7 @@ import { commonMenuData } from 'src/views/CRUD/data/common';
|
|||||||
import handleResourceExport from 'src/utils/export';
|
import handleResourceExport from 'src/utils/export';
|
||||||
import { ExtentionConfigs } from 'src/views/components/types';
|
import { ExtentionConfigs } from 'src/views/components/types';
|
||||||
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
|
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
|
||||||
|
import type { MenuObjectProps } from 'src/views/components/Menu';
|
||||||
import DatabaseModal from './DatabaseModal';
|
import DatabaseModal from './DatabaseModal';
|
||||||
|
|
||||||
import { DatabaseObject } from './types';
|
import { DatabaseObject } from './types';
|
||||||
@ -235,11 +236,13 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
|
|||||||
|
|
||||||
useEffect(() => hasFileUploadEnabled(), [databaseModalOpen]);
|
useEffect(() => hasFileUploadEnabled(), [databaseModalOpen]);
|
||||||
|
|
||||||
const filteredDropDown = uploadDropdownMenu.map(link => {
|
const filteredDropDown = uploadDropdownMenu.reduce((prev, cur) => {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
link.childs = link.childs.filter(item => item.perm);
|
cur.childs = cur.childs.filter(item => item.perm);
|
||||||
return link;
|
if (!cur.childs.length) return prev;
|
||||||
});
|
prev.push(cur);
|
||||||
|
return prev;
|
||||||
|
}, [] as MenuObjectProps[]);
|
||||||
|
|
||||||
const menuData: SubMenuProps = {
|
const menuData: SubMenuProps = {
|
||||||
activeChild: 'Databases',
|
activeChild: 'Databases',
|
||||||
|
Loading…
Reference in New Issue
Block a user