Skip to content

Commit

Permalink
Revert "chore: add intersect method from backend to fontend for uploa…
Browse files Browse the repository at this point in the history
…d extensions (apache#18811)"

This reverts commit 8d38675.
  • Loading branch information
sadpandajoe committed Mar 7, 2022
1 parent 593c271 commit 5d51371
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 47 deletions.
17 changes: 0 additions & 17 deletions superset-frontend/src/views/CRUD/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
getPasswordsNeeded,
getAlreadyExists,
hasTerminalValidation,
checkUploadExtensions,
} from 'src/views/CRUD/utils';

const terminalErrors = {
Expand Down Expand Up @@ -187,19 +186,3 @@ test('successfully modified rison to encode correctly', () => {
expect(rison.decode(actualEncoding)).toEqual(testObject);
});
});

test('checkUploadExtenssions should return valid upload extensions', () => {
const uploadExtensionTest = ['a', 'b', 'c'];
const randomExtension = ['a', 'c'];
const randomExtensionTwo = ['c'];
const randomExtensionThree: Array<any> = [];
expect(
checkUploadExtensions(randomExtension, uploadExtensionTest),
).toBeTruthy();
expect(
checkUploadExtensions(randomExtensionTwo, uploadExtensionTest),
).toBeTruthy();
expect(
checkUploadExtensions(randomExtensionThree, uploadExtensionTest),
).toBeFalsy();
});
12 changes: 0 additions & 12 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
css,
} from '@superset-ui/core';
import Chart from 'src/types/Chart';
import { intersection } from 'lodash';
import rison from 'rison';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { FetchDataConfig } from 'src/components/ListView';
Expand Down Expand Up @@ -410,14 +409,3 @@ export const hasTerminalValidation = (errors: Record<string, any>[]) =>
isNeedsPassword(payload) || isAlreadyExists(payload),
),
);

export const checkUploadExtensions = (
perm: Array<any> | string | undefined | boolean,
cons: Array<any>,
) => {
if (perm !== undefined) {
if (typeof perm === 'boolean') return perm;
return intersection(perm, cons).length;
}
return false;
};
2 changes: 1 addition & 1 deletion superset-frontend/src/views/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interface MenuObjectChildProps {
index?: number;
url?: string;
isFrontendRoute?: boolean;
perm?: string | Array<any> | boolean;
perm?: string | boolean;
view?: string;
}

Expand Down
6 changes: 1 addition & 5 deletions superset-frontend/src/views/components/MenuRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { useSelector } from 'react-redux';
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
import LanguagePicker from './LanguagePicker';
import DatabaseModal from '../CRUD/data/database/DatabaseModal';
import { checkUploadExtensions } from '../CRUD/utils';
import {
ExtentionConfigs,
GlobalMenuDataOptions,
Expand Down Expand Up @@ -76,7 +75,6 @@ const RightMenu = ({
CSV_EXTENSIONS,
COLUMNAR_EXTENSIONS,
EXCEL_EXTENSIONS,
ALLOWED_EXTENSIONS,
HAS_GSHEETS_INSTALLED,
} = useSelector<any, ExtentionConfigs>(state => state.common.conf);

Expand Down Expand Up @@ -190,9 +188,7 @@ const RightMenu = ({
title={menuIconAndLabel(menu)}
>
{menu.childs.map((item, idx) =>
typeof item !== 'string' &&
item.name &&
checkUploadExtensions(item.perm, ALLOWED_EXTENSIONS) ? (
typeof item !== 'string' && item.name && item.perm ? (
<>
{idx === 2 && <Menu.Divider />}
<Menu.Item key={item.name}>
Expand Down
7 changes: 3 additions & 4 deletions superset-frontend/src/views/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import { NavBarProps, MenuObjectProps } from './Menu';

export interface ExtentionConfigs {
ALLOWED_EXTENSIONS: Array<any>;
CSV_EXTENSIONS: Array<any>;
COLUMNAR_EXTENSIONS: Array<any>;
EXCEL_EXTENSIONS: Array<any>;
CSV_EXTENSIONS: boolean;
COLUMNAR_EXTENSIONS: boolean;
EXCEL_EXTENSIONS: boolean;
HAS_GSHEETS_INSTALLED: boolean;
}
export interface RightMenuProps {
Expand Down
18 changes: 10 additions & 8 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@
"GLOBAL_ASYNC_QUERIES_WEBSOCKET_URL",
"DASHBOARD_AUTO_REFRESH_MODE",
"SCHEDULED_QUERIES",
"EXCEL_EXTENSIONS",
"CSV_EXTENSIONS",
"COLUMNAR_EXTENSIONS",
"ALLOWED_EXTENSIONS",
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -351,10 +347,16 @@ def common_bootstrap_payload() -> Dict[str, Any]:
locale = str(get_locale())

# should not expose API TOKEN to frontend
frontend_config = {
k: (list(conf.get(k)) if isinstance(conf.get(k), set) else conf.get(k))
for k in FRONTEND_CONF_KEYS
}
frontend_config = {k: conf.get(k) for k in FRONTEND_CONF_KEYS}
frontend_config["EXCEL_EXTENSIONS"] = bool(
bool(conf["EXCEL_EXTENSIONS"].intersection(conf["ALLOWED_EXTENSIONS"])),
)
frontend_config["CSV_EXTENSIONS"] = bool(
bool(conf["CSV_EXTENSIONS"].intersection(conf["ALLOWED_EXTENSIONS"])),
)
frontend_config["COLUMNAR_EXTENSIONS"] = bool(
bool(conf["COLUMNAR_EXTENSIONS"].intersection(conf["ALLOWED_EXTENSIONS"])),
)

if conf.get("SLACK_API_TOKEN"):
frontend_config["ALERT_REPORTS_NOTIFICATION_METHODS"] = [
Expand Down

0 comments on commit 5d51371

Please sign in to comment.