From 144ee35421f59e03db6c8e619d1bae2e79225aef Mon Sep 17 00:00:00 2001 From: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Date: Fri, 17 Jan 2020 14:32:17 +0530 Subject: [PATCH] handle uncategorized types in permission builder (close #3603) (#3712) --- .../PermissionBuilder/utils.js | 171 ++++++++++-------- 1 file changed, 97 insertions(+), 74 deletions(-) diff --git a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js index 056a70e71fc6b5..528d513547b63a 100644 --- a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js +++ b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js @@ -27,173 +27,192 @@ export const PGTypes = { 'double precision', ], uuid: ['uuid'], + user_defined: [], // default for all other types +}; + +const operatorTypePGTypesMap = { + comparision: [ + 'boolean', + 'character', + 'dateTime', + 'numeric', + 'uuid', + 'user_defined', + ], + pattern_match: ['character'], + json: ['json'], + geometric: ['geometry'], + geometric_geographic: ['geometry', 'geography'], }; const boolOperatorsInfo = { _and: { - type: 'array', + type: 'bool', + inputStructure: 'array', }, _or: { - type: 'array', + type: 'bool', + inputStructure: 'array', }, _not: { - type: 'object', + type: 'bool', + inputStructure: 'object', }, }; const columnOperatorsInfo = { _eq: { - type: 'object', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'object', }, _ne: { - type: 'object', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'object', }, _in: { - type: 'array', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'array', }, _nin: { - type: 'array', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'array', }, _gt: { - type: 'object', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'object', }, _lt: { - type: 'object', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'object', }, _gte: { - type: 'object', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'object', }, _lte: { - type: 'object', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], + type: 'comparision', + inputStructure: 'object', }, _is_null: { - type: 'object', + type: 'comparision', + inputStructure: 'object', inputType: 'boolean', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], }, _ceq: { - type: 'object', + type: 'comparision', + inputStructure: 'object', inputType: 'column', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], }, _cne: { - type: 'object', + type: 'comparision', + inputStructure: 'object', inputType: 'column', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], }, _cgt: { - type: 'object', + type: 'comparision', + inputStructure: 'object', inputType: 'column', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], }, _clt: { - type: 'object', + type: 'comparision', + inputStructure: 'object', inputType: 'column', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], }, _cgte: { - type: 'object', + type: 'comparision', + inputStructure: 'object', inputType: 'column', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], }, _clte: { - type: 'object', + type: 'comparision', + inputStructure: 'object', inputType: 'column', - PGTypes: ['boolean', 'character', 'dateTime', 'numeric', 'uuid'], }, _like: { - type: 'object', - PGTypes: ['character'], + type: 'pattern_match', + inputStructure: 'object', }, _nlike: { - type: 'object', - PGTypes: ['character'], + type: 'pattern_match', + inputStructure: 'object', }, _ilike: { - type: 'object', - PGTypes: ['character'], + type: 'pattern_match', + inputStructure: 'object', }, _nilike: { - type: 'object', - PGTypes: ['character'], + type: 'pattern_match', + inputStructure: 'object', }, _similar: { - type: 'object', - PGTypes: ['character'], + type: 'pattern_match', + inputStructure: 'object', }, _nsimilar: { - type: 'object', - PGTypes: ['character'], + type: 'pattern_match', + inputStructure: 'object', }, _contains: { - type: 'object', - PGTypes: ['json'], + type: 'json', + inputStructure: 'object', }, _contained_in: { - type: 'object', - PGTypes: ['json'], + type: 'json', + inputStructure: 'object', }, _has_key: { - type: 'object', + type: 'json', + inputStructure: 'object', inputType: 'character', - PGTypes: ['json'], }, _has_keys_any: { - type: 'array', + type: 'json', + inputStructure: 'array', inputType: 'character', - PGTypes: ['json'], }, _has_keys_all: { - type: 'array', + type: 'json', + inputStructure: 'array', inputType: 'character', - PGTypes: ['json'], }, _st_contains: { - type: 'object', - PGTypes: ['geometry'], + type: 'geometric', + inputStructure: 'object', }, _st_crosses: { - type: 'object', + type: 'geometric', + inputStructure: 'object', inputType: 'json', - PGTypes: ['geometry'], }, _st_equals: { - type: 'object', + type: 'geometric', + inputStructure: 'object', inputType: 'json', - PGTypes: ['geometry'], }, _st_overlaps: { - type: 'object', + type: 'geometric', + inputStructure: 'object', inputType: 'json', - PGTypes: ['geometry'], }, _st_touches: { - type: 'object', + type: 'geometric', + inputStructure: 'object', inputType: 'json', - PGTypes: ['geometry'], }, _st_within: { - type: 'object', + type: 'geometric', + inputStructure: 'object', inputType: 'json', - PGTypes: ['geometry'], }, _st_d_within: { - type: 'object', + type: 'geometric_geographic', + inputStructure: 'object', inputType: 'json', - PGTypes: ['geometry', 'geography'], }, _st_intersects: { - type: 'object', + type: 'geometric_geographic', + inputStructure: 'object', inputType: 'json', - PGTypes: ['geometry', 'geography'], }, }; @@ -201,7 +220,7 @@ const getPGTypesOperators = () => { const _PGTypesOperators = {}; Object.keys(columnOperatorsInfo).forEach(op => { - columnOperatorsInfo[op].PGTypes.forEach(type => { + operatorTypePGTypesMap[columnOperatorsInfo[op].type].forEach(type => { _PGTypesOperators[type] = _PGTypesOperators[type] || []; _PGTypesOperators[type].push(op); }); @@ -237,7 +256,7 @@ export const isExistOperator = operator => { export const isArrayBoolOperator = operator => { const arrayBoolOperators = Object.keys(boolOperatorsInfo).filter( - op => boolOperatorsInfo[op].type === 'array' + op => boolOperatorsInfo[op].inputStructure === 'array' ); return arrayBoolOperators.includes(operator); @@ -249,7 +268,7 @@ export const isColumnOperator = operator => { export const isArrayColumnOperator = operator => { const arrayColumnOperators = Object.keys(columnOperatorsInfo).filter( - op => columnOperatorsInfo[op].type === 'array' + op => columnOperatorsInfo[op].inputStructure === 'array' ); return arrayColumnOperators.includes(operator); @@ -271,6 +290,10 @@ export const getRootPGType = type => { } } + if (!rootType) { + rootType = 'user_defined'; + } + return rootType; };