added endpoint for send-signal-event for users so we can handle permissions more easily w/ burnettk

This commit is contained in:
jasquat 2023-05-04 11:20:38 -04:00
parent 0b2b8a74d2
commit 8478c794e2
No known key found for this signature in database
6 changed files with 60 additions and 26 deletions

View File

@ -1588,9 +1588,9 @@ paths:
required: true
description: The unique id of the process instance
schema:
type: string
type: integer
post:
operationId: spiffworkflow_backend.routes.process_api_blueprint.send_bpmn_event
operationId: spiffworkflow_backend.routes.process_instances_controller.send_bpmn_event
summary: Send a BPMN event to the process
tags:
- Process Instances
@ -1779,6 +1779,27 @@ paths:
schema:
$ref: "#/components/schemas/OkTrue"
/tasks/{process_instance_id}/send-user-signal-event:
parameters:
- name: process_instance_id
in: path
required: true
description: The unique id of the process instance
schema:
type: integer
post:
operationId: spiffworkflow_backend.routes.process_instances_controller.send_user_signal_event
summary: Send a BPMN event to the process
tags:
- Process Instances
responses:
"200":
description: Event Sent Successfully
content:
application/json:
schema:
$ref: "#/components/schemas/Workflow"
/messages:
parameters:
- name: process_instance_id

View File

@ -189,25 +189,6 @@ def _get_required_parameter_or_raise(parameter: str, post_body: dict[str, Any])
return return_value
def send_bpmn_event(
modified_process_model_identifier: str,
process_instance_id: str,
body: Dict,
) -> Response:
"""Send a bpmn event to a workflow."""
process_instance = ProcessInstanceModel.query.filter(ProcessInstanceModel.id == int(process_instance_id)).first()
if process_instance:
processor = ProcessInstanceProcessor(process_instance)
processor.send_bpmn_event(body)
task = ProcessInstanceService.spiff_task_to_api_task(processor, processor.next_task())
return make_response(jsonify(task), 200)
else:
raise ApiError(
error_code="send_bpmn_event_error",
message=f"Could not send event to Instance: {process_instance_id}",
)
def _commit_and_push_to_git(message: str) -> None:
"""Commit_and_push_to_git."""
if current_app.config["SPIFFWORKFLOW_BACKEND_GIT_COMMIT_ON_SAVE"]:

View File

@ -642,6 +642,41 @@ def process_instance_find_by_id(
return make_response(jsonify(response_json), 200)
def send_user_signal_event(
process_instance_id: int,
body: Dict,
) -> Response:
"""Send a user signal event to a process instance."""
process_instance = _find_process_instance_for_me_or_raise(process_instance_id)
return _send_bpmn_event(process_instance, body)
def send_bpmn_event(
modified_process_model_identifier: str,
process_instance_id: int,
body: Dict,
) -> Response:
"""Send a bpmn event to a process instance."""
process_instance = ProcessInstanceModel.query.filter(ProcessInstanceModel.id == int(process_instance_id)).first()
if process_instance:
return _send_bpmn_event(process_instance, body)
else:
raise ApiError(
error_code="send_bpmn_event_error",
message=f"Could not send event to Instance: {process_instance_id}",
)
def _send_bpmn_event(
process_instance: ProcessInstanceModel,
body: dict
) -> Response:
processor = ProcessInstanceProcessor(process_instance)
processor.send_bpmn_event(body)
task = ProcessInstanceService.spiff_task_to_api_task(processor, processor.next_task())
return make_response(jsonify(task), 200)
def _get_process_instance(
modified_process_model_identifier: str,
process_instance: ProcessInstanceModel,

View File

@ -84,7 +84,6 @@ PATH_SEGMENTS_FOR_PERMISSION_ALL = [
{"path": "/process-instance-terminate", "relevant_permissions": ["create"]},
{"path": "/process-data", "relevant_permissions": ["read"]},
{"path": "/process-data-file-download", "relevant_permissions": ["read"]},
{"path": "/send-event", "relevant_permissions": ["create"]},
{"path": "/task-data", "relevant_permissions": ["read", "update"]},
]
@ -532,9 +531,8 @@ class AuthorizationService:
# we were thinking that if you can start an instance, you ought to be able to:
# 1. view your own instances.
# 2. view the logs for these instances.
# 3. click on buttons in user tasks that sends signal events to these instances
if permission_set == "start":
path_prefixes_that_allow_create_access = ["process-instances", "send-event"]
path_prefixes_that_allow_create_access = ["process-instances"]
for path_prefix in path_prefixes_that_allow_create_access:
target_uri = f"/{path_prefix}/{process_related_path_segment}"
permissions_to_assign.append(PermissionToAssign(permission="create", target_uri=target_uri))

View File

@ -125,7 +125,6 @@ class TestAuthorizationService(BaseTest):
expected_permissions = sorted(
[
("/event-error-details/some-process-group:some-process-model:*", "read"),
("/send-event/some-process-group:some-process-model:*", "create"),
("/logs/some-process-group:some-process-model:*", "read"),
("/logs/typeahead-filter-values/some-process-group:some-process-model:*", "read"),
("/process-data/some-process-group:some-process-model:*", "read"),

View File

@ -733,7 +733,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
if ('payload' in eventToSend)
eventToSend.payload = JSON.parse(eventPayload);
HttpService.makeCallToBackend({
path: `/send-event/${modifiedProcessModelId}/${params.process_instance_id}`,
path: targetUris.processInstanceSendEventPath,
httpMethod: 'POST',
successCallback: saveTaskDataResult,
failureCallback: addError,