这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,30 @@ class PermissionBuilder extends React.Component {
return _tableSchemas;
};

const isNotOperator = value => {
return value === boolOperators.not;
};

const isAndOrOperator = value => {
return value === boolOperators.or || value === boolOperators.and;
};

const isArrayColumnOperator = value => {
return arrayColumnOperators.indexOf(value) !== -1;
};

const isColumnOperator = value => {
return columnOperators.indexOf(value) !== -1;
};

const getFilter = (conditions, prefix, value = '') => {
const _where = {};

const prefixSplit = prefix.split('.');
const operation = prefixSplit[0];

if (prefixSplit.length !== 1) {
if (operation === boolOperators.or || operation === boolOperators.and) {
if (isAndOrOperator(operation)) {
const position = parseInt(prefixSplit[1], 10);
_where[operation] = conditions[operation];
_where[operation][position] = getFilter(
Expand All @@ -70,13 +86,13 @@ class PermissionBuilder extends React.Component {
if (Object.keys(_where[operation][position]).length === 0) {
_where[operation].splice(position, 1);
}
} else if (operation === boolOperators.not) {
} else if (isNotOperator(operation)) {
_where[operation] = getFilter(
conditions[operation],
prefixSplit.slice(1).join('.'),
value
);
} else if (arrayColumnOperators.indexOf(operation) !== -1) {
} else if (isArrayColumnOperator(operation)) {
const position = parseInt(prefixSplit[1], 10);
_where[operation] = conditions[operation] || [];
if (value) {
Expand All @@ -95,16 +111,13 @@ class PermissionBuilder extends React.Component {
} else {
if (operation === '--') {
// blank where
} else if (
operation === boolOperators.or ||
operation === boolOperators.and
) {
} else if (isAndOrOperator(operation)) {
_where[operation] = [];
} else if (operation === boolOperators.not) {
} else if (isNotOperator(operation)) {
_where[operation] = {};
} else if (arrayColumnOperators.indexOf(operation) !== -1) {
} else if (isArrayColumnOperator(operation)) {
_where[operation] = value || [];
} else if (columnOperators.indexOf(operation) !== -1) {
} else if (isColumnOperator(operation)) {
_where[operation] = value;
// if (operation === '$eq') {
// _where = value
Expand Down Expand Up @@ -261,7 +274,7 @@ class PermissionBuilder extends React.Component {

let valueInput = '';
if (operator) {
if (arrayColumnOperators.indexOf(operator) !== -1) {
if (isArrayColumnOperator(operator)) {
valueInput = renderInputArray(
dispatchFunc,
operationValue,
Expand Down Expand Up @@ -402,15 +415,15 @@ class PermissionBuilder extends React.Component {
let boolExpValue = null;
if (operation) {
const newPrefix = addToPrefix(prefix, operation);
if (operation === boolOperators.or || operation === boolOperators.and) {
if (isAndOrOperator(operation)) {
boolExpValue = renderBoolExpArray(
dispatchFunc,
condition[operation],
table,
tableSchemas,
newPrefix
);
} else if (operation === boolOperators.not) {
} else if (isNotOperator(operation)) {
boolExpValue = renderBoolExp(
dispatchFunc,
condition[operation],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ export const columnOperators = [

export const arrayColumnOperators = ['_in', '_nin'];

export const legacyOperatorsMap = {
$and: '_and',
$or: '_or',
$not: '_not',
$eq: '_eq',
$ne: '_ne',
$in: '_in',
$nin: '_nin',
$gt: '_gt',
$lt: '_lt',
$gte: '_gte',
$lte: '_lte',
$like: '_like',
$nlike: '_nlike',
$similar: '_similar',
$nsimilar: '_nsimilar',
};

export function addToPrefix(prefix, value) {
let _newPrefix;
if (prefix !== null && prefix.toString()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import PermissionBuilder from './PermissionBuilder/PermissionBuilder';
import TableHeader from '../TableCommon/TableHeader';
import ViewHeader from '../TableBrowseRows/ViewHeader';
import { setTable } from '../DataActions';
import { getIngForm } from '../utils';
import { getIngForm, escapeRegExp } from '../utils';
import { legacyOperatorsMap } from './PermissionBuilder/utils';

class Permissions extends Component {
componentDidMount() {
Expand Down Expand Up @@ -670,6 +671,16 @@ class Permissions extends Component {
filterString = JSON.stringify(permsState[query][filterKey]);
}

// replace legacy operator values
Object.keys(legacyOperatorsMap).forEach(legacyOperator => {
const legacyString = '"' + legacyOperator + '"';
const currentString = '"' + legacyOperatorsMap[legacyOperator] + '"';
filterString = filterString.replace(
new RegExp(escapeRegExp(legacyString), 'g'),
currentString
);
});

return (
<div className={styles.editPermissionsSection}>
Allow {getIngForm(permsState.query)} <b>rows</b> for role '
Expand Down
5 changes: 5 additions & 0 deletions console/src/components/Services/Data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ const getEdForm = string => {
);
};

const escapeRegExp = string => {
return string.replace(/([.*+?^${}()|[\]\\])/g, '\\$1');
};

export {
ordinalColSort,
findTableFromRel,
findAllFromRel,
getEdForm,
getIngForm,
escapeRegExp,
};