You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/01/05 19:57:21 UTC
[superset] 01/14: fix(database-list): hidden upload file button if no permission (#21216)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/superset.git
commit e79e2b37eee9a6d887a3ec4399f5e01231c8a853
Author: Stephen Liu <75...@qq.com>
AuthorDate: Tue Aug 30 10:34:28 2022 +0800
fix(database-list): hidden upload file button if no permission (#21216)
---
.../views/CRUD/data/database/DatabaseList.test.jsx | 28 +++++++++++++++++++++-
.../src/views/CRUD/data/database/DatabaseList.tsx | 11 +++++----
2 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseList.test.jsx b/superset-frontend/src/views/CRUD/data/database/DatabaseList.test.jsx
index 12580d8ee7..964adc64d5 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseList.test.jsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseList.test.jsx
@@ -108,7 +108,7 @@ fetchMock.get(databaseRelatedEndpoint, {
const useSelectorMock = jest.spyOn(redux, 'useSelector');
-describe('DatabaseList', () => {
+describe('Admin DatabaseList', () => {
useSelectorMock.mockReturnValue({
CSV_EXTENSIONS: ['csv'],
EXCEL_EXTENSIONS: ['xls', 'xlsx'],
@@ -207,6 +207,32 @@ 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)"`,
);
});
+
+ 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();
+ });
});
describe('RTL', () => {
diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx
index 10149bc9e8..0080cc4e91 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx
@@ -34,6 +34,7 @@ import ImportModelsModal from 'src/components/ImportModal/index';
import handleResourceExport from 'src/utils/export';
import { ExtentionConfigs } from 'src/views/components/types';
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
+import type { MenuObjectProps } from 'src/views/components/Menu';
import DatabaseModal from './DatabaseModal';
import { DatabaseObject } from './types';
@@ -217,11 +218,13 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
},
];
- const filteredDropDown = uploadDropdownMenu.map(link => {
+ const filteredDropDown = uploadDropdownMenu.reduce((prev, cur) => {
// eslint-disable-next-line no-param-reassign
- link.childs = link.childs.filter(item => item.perm);
- return link;
- });
+ cur.childs = cur.childs.filter(item => item.perm);
+ if (!cur.childs.length) return prev;
+ prev.push(cur);
+ return prev;
+ }, [] as MenuObjectProps[]);
const menuData: SubMenuProps = {
activeChild: 'Databases',