handle invalid keys in permission builder (close #3848) (#3863)

* handle non-existent column names
* handle invalid _exist operator expression keys
* handle non-array values for _and/_or operators
This commit is contained in:
Rikin Kachhia 2020-02-12 14:45:26 +05:30 committed by GitHub
parent 3a07228525
commit 4b78884d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,6 +42,7 @@ import {
isJsonString,
getAllJsonPaths,
isObject,
isArray,
} from '../../../../Common/utils/jsUtils';
class PermissionBuilder extends React.Component {
@ -101,9 +102,13 @@ class PermissionBuilder extends React.Component {
_missingSchemas = findMissingSchemas(newPath, currTable);
} else if (isExistOperator(operator)) {
const existTableDef = getQualifiedTableDef(value[TABLE_KEY]);
const existTableSchema = existTableDef.schema;
const existWhere = value[WHERE_KEY];
let existTableSchema;
if (existTableDef) {
existTableSchema = existTableDef.schema;
}
const existWhere = value[WHERE_KEY] || '';
if (existTableSchema) {
const { allTableSchemas } = this.props;
@ -443,12 +448,12 @@ class PermissionBuilder extends React.Component {
);
});
const selectedValue = addToPrefix(prefix, value);
const selectedValue = addToPrefix(prefix, value || '--');
return (
<select
value={selectedValue}
name={value}
name={prefix}
onChange={dispatchSelect}
className={styles.qb_select}
data-test="qb-select"
@ -720,7 +725,9 @@ class PermissionBuilder extends React.Component {
let columnType = '';
if (tableSchema && columnName) {
const column = getTableColumn(tableSchema, columnName);
columnType = getColumnType(column);
if (column) {
columnType = getColumnType(column);
}
}
_columnExp = renderOperatorExp(
@ -818,7 +825,7 @@ class PermissionBuilder extends React.Component {
};
const unselectedElements = [];
if (!existsOpTable.name) {
if (!existsOpTable || !existsOpTable.name) {
unselectedElements.push(WHERE_KEY);
}
@ -840,6 +847,8 @@ class PermissionBuilder extends React.Component {
) => {
const _boolExpArray = [];
expressions = isArray(expressions) ? expressions : [];
expressions.concat([{}]).forEach((expression, i) => {
const _boolExp = renderBoolExp(
dispatchFunc,