From f2d31155551a3397f9bbe162bd25b75f611d2cd0 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Wed, 6 Feb 2019 17:18:02 +0530 Subject: [PATCH 01/18] update docs --- docs/graphql/manual/auth/basics.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/graphql/manual/auth/basics.rst b/docs/graphql/manual/auth/basics.rst index 18af232a31bfd..6e4e2931d5d07 100644 --- a/docs/graphql/manual/auth/basics.rst +++ b/docs/graphql/manual/auth/basics.rst @@ -106,7 +106,10 @@ You can notice above how the same query now only includes the right slice of dat ] } - This rule reads as: allow selecting an article if it was published after "31-12-2018" and its author is the current user. + This rule reads as: allow selecting an article if it was published after "31-12-2018" and its author is the current + user. + + **Note:** The operators ``_has_keys_all`` and ``_has_keys_any`` are currently not supported in permission rules .. _restrict_columns: From fbd4436838c63c04d9239adfc3261c17abaa65c8 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 14 Feb 2019 03:20:37 +0530 Subject: [PATCH 02/18] update console permission builder --- .../PermissionBuilder/PermissionBuilder.js | 258 ++++++++++++------ .../PermissionBuilder/utils.js | 180 +++++++++--- .../Data/TablePermissions/Permissions.js | 9 +- 3 files changed, 316 insertions(+), 131 deletions(-) diff --git a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/PermissionBuilder.js b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/PermissionBuilder.js index f513b38084062..111b77189680a 100644 --- a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/PermissionBuilder.js +++ b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/PermissionBuilder.js @@ -11,14 +11,21 @@ import { getTableRelationship, getTableDef, getTableSchema, + getColumnType, + isJsonString, getAllJsonPaths, isNotOperator, isAndOrOperator, isColumnOperator, - isBoolColumnOperator, - isArrayColumnOperator, + isBoolTypeColumnOperator, + isArrayTypeColumnOperator, + isJsonTypeColumnOperator, boolOperators, - columnOperators, + genericOperators, + textColumnOperators, + jsonColumnOperators, + topologyColumnOperators, + PGTypes } from './utils'; import QueryBuilderJson from '../../../../QueryBuilderJson/QueryBuilderJson'; @@ -41,6 +48,8 @@ class PermissionBuilder extends React.Component { } componentDidUpdate(prevProps) { + // check for and fetch any missing schemas if + // either permission filter or available table schemas have changed if ( this.props.filter !== prevProps.filter || this.props.allTableSchemas.length !== prevProps.allTableSchemas.length @@ -71,7 +80,7 @@ class PermissionBuilder extends React.Component { } else if (isNotOperator(operator)) { const newPath = pathSplit.slice(1).join('.'); _missingSchemas = findMissingSchemas(newPath, currTable); - } else if (isColumnOperator(operator) || isArrayColumnOperator(operator)) { + } else if (isColumnOperator(operator)) { // no missing schemas } else { const { allTableSchemas } = this.props; @@ -127,6 +136,8 @@ class PermissionBuilder extends React.Component { ); }; + /********************************/ + const getFilter = (conditions, prefix, value = '') => { let _where = {}; @@ -195,7 +206,7 @@ class PermissionBuilder extends React.Component { const position = parseInt(opPrefixSplit[0], 10); _filter[operator] = opConditions || []; - if (opValue) { + if (opValue !== '') { _filter[operator][position] = opValue; } else { _filter[operator].splice(position, 1); @@ -240,7 +251,7 @@ class PermissionBuilder extends React.Component { const opConditions = isLast ? null : conditions[operator]; - if (operator === '--') { + if (operator === '') { // blank where } else if (isAndOrOperator(operator)) { _where = getAndOrOperatorFilter( @@ -258,7 +269,7 @@ class PermissionBuilder extends React.Component { newPrefix, isLast ); - } else if (isArrayColumnOperator(operator)) { + } else if (isArrayTypeColumnOperator(operator)) { _where = getArrayColumnOperatorFilter( operator, value, @@ -294,43 +305,34 @@ class PermissionBuilder extends React.Component { dispatch(dispatchFuncSetFilter(JSON.stringify(newFilter))); }; - const renderBoolSelect = (dispatchFunc, value) => { - const boolDispatchFunc = val => { - let boolVal = ''; - if (val === 'true') { - boolVal = true; - } else if (val === 'false') { - boolVal = false; - } - - dispatchFunc(boolVal); - }; + /********************************/ - let selectValue = ''; - if (value === true) { - selectValue = 'true'; - } else if (value === false) { - selectValue = 'false'; - } + const renderBoolSelect = ( + selectDispatchFunc, + value, + prefix = '', + disabledValues = [] + ) => { + const _value = (typeof value === 'boolean') ? value.toString() : ''; - const selectValues = ['true', 'false']; + const values = ['true', 'false']; - return renderSelect(boolDispatchFunc, selectValue, selectValues); + return renderSelect(selectDispatchFunc, _value, values, prefix, disabledValues); }; const renderSelect = ( - dispatchFunc, + selectDispatchFunc, value, values, prefix = '', disabledValues = [] ) => { const dispatchSelect = e => { - dispatchFunc(e.target.value); + selectDispatchFunc(e.target.value); }; const _selectOptions = []; - ['--'].concat(values).forEach((val, i) => { + [''].concat(values).forEach((val, i) => { const optionVal = addToPrefix(prefix, val); _selectOptions.push( ); }); - const selectedValue = addToPrefix(prefix, value || '--'); + const selectedValue = addToPrefix(prefix, value); return ( ); + }; + + const renderSuggestion = (suggestionDispatchFunc, inputValue, displayValue = null) => { + const dispatchSuggestion = () => { + suggestionDispatchFunc(inputValue); + }; - const suggestion = ( + return ( - [X-Hasura-User-Id] + [{ displayValue || inputValue }] ); + }; + + /********************************/ + + const renderValue = (dispatchFunc, value, prefix, valueType) => { + const dispatchInput = val => { + let _val = val; + + if (val !== '') { + if (PGTypes.boolean.includes(valueType)) { + _val = (val === 'true'); + } else if (PGTypes.numeric.includes(valueType) && !isNaN(val) && val.substr(-1) !== '.') { + _val = Number(val); + } else if ((PGTypes.json.includes(valueType) || PGTypes.postgis.includes(valueType)) && isJsonString(val)) { + _val = JSON.parse(val); + } + } + + dispatchFunc({ prefix: prefix, value: _val }); + }; + + const inputBox = () => { + return renderInput(dispatchInput, value); + }; + + const sessionVariableSuggestion = () => { + return renderSuggestion(dispatchInput, 'X-Hasura-User-Id'); + }; + + const jsonSuggestion = () => { + return renderSuggestion(dispatchInput, '{}', 'JSON'); + }; + + let input; + let suggestion; + + if (PGTypes.boolean.includes(valueType)) { + input = renderBoolSelect(dispatchInput, value); + } else if (PGTypes.json.includes(valueType) || PGTypes.postgis.includes(valueType)) { + input = inputBox(); + suggestion = jsonSuggestion(); + } else { + input = wrapDoubleQuotes(inputBox()); + suggestion = sessionVariableSuggestion(); + } return ( @@ -393,10 +448,10 @@ class PermissionBuilder extends React.Component { ); }; - const renderInputArray = (dispatchFunc, values, prefix) => { + const renderValueArray = (dispatchFunc, values, prefix, valueType) => { const _inputArray = []; (values || []).concat(['']).map((val, i) => { - const input = renderInput(dispatchFunc, val, addToPrefix(prefix, i)); + const input = renderValue(dispatchFunc, val, addToPrefix(prefix, i), valueType); _inputArray.push(input); }); @@ -410,54 +465,72 @@ class PermissionBuilder extends React.Component { ); }; - const renderOperatorExp = (dispatchFunc, condition, prefix) => { - const dispatchColumnOperator = val => { + const renderOperatorExp = (dispatchFunc, expression, prefix, valueType) => { + const dispatchColumnOperatorSelect = val => { dispatchFunc({ prefix: val }); }; - let _condition = condition; - if (typeof _condition === 'string') { - _condition = { $eq: _condition }; + // let _expression = expression; + // if (typeof _expression === 'string') { + // _expression = { $eq: _expression }; + // } + + const operator = Object.keys(expression)[0]; + const operationValue = expression[operator]; + + let operators; + if (PGTypes.character.includes(valueType)) { + operators = textColumnOperators; + } else if (PGTypes.json.includes(valueType)) { + operators = jsonColumnOperators; + } else if (PGTypes.postgis.includes(valueType)) { + operators = topologyColumnOperators; + } else { + operators = genericOperators; } - const operator = Object.keys(_condition)[0]; - const operationValue = _condition[operator]; - - const operatorSelect = renderSelect( - dispatchColumnOperator, + const _operatorSelect = renderSelect( + dispatchColumnOperatorSelect, operator, - columnOperators, + operators, prefix ); - let valueInput = ''; + let _valueInput = ''; if (operator) { - if (isArrayColumnOperator(operator)) { - valueInput = renderInputArray( + if (isArrayTypeColumnOperator(operator)) { + _valueInput = renderValueArray( + dispatchFunc, + operationValue, + addToPrefix(prefix, operator), + valueType + ); + } else if (isBoolTypeColumnOperator(operator)) { + _valueInput = renderValue( dispatchFunc, operationValue, - addToPrefix(prefix, operator) + addToPrefix(prefix, operator), + 'boolean' ); - } else if (isBoolColumnOperator(operator)) { - const boolOperatorDispatchFunc = val => { - dispatchFunc({ prefix: addToPrefix(prefix, operator), value: val }); - }; - - valueInput = renderBoolSelect( - boolOperatorDispatchFunc, - operationValue + } else if (isJsonTypeColumnOperator(operator)) { + _valueInput = renderValue( + dispatchFunc, + operationValue, + addToPrefix(prefix, operator), + 'jsonb' ); } else { // normal column operator - valueInput = renderInput( + _valueInput = renderValue( dispatchFunc, operationValue, - addToPrefix(prefix, operator) + addToPrefix(prefix, operator), + valueType ); } } - const _operatorExp = [{ key: operatorSelect, value: valueInput }]; + const _operatorExp = [{ key: _operatorSelect, value: _valueInput }]; const unselectedElements = []; if (!operator) { @@ -475,7 +548,7 @@ class PermissionBuilder extends React.Component { const renderColumnExp = ( dispatchFunc, column, - condition, + expression, table, tableSchemas, prefix @@ -494,13 +567,15 @@ class PermissionBuilder extends React.Component { _columnExp = renderBoolExp( dispatchFunc, - condition, + expression, refTable, tableSchemas, prefix ); // eslint-disable-line no-use-before-define } else { - _columnExp = renderOperatorExp(dispatchFunc, condition, prefix); + const columnType = getColumnType(column, tableSchema); + + _columnExp = renderOperatorExp(dispatchFunc, expression, prefix, columnType); } return _columnExp; @@ -508,17 +583,17 @@ class PermissionBuilder extends React.Component { const renderBoolExpArray = ( dispatchFunc, - conditions, + expressions, table, tableSchemas, prefix ) => { const _boolExpArray = []; - conditions.concat([{}]).forEach((condition, i) => { + expressions.concat([{}]).forEach((expression, i) => { const _boolExp = renderBoolExp( dispatchFunc, - condition, + expression, table, tableSchemas, addToPrefix(prefix, i) @@ -526,7 +601,7 @@ class PermissionBuilder extends React.Component { _boolExpArray.push(_boolExp); }); - const unselectedElements = [conditions.length]; + const unselectedElements = [expressions.length]; return ( { - const dispatchOperation = val => { + const dispatchOperationSelect = val => { dispatchFunc({ prefix: val }); }; let operation = null; - if (condition) { - operation = Object.keys(condition)[0]; + if (expression) { + operation = Object.keys(expression)[0]; } let tableColumns = []; @@ -561,44 +636,43 @@ class PermissionBuilder extends React.Component { } const columnOptions = tableColumns.concat(tableRelationships); - const operationOptions = Object.values(boolOperators); const operatorOptions = columnOptions .concat(['---']) - .concat(operationOptions); + .concat(boolOperators); - const boolExpKey = renderSelect( - dispatchOperation, + const _boolExpKey = renderSelect( + dispatchOperationSelect, operation, operatorOptions, prefix, ['---'] ); - let boolExpValue = null; + let _boolExpValue = null; if (operation) { const newPrefix = addToPrefix(prefix, operation); if (isAndOrOperator(operation)) { - boolExpValue = renderBoolExpArray( + _boolExpValue = renderBoolExpArray( dispatchFunc, - condition[operation], + expression[operation], table, tableSchemas, newPrefix ); } else if (isNotOperator(operation)) { - boolExpValue = renderBoolExp( + _boolExpValue = renderBoolExp( dispatchFunc, - condition[operation], + expression[operation], table, tableSchemas, newPrefix ); } else { - boolExpValue = renderColumnExp( + _boolExpValue = renderColumnExp( dispatchFunc, operation, - condition[operation], + expression[operation], table, tableSchemas, newPrefix @@ -606,7 +680,7 @@ class PermissionBuilder extends React.Component { } } - const _boolExp = [{ key: boolExpKey, value: boolExpValue }]; + const _boolExp = [{ key: _boolExpKey, value: _boolExpValue }]; const unselectedElements = []; if (!operation) { @@ -621,6 +695,8 @@ class PermissionBuilder extends React.Component { ); }; + /********************************/ + const showPermissionBuilder = () => { const { tableName, schemaName, filter, allTableSchemas } = this.props; diff --git a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js index a544d811be3bc..56ae3e67dad15 100644 --- a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js +++ b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js @@ -1,10 +1,54 @@ -export const boolOperators = { - and: '_and', - not: '_not', - or: '_or', +/* Constants */ + +export const PGTypes = { + boolean: [ + 'boolean' + ], + uuid: [ + 'uuid' + ], + numeric: [ + 'smallint', + 'integer', + 'bigint', + 'decimal', + 'numeric', + 'real', + 'double precision', + ], + character: [ + 'character', + 'character varying', + 'text' + ], + dateTime: [ + 'timestamp', + 'timestamp with time zone', + 'date', + 'time', + 'time with time zone', + 'interval' + ], + json: [ + 'json', + 'jsonb' + ], + postgis: [ + 'geometry', + 'geography' + ] }; -export const columnOperators = [ +export const notBoolOperators = [ + '_not' +]; + +export const andOrBoolOperators = [ + '_and', + '_or' +]; + +export const genericSimpleColumnOperators = [ '_eq', '_ne', '_in', @@ -12,55 +56,93 @@ export const columnOperators = [ '_gt', '_lt', '_gte', - '_lte', + '_lte' +]; + +export const genericArrayColumnOperators = [ + '_in', + '_nin' +]; + +export const genericBoolColumnOperators = [ + '_is_null' +]; + +export const textOnlyColumnOperators = [ '_like', '_nlike', + '_ilike', + '_nilike', '_similar', '_nsimilar', - '_is_null', ]; -export const arrayColumnOperators = ['_in', '_nin']; - -export const boolColumnOperators = ['_is_null']; - -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', - $is_null: '_is_null', -}; +export const jsonColumnOperators = [ + '_contains', + '_contained_in' +]; + +export const topologyColumnOperators = [ + '_st_contains', + '_st_crosses', + '_st_equals', + '_st_intersects', + '_st_overlaps', + '_st_touches', + '_st_within', + '_st_d_within' +]; + +export const boolOperators = notBoolOperators + .concat(andOrBoolOperators); + +export const columnOperators = genericSimpleColumnOperators + .concat(genericArrayColumnOperators) + .concat(genericBoolColumnOperators) + .concat(textOnlyColumnOperators) + .concat(jsonColumnOperators) + .concat(topologyColumnOperators); + +export const genericOperators = genericSimpleColumnOperators + .concat(genericArrayColumnOperators) + .concat(genericBoolColumnOperators); + +export const textColumnOperators = genericOperators + .concat(textOnlyColumnOperators); + +export const allOperators = boolOperators + .concat(columnOperators); + +/* Util functions */ export function isNotOperator(value) { - return value === boolOperators.not; + return notBoolOperators.includes(value); } export function isAndOrOperator(value) { - return value === boolOperators.or || value === boolOperators.and; + return andOrBoolOperators.includes(value); } -export function isArrayColumnOperator(value) { - return arrayColumnOperators.indexOf(value) !== -1; +export function isArrayTypeColumnOperator(value) { + return genericArrayColumnOperators.includes(value); } -export function isBoolColumnOperator(value) { - return boolColumnOperators.indexOf(value) !== -1; +export function isBoolTypeColumnOperator(value) { + return genericBoolColumnOperators.includes(value); +} + +export function isJsonTypeColumnOperator(value) { + return jsonColumnOperators + .concat(topologyColumnOperators) + .includes(value); } export function isColumnOperator(value) { - return columnOperators.indexOf(value) !== -1; + return columnOperators.includes(value); +} + +export function getLegacyOperator(operator) { + return operator.replace('_', '$'); } export function addToPrefix(prefix, value) { @@ -156,6 +238,32 @@ export function getRefTable(rel, tableSchema) { return _refTable; } +export function getColumnType(columnName, tableSchema) { + let _columnType = ''; + + if (!tableSchema || !columnName) { + return _columnType; + } + + const columnSchema = tableSchema.columns.find(_columnSchema => (_columnSchema.column_name === columnName)); + + if (columnSchema) { + _columnType = columnSchema.data_type; + } + + return _columnType; +} + +export function isJsonString(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + + return true; +} + export function getAllJsonPaths(json, prefix = '') { const _paths = []; diff --git a/console/src/components/Services/Data/TablePermissions/Permissions.js b/console/src/components/Services/Data/TablePermissions/Permissions.js index 56785e67b87b6..8ca9453eaef64 100644 --- a/console/src/components/Services/Data/TablePermissions/Permissions.js +++ b/console/src/components/Services/Data/TablePermissions/Permissions.js @@ -42,7 +42,7 @@ import TableHeader from '../TableCommon/TableHeader'; import ViewHeader from '../TableBrowseRows/ViewHeader'; import { setTable, fetchViewInfoFromInformationSchema } from '../DataActions'; import { getIngForm, escapeRegExp } from '../utils'; -import { legacyOperatorsMap } from './PermissionBuilder/utils'; +import { allOperators, getLegacyOperator } from './PermissionBuilder/utils'; import semverCheck from '../../../../helpers/semver'; import Button from '../../Layout/Button/Button'; @@ -1337,9 +1337,10 @@ class Permissions extends Component { } // replace legacy operator values - Object.keys(legacyOperatorsMap).forEach(legacyOperator => { - const legacyString = '"' + legacyOperator + '"'; - const currentString = '"' + legacyOperatorsMap[legacyOperator] + '"'; + allOperators.forEach(operator => { + const currentString = '"' + operator + '"'; + const legacyString = '"' + getLegacyOperator(operator) + '"'; + filterString = filterString.replace( new RegExp(escapeRegExp(legacyString), 'g'), currentString From 2fe38f84bc72af5434fd0b07f2383a21a499a4a4 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 14 Feb 2019 16:16:42 +0530 Subject: [PATCH 03/18] fix postgis type in console permissions --- .../Services/Data/TablePermissions/PermissionBuilder/utils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js index 56ae3e67dad15..183c0ed9900fa 100644 --- a/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js +++ b/console/src/components/Services/Data/TablePermissions/PermissionBuilder/utils.js @@ -249,6 +249,10 @@ export function getColumnType(columnName, tableSchema) { if (columnSchema) { _columnType = columnSchema.data_type; + + if (_columnType === 'USER-DEFINED') { + _columnType = columnSchema.udt_name; + } } return _columnType; From a056d547b2bb9a3c40d5ee7ae2762b39271822d3 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 14 Feb 2019 16:25:34 +0530 Subject: [PATCH 04/18] update package-lock.json --- console/package-lock.json | 55 +++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/console/package-lock.json b/console/package-lock.json index 8608c573dd2a7..7c34d65c6af4c 100644 --- a/console/package-lock.json +++ b/console/package-lock.json @@ -5448,7 +5448,7 @@ "dependencies": { "combined-stream": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", + "resolved": "http://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", "integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=", "requires": { "delayed-stream": "~1.0.0" @@ -5541,7 +5541,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -5559,11 +5560,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5576,15 +5579,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -5687,7 +5693,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -5697,6 +5704,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5709,17 +5717,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -5736,6 +5747,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -5808,7 +5820,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -5818,6 +5831,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -5893,7 +5907,8 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -5923,6 +5938,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5940,6 +5956,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5978,11 +5995,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.2", - "bundled": true + "bundled": true, + "optional": true } } }, @@ -8829,7 +8848,7 @@ }, "node-fetch": { "version": "2.1.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", + "resolved": "http://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=" }, "node-gyp": { @@ -9259,6 +9278,7 @@ "version": "0.1.4", "bundled": true, "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2", "longest": "^1.0.1", @@ -10262,7 +10282,8 @@ "longest": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "lru-cache": { "version": "4.1.3", @@ -11472,7 +11493,7 @@ }, "onetime": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", "dev": true }, @@ -11569,7 +11590,7 @@ }, "p-is-promise": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=", "dev": true }, @@ -16738,7 +16759,7 @@ }, "whatwg-fetch": { "version": "2.0.4", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", + "resolved": "http://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" }, "whet.extend": { From fed6a76ab389df1ccc0a961e17711107d6239475 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 14 Feb 2019 18:18:35 +0530 Subject: [PATCH 05/18] update to --- .../Services/Data/Function/Permission/Permission.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/console/src/components/Services/Data/Function/Permission/Permission.js b/console/src/components/Services/Data/Function/Permission/Permission.js index de9f6c490eabf..04d635f0e63ce 100644 --- a/console/src/components/Services/Data/Function/Permission/Permission.js +++ b/console/src/components/Services/Data/Function/Permission/Permission.js @@ -2,7 +2,7 @@ import React from 'react'; import Helmet from 'react-helmet'; import CommonTabLayout from '../../../Layout/CommonTabLayout/CommonTabLayout'; -// import { Link } from 'react-router'; +import { Link } from 'react-router'; import { push } from 'react-router-redux'; import { pageTitle, appPrefix } from '../Modify/constants'; @@ -82,14 +82,14 @@ class Permission extends React.Component { applicable to the data returned by this function

); From c3f8cffd6f63d05c6f9fc978539b5a290e4f6093 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 14 Feb 2019 18:34:38 +0530 Subject: [PATCH 06/18] replace indexOf with includes --- .../components/QueryBuilderJson/QueryBuilderJson.js | 6 +++--- .../PermissionBuilder/PermissionBuilder.js | 4 ++-- .../Services/Data/TablePermissions/Permissions.js | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/console/src/components/QueryBuilderJson/QueryBuilderJson.js b/console/src/components/QueryBuilderJson/QueryBuilderJson.js index d03bbb4013e23..5bc631c823201 100644 --- a/console/src/components/QueryBuilderJson/QueryBuilderJson.js +++ b/console/src/components/QueryBuilderJson/QueryBuilderJson.js @@ -109,14 +109,14 @@ class QueryBuilderJson extends React.Component { Object.keys(object).forEach((key, i) => { objectArray.push({ key: key, value: object[key] }); // replace unselected key with array position - if (unselectedElements.indexOf(key) !== -1) { + if (unselectedElements.includes(key)) { unselectedElements[unselectedElements.indexOf(key)] = i; } }); } objectArray.forEach((_object, i) => { - const unselected = unselectedElements.indexOf(i) !== -1; + const unselected = unselectedElements.includes(i); _jsonObject.push(
{ /* eslint-disable no-use-before-define */ - const unselected = unselectedElements.indexOf(i) !== -1; + const unselected = unselectedElements.includes(i); _jsonArray.push(
{val || '--'} @@ -561,7 +561,7 @@ class PermissionBuilder extends React.Component { } let _columnExp = ''; - if (tableRelationships.indexOf(column) !== -1) { + if (tableRelationships.includes(column)) { const rel = getTableRelationship(tableSchema, column); const refTable = getRefTable(rel, tableSchema); diff --git a/console/src/components/Services/Data/TablePermissions/Permissions.js b/console/src/components/Services/Data/TablePermissions/Permissions.js index 9fc4b08ce5944..60fd92785be95 100644 --- a/console/src/components/Services/Data/TablePermissions/Permissions.js +++ b/console/src/components/Services/Data/TablePermissions/Permissions.js @@ -321,7 +321,7 @@ class Permissions extends Component { if (role === 'admin') { _permission = permissionsSymbols.fullAccess; - } else if (Object.keys(rolePermissions).indexOf(role) === -1) { + } else if (!Object.keys(rolePermissions).includes(role)) { _permission = permissionsSymbols.noAccess; } else { const permissions = rolePermissions[role][queryType]; @@ -342,7 +342,7 @@ class Permissions extends Component { if (JSON.stringify(permissions[filterKey]) === '{}') { if ( checkColumns && - permissions.columns.indexOf('*') === -1 && + !permissions.columns.includes('*') && permissions.columns.length !== tableSchema.columns.length ) { _permission = permissionsSymbols.partialAccess; @@ -1208,7 +1208,7 @@ class Permissions extends Component { return tableSchema.columns.map((colObj, i) => { const column = colObj.column_name; const checked = permsState[query] - ? permsState[query].columns.indexOf(column) !== -1 + ? permsState[query].columns.includes(column) : false; return ( @@ -1235,7 +1235,7 @@ class Permissions extends Component { if ( getQueriesWithPermColumns( semverCheck('insertPermRestrictColumns', this.props.serverVersion) - ).indexOf(query) !== -1 + ).includes(query) ) { const dispatchToggleAllColumns = () => { const allColumns = tableSchema.columns.map(c => c.column_name); @@ -1593,7 +1593,7 @@ class Permissions extends Component { }; const roleList = []; currentPermissions.map(perm => { - if (roleList.indexOf(perm.role_name) === -1) { + if (!roleList.includes(perm.role_name)) { roleList.push(perm.role_name); } }); From 347a520ce614578e20140d25d9cd9cc3db7699cf Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 14 Feb 2019 18:49:15 +0530 Subject: [PATCH 07/18] update partial access filter icon in permissions --- .../Services/Data/TablePermissions/Permissions.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/console/src/components/Services/Data/TablePermissions/Permissions.js b/console/src/components/Services/Data/TablePermissions/Permissions.js index 60fd92785be95..a2296532e7b0f 100644 --- a/console/src/components/Services/Data/TablePermissions/Permissions.js +++ b/console/src/components/Services/Data/TablePermissions/Permissions.js @@ -618,14 +618,9 @@ class Permissions extends Component { const getPermissionsTable = (tableSchema, queryTypes, permsState) => { const permissionsSymbols = { - //