make data store component respect permissions (#929)

Co-authored-by: burnettk <burnettk@users.noreply.github.com>
This commit is contained in:
Kevin Burnett 2024-01-30 09:43:05 -08:00 committed by GitHub
parent 40b9570e22
commit b4f85925d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 33 additions and 16 deletions

View File

@ -3,8 +3,10 @@ import { useSearchParams } from 'react-router-dom';
import { ArrowRight } from '@carbon/icons-react';
import { ClickableTile } from '@carbon/react';
import HttpService from '../services/HttpService';
import { DataStore, ProcessGroup } from '../interfaces';
import { DataStore, PermissionsToCheck, ProcessGroup } from '../interfaces';
import { truncateString } from '../helpers';
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
import { usePermissionFetcher } from '../hooks/PermissionService';
type OwnProps = {
defaultDataStores?: DataStore[];
@ -26,12 +28,17 @@ export default function DataStoreListTiles({
const [searchParams] = useSearchParams();
const [dataStores, setDataStores] = useState<DataStore[] | null>(null);
const { targetUris } = useUriListForPermissions();
const permissionRequestData: PermissionsToCheck = {
[targetUris.dataStoreListPath]: ['GET'],
};
const { ability, permissionsLoaded } = usePermissionFetcher(
permissionRequestData
);
useEffect(() => {
const setDataStoresFromResult = (result: any) => {
setDataStores(result);
};
if (permissionsLoaded) {
if (ability.can('GET', targetUris.dataStoreListPath)) {
if (defaultDataStores) {
setDataStores(defaultDataStores);
} else {
@ -40,11 +47,21 @@ export default function DataStoreListTiles({
queryParams = `${queryParams}&process_group_identifier=${processGroup.id}`;
}
HttpService.makeCallToBackend({
path: `/data-stores${queryParams}`,
successCallback: setDataStoresFromResult,
path: `${targetUris.dataStoreListPath}${queryParams}`,
successCallback: setDataStores,
});
}
}, [searchParams, dataStore, defaultDataStores, processGroup]);
}
}
}, [
searchParams,
dataStore,
defaultDataStores,
processGroup,
permissionsLoaded,
ability,
targetUris.dataStoreListPath,
]);
const dataStoresDisplayArea = () => {
let displayText = null;