From 67a97d8fcfa1e5bcf851276ffd2f3a519793469c Mon Sep 17 00:00:00 2001 From: rikinsk Date: Tue, 9 Apr 2019 18:15:15 +0530 Subject: [PATCH] readd same as other action options in permissions --- .../Data/TablePermissions/Permissions.js | 106 ++++++++++++++++-- 1 file changed, 96 insertions(+), 10 deletions(-) diff --git a/console/src/components/Services/Data/TablePermissions/Permissions.js b/console/src/components/Services/Data/TablePermissions/Permissions.js index 530530e221961..98f7d28b004d1 100644 --- a/console/src/components/Services/Data/TablePermissions/Permissions.js +++ b/console/src/components/Services/Data/TablePermissions/Permissions.js @@ -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 = ( ); + // TODO: add no access option + const addNoChecksOption = () => { const isSelected = !permissionsState.custom_checked && noChecks; + // Add allow all option + let allowAllQueryInfo = ''; + if (filterQueries['{}']) { + allowAllQueryInfo = ( + + (Same as {filterQueries['{}'].join(', ')}) + + ); + } + const allowAllLabel = ( - Without any checks + + Without any checks {allowAllQueryInfo} + ); _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 = ( + + With same custom checks as {queries} + + ); + _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 = ( @@ -757,6 +839,7 @@ class Permissions extends Component { }; addNoChecksOption(); + addSameAsOptions(); addCustomCheckOption(); return _filterOptionsSection; @@ -834,8 +917,11 @@ class Permissions extends Component { >
- Allow role {permissionsState.role} to{' '} - {permissionsState.query} rows:{getFilterOptions()} +
+ Allow role {permissionsState.role} to{' '} + {permissionsState.query} rows: +
+ {getFilterOptions()}
{getLimitSection()}