added some permissions for tasks
This commit is contained in:
parent
dfe267caaa
commit
ac2064252e
|
@ -976,7 +976,7 @@ paths:
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/Task"
|
$ref: "#/components/schemas/Task"
|
||||||
|
|
||||||
/process-instance/{process_instance_id}/tasks:
|
/process-instances/{modified_process_model_id}/{process_instance_id}/tasks:
|
||||||
parameters:
|
parameters:
|
||||||
- name: process_instance_id
|
- name: process_instance_id
|
||||||
in: path
|
in: path
|
||||||
|
|
|
@ -81,3 +81,15 @@ permissions:
|
||||||
users: []
|
users: []
|
||||||
allowed_permissions: [read]
|
allowed_permissions: [read]
|
||||||
uri: /*
|
uri: /*
|
||||||
|
|
||||||
|
invoice-approval-tasks-read:
|
||||||
|
groups: ["Finance Team"]
|
||||||
|
users: []
|
||||||
|
allowed_permissions: [read]
|
||||||
|
uri: /v1.0/process-instances/category_number_one:lanes/*
|
||||||
|
#
|
||||||
|
# invoice-approval-run:
|
||||||
|
# groups: ["Finance Team"]
|
||||||
|
# users: []
|
||||||
|
# allowed_permissions: [create]
|
||||||
|
# uri: /v1.0/process-models/execute-procure-to-pay:cc-invoice-approval-process/process-instances
|
||||||
|
|
|
@ -1141,7 +1141,7 @@ def get_tasks(
|
||||||
|
|
||||||
|
|
||||||
def process_instance_task_list(
|
def process_instance_task_list(
|
||||||
process_instance_id: int, all_tasks: bool = False, spiff_step: int = 0
|
modified_process_model_id: str, process_instance_id: int, all_tasks: bool = False, spiff_step: int = 0
|
||||||
) -> flask.wrappers.Response:
|
) -> flask.wrappers.Response:
|
||||||
"""Process_instance_task_list."""
|
"""Process_instance_task_list."""
|
||||||
process_instance = find_process_instance_by_id_or_raise(process_instance_id)
|
process_instance = find_process_instance_by_id_or_raise(process_instance_id)
|
||||||
|
@ -1204,6 +1204,7 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response
|
||||||
task = ProcessInstanceService.spiff_task_to_api_task(spiff_task)
|
task = ProcessInstanceService.spiff_task_to_api_task(spiff_task)
|
||||||
task.data = spiff_task.data
|
task.data = spiff_task.data
|
||||||
task.process_model_display_name = process_model.display_name
|
task.process_model_display_name = process_model.display_name
|
||||||
|
task.process_model_identifier = process_model.id
|
||||||
process_model_with_form = process_model
|
process_model_with_form = process_model
|
||||||
|
|
||||||
if task.type == "User Task":
|
if task.type == "User Task":
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// We may need to update usage of Ability when we update.
|
||||||
|
// They say they are going to rename PureAbility to Ability and remove the old class.
|
||||||
import { AbilityBuilder, Ability } from '@casl/ability';
|
import { AbilityBuilder, Ability } from '@casl/ability';
|
||||||
import { useContext, useEffect } from 'react';
|
import { useContext, useEffect } from 'react';
|
||||||
import { AbilityContext } from '../contexts/Can';
|
import { AbilityContext } from '../contexts/Can';
|
||||||
|
@ -11,6 +13,7 @@ export const usePermissionFetcher = (
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const processPermissionResult = (result: PermissionCheckResponseBody) => {
|
const processPermissionResult = (result: PermissionCheckResponseBody) => {
|
||||||
|
const oldRules = ability.rules;
|
||||||
const { can, cannot, rules } = new AbilityBuilder(Ability);
|
const { can, cannot, rules } = new AbilityBuilder(Ability);
|
||||||
Object.keys(result.results).forEach((url: string) => {
|
Object.keys(result.results).forEach((url: string) => {
|
||||||
const permissionVerbResults = result.results[url];
|
const permissionVerbResults = result.results[url];
|
||||||
|
@ -23,14 +26,21 @@ export const usePermissionFetcher = (
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
oldRules.forEach((oldRule: any) => {
|
||||||
|
if (oldRule.inverted) {
|
||||||
|
cannot(oldRule.action, oldRule.subject);
|
||||||
|
} else {
|
||||||
|
can(oldRule.action, oldRule.subject);
|
||||||
|
}
|
||||||
|
});
|
||||||
ability.update(rules);
|
ability.update(rules);
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: `/permissions-check`,
|
path: `/permissions-check`,
|
||||||
httpMethod: 'POST',
|
httpMethod: 'POST',
|
||||||
successCallback: processPermissionResult,
|
successCallback: processPermissionResult,
|
||||||
postBody: { requests_to_check: permissionsToCheck },
|
postBody: { requests_to_check: permissionsToCheck },
|
||||||
// failureCallback: setErrorMessage,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,15 @@ import { useParams } from 'react-router-dom';
|
||||||
export const useUriListForPermissions = () => {
|
export const useUriListForPermissions = () => {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const targetUris = {
|
const targetUris = {
|
||||||
processGroupListPath: `/v1.0/process-groups`,
|
messageInstanceListPath: '/v1.0/messages',
|
||||||
|
processGroupListPath: '/v1.0/process-groups',
|
||||||
processGroupShowPath: `/v1.0/process-groups/${params.process_group_id}`,
|
processGroupShowPath: `/v1.0/process-groups/${params.process_group_id}`,
|
||||||
|
processInstanceActionPath: `/v1.0/process-models/${params.process_model_id}/process-instances`,
|
||||||
|
processInstanceListPath: '/v1.0/process-instances',
|
||||||
processModelCreatePath: `/v1.0/process-models/${params.process_group_id}`,
|
processModelCreatePath: `/v1.0/process-models/${params.process_group_id}`,
|
||||||
processModelShowPath: `/v1.0/process-models/${params.process_model_id}`,
|
|
||||||
processModelFileCreatePath: `/v1.0/process-models/${params.process_model_id}/files`,
|
processModelFileCreatePath: `/v1.0/process-models/${params.process_model_id}/files`,
|
||||||
processModelFileShowPath: `/v1.0/process-models/${params.process_model_id}/files/${params.file_name}`,
|
processModelFileShowPath: `/v1.0/process-models/${params.process_model_id}/files/${params.file_name}`,
|
||||||
processInstanceListPath: `/v1.0/process-instances`,
|
processModelShowPath: `/v1.0/process-models/${params.process_model_id}`,
|
||||||
processInstanceActionPath: `/v1.0/process-models/${params.process_model_id}/process-instances`,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return { targetUris };
|
return { targetUris };
|
||||||
|
|
|
@ -23,6 +23,7 @@ import {
|
||||||
Stack,
|
Stack,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
} from '@carbon/react';
|
} from '@carbon/react';
|
||||||
|
import { Can } from '@casl/react';
|
||||||
import ProcessBreadcrumb from '../components/ProcessBreadcrumb';
|
import ProcessBreadcrumb from '../components/ProcessBreadcrumb';
|
||||||
import HttpService from '../services/HttpService';
|
import HttpService from '../services/HttpService';
|
||||||
import ReactDiagramEditor from '../components/ReactDiagramEditor';
|
import ReactDiagramEditor from '../components/ReactDiagramEditor';
|
||||||
|
@ -32,6 +33,9 @@ import {
|
||||||
} from '../helpers';
|
} from '../helpers';
|
||||||
import ButtonWithConfirmation from '../components/ButtonWithConfirmation';
|
import ButtonWithConfirmation from '../components/ButtonWithConfirmation';
|
||||||
import ErrorContext from '../contexts/ErrorContext';
|
import ErrorContext from '../contexts/ErrorContext';
|
||||||
|
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
|
||||||
|
import { PermissionsToCheck } from '../interfaces';
|
||||||
|
import { usePermissionFetcher } from '../hooks/PermissionService';
|
||||||
|
|
||||||
export default function ProcessInstanceShow() {
|
export default function ProcessInstanceShow() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
@ -50,6 +54,12 @@ export default function ProcessInstanceShow() {
|
||||||
);
|
);
|
||||||
const modifiedProcessModelId = params.process_model_id;
|
const modifiedProcessModelId = params.process_model_id;
|
||||||
|
|
||||||
|
const { targetUris } = useUriListForPermissions();
|
||||||
|
const permissionRequestData: PermissionsToCheck = {
|
||||||
|
[targetUris.messageInstanceListPath]: ['GET'],
|
||||||
|
};
|
||||||
|
const { ability } = usePermissionFetcher(permissionRequestData);
|
||||||
|
|
||||||
const navigateToProcessInstances = (_result: any) => {
|
const navigateToProcessInstances = (_result: any) => {
|
||||||
navigate(
|
navigate(
|
||||||
`/admin/process-instances?process_model_identifier=${unModifiedProcessModelId}`
|
`/admin/process-instances?process_model_identifier=${unModifiedProcessModelId}`
|
||||||
|
@ -63,12 +73,12 @@ export default function ProcessInstanceShow() {
|
||||||
});
|
});
|
||||||
if (typeof params.spiff_step === 'undefined')
|
if (typeof params.spiff_step === 'undefined')
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: `/process-instance/${params.process_instance_id}/tasks?all_tasks=true`,
|
path: `/process-instances/${modifiedProcessModelId}/${params.process_instance_id}/tasks?all_tasks=true`,
|
||||||
successCallback: setTasks,
|
successCallback: setTasks,
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: `/process-instance/${params.process_instance_id}/tasks?all_tasks=true&spiff_step=${params.spiff_step}`,
|
path: `/process-instances/${modifiedProcessModelId}/${params.process_instance_id}/tasks?all_tasks=true&spiff_step=${params.spiff_step}`,
|
||||||
successCallback: setTasks,
|
successCallback: setTasks,
|
||||||
});
|
});
|
||||||
}, [params, modifiedProcessModelId]);
|
}, [params, modifiedProcessModelId]);
|
||||||
|
@ -245,14 +255,20 @@ export default function ProcessInstanceShow() {
|
||||||
>
|
>
|
||||||
Logs
|
Logs
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Can
|
||||||
size="sm"
|
I="GET"
|
||||||
className="button-white-background"
|
a={targetUris.messageInstanceListPath}
|
||||||
data-qa="process-instance-message-instance-list-link"
|
ability={ability}
|
||||||
href={`/admin/messages?process_model_id=${params.process_model_id}&process_instance_id=${params.process_instance_id}`}
|
|
||||||
>
|
>
|
||||||
Messages
|
<Button
|
||||||
</Button>
|
size="sm"
|
||||||
|
className="button-white-background"
|
||||||
|
data-qa="process-instance-message-instance-list-link"
|
||||||
|
href={`/admin/messages?process_model_id=${params.process_model_id}&process_instance_id=${params.process_instance_id}`}
|
||||||
|
>
|
||||||
|
Messages
|
||||||
|
</Button>
|
||||||
|
</Can>
|
||||||
</ButtonSet>
|
</ButtonSet>
|
||||||
</Column>
|
</Column>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import ReactMarkdown from 'react-markdown';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
import HttpService from '../services/HttpService';
|
import HttpService from '../services/HttpService';
|
||||||
import ErrorContext from '../contexts/ErrorContext';
|
import ErrorContext from '../contexts/ErrorContext';
|
||||||
|
import { modifyProcessModelPath } from '../helpers';
|
||||||
|
|
||||||
export default function TaskShow() {
|
export default function TaskShow() {
|
||||||
const [task, setTask] = useState(null);
|
const [task, setTask] = useState(null);
|
||||||
|
@ -18,16 +19,22 @@ export default function TaskShow() {
|
||||||
const setErrorMessage = (useContext as any)(ErrorContext)[1];
|
const setErrorMessage = (useContext as any)(ErrorContext)[1];
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const processResult = (result: any) => {
|
||||||
|
setTask(result);
|
||||||
|
HttpService.makeCallToBackend({
|
||||||
|
path: `/process-instances/${modifyProcessModelPath(
|
||||||
|
result.process_model_identifier
|
||||||
|
)}/${params.process_instance_id}/tasks`,
|
||||||
|
successCallback: setUserTasks,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: `/tasks/${params.process_instance_id}/${params.task_id}`,
|
path: `/tasks/${params.process_instance_id}/${params.task_id}`,
|
||||||
successCallback: setTask,
|
successCallback: processResult,
|
||||||
// This causes the page to continuously reload
|
// This causes the page to continuously reload
|
||||||
// failureCallback: setErrorMessage,
|
// failureCallback: setErrorMessage,
|
||||||
});
|
});
|
||||||
HttpService.makeCallToBackend({
|
|
||||||
path: `/process-instance/${params.process_instance_id}/tasks`,
|
|
||||||
successCallback: setUserTasks,
|
|
||||||
});
|
|
||||||
}, [params]);
|
}, [params]);
|
||||||
|
|
||||||
const processSubmitResult = (result: any) => {
|
const processSubmitResult = (result: any) => {
|
||||||
|
|
Loading…
Reference in New Issue