这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
106 changes: 96 additions & 10 deletions console/src/components/Services/Data/TablePermissions/Permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
permOpenEdit,
permAddTableSchemas,
permSetFilter,
permSetFilterSameAs,
permToggleColumn,
permToggleAllColumns,
permAllowAll,
Expand Down Expand Up @@ -158,6 +159,10 @@ class Permissions extends Component {
);
};

const getQueryFilterKey = query => {
return query === 'insert' ? 'check' : 'filter';
};

/********************/

const getAlertHtml = (
Expand Down Expand Up @@ -613,7 +618,7 @@ class Permissions extends Component {
};

const getRowSection = () => {
const filterKey = query === 'insert' ? 'check' : 'filter';
const filterKey = getQueryFilterKey(query);

let filterString = '';
if (permissionsState[query]) {
Expand All @@ -639,12 +644,45 @@ class Permissions extends Component {
dispatch(permAllowAll());
};

const dispatchSetFilterSameAs = filter => () => {
dispatch(permSetFilterSameAs(JSON.parse(filter)));
};

const dispatchCustomChecked = () => {
dispatch(permCustomChecked());
};

// return queries grouped by filterString i.e. { filterString: [query] }
const getFilterQueries = () => {
const _filterQueries = {};
queryTypes.forEach(queryType => {
if (queryType === permissionsState.query) {
return;
}

const queryFilterKey = getQueryFilterKey(queryType);

let queryFilterString = '';
if (permissionsState[queryType]) {
queryFilterString = JSON.stringify(
permissionsState[queryType][queryFilterKey]
);
}

if (queryFilterString) {
_filterQueries[queryFilterString] =
_filterQueries[queryFilterString] || [];
_filterQueries[queryFilterString].push(queryType);
}
});

return _filterQueries;
};

const _filterOptionsSection = [];

const filterQueries = getFilterQueries();

const selectedValue = (
<AceEditor
mode="json"
Expand Down Expand Up @@ -674,11 +712,25 @@ class Permissions extends Component {
</div>
);

// TODO: add no access option

const addNoChecksOption = () => {
const isSelected = !permissionsState.custom_checked && noChecks;

// Add allow all option
let allowAllQueryInfo = '';
if (filterQueries['{}']) {
allowAllQueryInfo = (
<i className={styles.add_mar_left_small}>
(Same as <b>{filterQueries['{}'].join(', ')}</b>)
</i>
);
}

const allowAllLabel = (
<span data-test="without-checks">Without any checks</span>
<span data-test="without-checks">
Without any checks {allowAllQueryInfo}
</span>
);

_filterOptionsSection.push(
Expand All @@ -696,7 +748,37 @@ class Permissions extends Component {
}
};

// TODO: add no access option
const addSameAsOptions = () => {
// Add other query options
Object.keys(filterQueries).forEach((filter, i) => {
if (filter === '{}') {
return;
}

const isSelected =
!permissionsState.custom_checked && filterString === filter;

const queries = filterQueries[filter].join(', ');
const queryLabel = (
<span data-test="mutual-check">
With same custom checks as <b>{queries}</b>
</span>
);
_filterOptionsSection.push(
getFilterRadio(
i,
isSelected,
queries,
dispatchSetFilterSameAs(filter),
queryLabel
)
);

if (isSelected) {
_filterOptionsSection.push(selectedValue);
}
});
};

const addCustomCheckOption = () => {
const dispatchFuncSetFilter = filter =>
Expand All @@ -705,13 +787,13 @@ class Permissions extends Component {
const dispatchFuncAddTableSchemas = schemaNames =>
permAddTableSchemas(schemaNames);

const isCustomFilter = () => {
return filterString !== '' && filterString !== '{}';
};
const isUniqueFilter =
filterString !== '' &&
filterString !== '{}' &&
!filterQueries[filterString];

const isSelected =
permissionsState.custom_checked ||
isCustomFilter(queryTypes, permissionsState, filterString);
permissionsState.custom_checked || isUniqueFilter;

const customCheckToolTip = (
<Tooltip id="tooltip-custom-check">
Expand Down Expand Up @@ -757,6 +839,7 @@ class Permissions extends Component {
};

addNoChecksOption();
addSameAsOptions();
addCustomCheckOption();

return _filterOptionsSection;
Expand Down Expand Up @@ -834,8 +917,11 @@ class Permissions extends Component {
>
<div className={styles.editPermsSection}>
<div>
Allow role <b>{permissionsState.role}</b> to{' '}
{permissionsState.query} <b>rows</b>:{getFilterOptions()}
<div>
Allow role <b>{permissionsState.role}</b> to{' '}
{permissionsState.query} <b>rows</b>:
</div>
{getFilterOptions()}
</div>
<div className={styles.add_mar_top}>{getLimitSection()}</div>
</div>
Expand Down