这是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
15 changes: 15 additions & 0 deletions console/cypress/integration/data/permissions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ export const permNoCheck = (tableName, query, first) => {
.contains('Toggle all')
.click();
}
if (query === 'insert' || query === 'update') {
cy.get(getElementFromAlias('toggle-column-presets')).click();
cy.get(getElementFromAlias('column-presets-column-0')).select(
getColName(0)
);
cy.get(getElementFromAlias('column-presets-type-0')).select('static');
cy.get(getElementFromAlias('column-presets-value-0'))
.type('1')
.blur();
cy.get(getElementFromAlias('column-presets-column-1')).select(
getColName(1)
);
cy.get(getElementFromAlias('column-presets-type-1')).select('session');
cy.get(getElementFromAlias('column-presets-value-1')).type('user-id');
}
// Save
savePermission();
// Validate
Expand Down
6 changes: 6 additions & 0 deletions console/cypress/integration/validators/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,18 @@ const compareChecks = (permObj, check, query, columns) => {
if (check === 'none') {
if (query === 'insert') {
expect(Object.keys(permObj.check).length === 0).to.be.true;
expect(permObj.set[getColName(0)] === '1').to.be.true;
expect(permObj.set[getColName(1)] === 'x-hasura-user-id').to.be.true;
} else {
expect(Object.keys(permObj.filter).length === 0).to.be.true;
if (query === 'select' || query === 'update') {
[0, 1, 2].forEach(index => {
expect(permObj.columns.includes(getColName(index)));
});
if (query === 'update') {
expect(permObj.set[getColName(0)] === '1').to.be.true;
expect(permObj.set[getColName(1)] === 'x-hasura-user-id').to.be.true;
}
}
}
} else if (query === 'insert') {
Expand Down
6 changes: 2 additions & 4 deletions console/src/components/Common/InputChecker/InputChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export default class InputChecker extends React.Component {
}
onBlur(e) {
const val = e.target.value;
const indexId =
e.target && parseInt(e.target.getAttribute('data-index-id'), 10);
if (!val) {
this.setState({
isError: false,
Expand All @@ -23,12 +21,11 @@ export default class InputChecker extends React.Component {
return;
}
inputChecker(this.props.type, val)
.then(r => {
.then(() => {
this.setState({
isError: false,
errorMessage: '',
});
this.props.onBlur(undefined, indexId, r);
})
.catch(r => {
this.setState({
Expand All @@ -55,6 +52,7 @@ export default class InputChecker extends React.Component {
data-index-id={indexId || 0}
disabled={disabled}
title={this.state.errorMessage || ''}
data-test={this.props['data-test']}
/>
);
}
Expand Down
23 changes: 18 additions & 5 deletions console/src/components/Services/Data/DataState.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ const defaultPermissionsState = {
tableSchemas: [],
};

const defaultInsertSetState = {
key: '',
value: '',
const defaultSetState = {
insert: {
key: '',
value: '',
},
update: {
key: '',
value: '',
},
};
const defaultQueryPermissions = {
insert: {
Expand All @@ -45,7 +51,7 @@ const defaultQueryPermissions = {
columns: [],
localSet: [
{
...defaultInsertSetState,
...defaultSetState.insert,
},
],
isSetConfigChecked: false,
Expand All @@ -59,6 +65,13 @@ const defaultQueryPermissions = {
update: {
columns: [],
filter: {},
set: {},
localSet: [
{
...defaultSetState.update,
},
],
isSetConfigChecked: false,
},
delete: {
filter: {},
Expand Down Expand Up @@ -153,5 +166,5 @@ export {
defaultModifyState,
defaultPermissionsState,
defaultQueryPermissions,
defaultInsertSetState,
defaultSetState,
};
97 changes: 55 additions & 42 deletions console/src/components/Services/Data/TableCommon/TableReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
defaultModifyState,
defaultPermissionsState,
defaultInsertSetState,
defaultSetState,
} from '../DataState';

import { MAKE_REQUEST, REQUEST_SUCCESS, REQUEST_ERROR } from '../DataActions';
Expand Down Expand Up @@ -70,10 +70,10 @@ import {
deleteFromPermissionsState,
updateBulkSelect,
updateBulkSameSelect,
CREATE_NEW_INSERT_SET_VAL,
DELETE_INSERT_SET_VAL,
CREATE_NEW_SET_VAL,
DELETE_SET_VAL,
UPDATE_PERM_SET_KEY_VALUE,
TOGGLE_PERM_INSERT_SET_OPERATION_CHECK,
TOGGLE_PERM_SET_OPERATION_CHECK,
} from '../TablePermissions/Actions';

const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
Expand Down Expand Up @@ -485,50 +485,61 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
};

/* Set operations */
case TOGGLE_PERM_INSERT_SET_OPERATION_CHECK:
return {
...modifyState,
permissionsState: {
...modifyState.permissionsState,
insert: {
...modifyState.permissionsState.insert,
isSetConfigChecked: !modifyState.permissionsState.insert
.isSetConfigChecked,
case TOGGLE_PERM_SET_OPERATION_CHECK:
if (
modifyState.permissionsState[action.data.queryType].localSet.length ===
0 ||
(modifyState.permissionsState[action.data.queryType].localSet.length ===
1 &&
modifyState.permissionsState[action.data.queryType].localSet[0]
.key === '')
) {
return {
...modifyState,
permissionsState: {
...modifyState.permissionsState,
[action.data.queryType]: {
...modifyState.permissionsState[action.data.queryType],
isSetConfigChecked: !modifyState.permissionsState[
action.data.queryType
].isSetConfigChecked,
},
},
},
};

case CREATE_NEW_INSERT_SET_VAL:
};
}
return modifyState;
case CREATE_NEW_SET_VAL:
return {
...modifyState,
permissionsState: {
...modifyState.permissionsState,
insert: {
...modifyState.permissionsState.insert,
[action.data.queryType]: {
...modifyState.permissionsState[action.data.queryType],
localSet: [
...modifyState.permissionsState.insert.localSet.slice(),
{ ...defaultInsertSetState },
...modifyState.permissionsState[action.data.queryType].localSet,
{ ...defaultSetState[action.data.queryType] },
],
},
},
};

case DELETE_INSERT_SET_VAL:
case DELETE_SET_VAL:
const deleteIndex = action.data.index;
return {
...modifyState,
permissionsState: {
...modifyState.permissionsState,
insert: {
...modifyState.permissionsState.insert,
[action.data.queryType]: {
...modifyState.permissionsState[action.data.queryType],
localSet: [
...modifyState.permissionsState.insert.localSet.slice(
0,
deleteIndex
),
...modifyState.permissionsState.insert.localSet.slice(
...modifyState.permissionsState[
action.data.queryType
].localSet.slice(0, deleteIndex),
...modifyState.permissionsState[
action.data.queryType
].localSet.slice(
deleteIndex + 1,
modifyState.permissionsState.insert.localSet.length
modifyState.permissionsState[action.data.queryType].localSet
.length
),
],
},
Expand All @@ -538,34 +549,36 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
case UPDATE_PERM_SET_KEY_VALUE:
const updatedIndex = action.data.index;
const setKeyVal =
modifyState.permissionsState.insert.localSet[updatedIndex];
modifyState.permissionsState[action.data.queryType].localSet[
updatedIndex
];
setKeyVal[action.data.key] = action.data.value;
if (action.data.key === 'key') {
// Clear if key changes
setKeyVal.value = '';
}

return {
...modifyState,
permissionsState: {
...modifyState.permissionsState,
insert: {
...modifyState.permissionsState.insert,
[action.data.queryType]: {
...modifyState.permissionsState[action.data.queryType],
localSet: [
...modifyState.permissionsState.insert.localSet.slice(
0,
updatedIndex
),
...modifyState.permissionsState[
action.data.queryType
].localSet.slice(0, updatedIndex),
{ ...setKeyVal },
...modifyState.permissionsState.insert.localSet.slice(
...modifyState.permissionsState[
action.data.queryType
].localSet.slice(
updatedIndex + 1,
modifyState.permissionsState.insert.localSet.length
modifyState.permissionsState[action.data.queryType].localSet
.length
),
],
},
},
};

case PERM_RESET_BULK_SELECT:
return {
...modifyState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,7 @@ hr
}
}
}

.chevron_mar_right {
margin-right: 5px;
}
24 changes: 13 additions & 11 deletions console/src/components/Services/Data/TablePermissions/Actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
defaultPermissionsState,
defaultQueryPermissions,
defaultInsertSetState,
defaultSetState,
} from '../DataState';
import { getEdForm, getIngForm } from '../utils';
import { makeMigrationCall } from '../DataActions';
Expand Down Expand Up @@ -43,13 +43,12 @@ export const X_HASURA_CONST = 'x-hasura-';
export const UPDATE_PERM_SET_KEY_VALUE =
'ModifyTable/UPDATE_PERM_SET_KEY_VALUE';

export const CREATE_NEW_INSERT_SET_VAL =
'ModifyTable/CREATE_NEW_INSERT_SET_VAL';
export const CREATE_NEW_SET_VAL = 'ModifyTable/CREATE_NEW_SET_VAL';

export const DELETE_INSERT_SET_VAL = 'ModifyTable/DELETE_INSERT_SET_VAL';
export const DELETE_SET_VAL = 'ModifyTable/DELETE_SET_VAL';

export const TOGGLE_PERM_INSERT_SET_OPERATION_CHECK =
'ModifyTable/TOGGLE_PERM_INSERT_SET_OPERATION_CHECK';
export const TOGGLE_PERM_SET_OPERATION_CHECK =
'ModifyTable/TOGGLE_PERM_SET_OPERATION_CHECK';
export const SET_TYPE_CONFIG = 'ModifyTable/SET_TYPE_CONFIG';

/* */
Expand Down Expand Up @@ -160,7 +159,7 @@ const getBasePermissionsState = (
let set = [];
_permissions[q] = rolePermissions.permissions[q];
// If the query is insert, transform set object if exists to an array
if (q === 'insert') {
if (q === 'insert' || q === 'update') {
// If set is an object
if (insertPermColumnRestriction) {
if (!_permissions[q].columns) {
Expand All @@ -180,7 +179,7 @@ const getBasePermissionsState = (
value: _permissions[q].set[s],
});
});
set.push(defaultInsertSetState);
set.push(defaultSetState[q]);
_permissions[q].isSetConfigChecked = true;
} else if (
'localSet' in _permissions[q] &&
Expand All @@ -189,13 +188,13 @@ const getBasePermissionsState = (
set = [..._permissions[q].localSet];
_permissions[q].isSetConfigChecked = true;
} else {
set.push(defaultInsertSetState);
set.push(defaultSetState[q]);
}
_permissions[q].localSet = [...set];
} else {
// Just to support version changes
// If user goes from current to previous version and back
_permissions[q].localSet = [defaultInsertSetState];
_permissions[q].localSet = [defaultSetState[q]];
_permissions[q].set = {};
}
}
Expand Down Expand Up @@ -599,7 +598,10 @@ const permChangePermissions = changeType => {
},
};

if (query === 'insert' && 'localSet' in permissionsState[query]) {
if (
(query === 'insert' || query === 'update') &&
'localSet' in permissionsState[query]
) {
// Convert insert set array to Object
if (permissionsState[query].isSetConfigChecked) {
const newSet = {};
Expand Down
Loading