mirror of
https://github.com/zhigang1992/graphql-engine.git
synced 2026-05-25 18:32:23 +08:00
re-add same as other action options in permissions (#1970)
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
permOpenEdit,
|
||||
permAddTableSchemas,
|
||||
permSetFilter,
|
||||
permSetFilterSameAs,
|
||||
permToggleColumn,
|
||||
permToggleAllColumns,
|
||||
permAllowAll,
|
||||
@@ -158,6 +159,10 @@ class Permissions extends Component {
|
||||
);
|
||||
};
|
||||
|
||||
const getQueryFilterKey = query => {
|
||||
return query === 'insert' ? 'check' : 'filter';
|
||||
};
|
||||
|
||||
/********************/
|
||||
|
||||
const getAlertHtml = (
|
||||
@@ -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]) {
|
||||
@@ -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"
|
||||
@@ -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(
|
||||
@@ -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 =>
|
||||
@@ -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">
|
||||
@@ -757,6 +839,7 @@ class Permissions extends Component {
|
||||
};
|
||||
|
||||
addNoChecksOption();
|
||||
addSameAsOptions();
|
||||
addCustomCheckOption();
|
||||
|
||||
return _filterOptionsSection;
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user