From 83328eef93fdc7585420d315c5654fade3d986dd Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 25 Nov 2022 15:23:08 -0500 Subject: [PATCH] allow disabling the permission check for the Create New Instance page to improve performance. --- .../src/components/ProcessInstanceRun.tsx | 27 ++++++++++++++----- .../src/components/ProcessModelListTiles.tsx | 3 +++ .../src/hooks/PermissionService.tsx | 15 ++++++----- .../src/routes/CreateNewInstance.tsx | 5 +++- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/spiffworkflow-frontend/src/components/ProcessInstanceRun.tsx b/spiffworkflow-frontend/src/components/ProcessInstanceRun.tsx index bcead73fc..87406f80f 100644 --- a/spiffworkflow-frontend/src/components/ProcessInstanceRun.tsx +++ b/spiffworkflow-frontend/src/components/ProcessInstanceRun.tsx @@ -68,12 +68,14 @@ type OwnProps = { processModel: ProcessModel; onSuccessCallback: Function; className?: string; + checkPermissions?: boolean; }; export default function ProcessInstanceRun({ processModel, onSuccessCallback, className, + checkPermissions = true, }: OwnProps) { const navigate = useNavigate(); const setErrorMessage = (useContext as any)(ErrorContext)[1]; @@ -82,9 +84,14 @@ export default function ProcessInstanceRun({ ); const processInstanceActionPath = `/v1.0/process-models/${modifiedProcessModelId}/process-instances`; - const permissionRequestData: PermissionsToCheck = { + let permissionRequestData: PermissionsToCheck = { [processInstanceActionPath]: ['POST'], }; + + if (!checkPermissions) { + permissionRequestData = {}; + } + const { ability } = usePermissionFetcher(permissionRequestData); const onProcessInstanceRun = (processInstance: any) => { @@ -115,12 +122,18 @@ export default function ProcessInstanceRun({ httpMethod: 'POST', }); }; - + if (checkPermissions) { + return ( + + + + ); + } return ( - - - + ); } diff --git a/spiffworkflow-frontend/src/components/ProcessModelListTiles.tsx b/spiffworkflow-frontend/src/components/ProcessModelListTiles.tsx index f42a032d4..3022fadc1 100644 --- a/spiffworkflow-frontend/src/components/ProcessModelListTiles.tsx +++ b/spiffworkflow-frontend/src/components/ProcessModelListTiles.tsx @@ -15,11 +15,13 @@ import ProcessInstanceRun from './ProcessInstanceRun'; type OwnProps = { headerElement?: ReactElement; processGroup?: ProcessGroup; + checkPermissions?: boolean; }; export default function ProcessModelListTiles({ headerElement, processGroup, + checkPermissions = true, }: OwnProps) { const [searchParams] = useSearchParams(); const [processModels, setProcessModels] = useState( @@ -94,6 +96,7 @@ export default function ProcessModelListTiles({ processModel={row} onSuccessCallback={setProcessInstance} className="tile-pin-bottom" + checkPermissions={checkPermissions} /> diff --git a/spiffworkflow-frontend/src/hooks/PermissionService.tsx b/spiffworkflow-frontend/src/hooks/PermissionService.tsx index f4d0aa090..fad496a76 100644 --- a/spiffworkflow-frontend/src/hooks/PermissionService.tsx +++ b/spiffworkflow-frontend/src/hooks/PermissionService.tsx @@ -37,13 +37,14 @@ export const usePermissionFetcher = ( ability.update(rules); setPermissionsLoaded(true); }; - - HttpService.makeCallToBackend({ - path: `/permissions-check`, - httpMethod: 'POST', - successCallback: processPermissionResult, - postBody: { requests_to_check: permissionsToCheck }, - }); + if (Object.keys(permissionsToCheck).length !== 0) { + HttpService.makeCallToBackend({ + path: `/permissions-check`, + httpMethod: 'POST', + successCallback: processPermissionResult, + postBody: { requests_to_check: permissionsToCheck }, + }); + } }); return { ability, permissionsLoaded }; diff --git a/spiffworkflow-frontend/src/routes/CreateNewInstance.tsx b/spiffworkflow-frontend/src/routes/CreateNewInstance.tsx index 551e3abb5..24f1f9fcc 100644 --- a/spiffworkflow-frontend/src/routes/CreateNewInstance.tsx +++ b/spiffworkflow-frontend/src/routes/CreateNewInstance.tsx @@ -2,6 +2,9 @@ import ProcessModelListTiles from '../components/ProcessModelListTiles'; export default function CreateNewInstance() { return ( - Processes I can start} /> + Processes I can start} + checkPermissions={false} + /> ); }