look up human tasks with the guid instead of the task spec identifier w/ burnettk (#317)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2023-06-08 17:26:48 -04:00 committed by GitHub
parent febca3bc0b
commit 1a30ee6c69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 13 deletions

View File

@ -2385,7 +2385,7 @@ lxml = "*"
type = "git" type = "git"
url = "https://github.com/sartography/SpiffWorkflow" url = "https://github.com/sartography/SpiffWorkflow"
reference = "main" reference = "main"
resolved_reference = "01a25fc3f829786c4b65d19fd0fda408de37c79f" resolved_reference = "efcdcf545c861d58cfae92ad070b3208ef6028db"
[[package]] [[package]]
name = "sqlalchemy" name = "sqlalchemy"

View File

@ -278,9 +278,7 @@ def task_show(process_instance_id: int, task_guid: str = "next") -> flask.wrappe
can_complete = False can_complete = False
try: try:
AuthorizationService.assert_user_can_complete_task( AuthorizationService.assert_user_can_complete_task(process_instance.id, task_model.guid, g.user)
process_instance.id, task_definition.bpmn_identifier, g.user
)
can_complete = True can_complete = True
except HumanTaskNotFoundError: except HumanTaskNotFoundError:
can_complete = False can_complete = False
@ -483,7 +481,7 @@ def _task_submit_shared(
processor = ProcessInstanceProcessor(process_instance) processor = ProcessInstanceProcessor(process_instance)
spiff_task = _get_spiff_task_from_process_instance(task_guid, process_instance, processor=processor) spiff_task = _get_spiff_task_from_process_instance(task_guid, process_instance, processor=processor)
AuthorizationService.assert_user_can_complete_task(process_instance.id, spiff_task.task_spec.name, principal.user) AuthorizationService.assert_user_can_complete_task(process_instance.id, str(spiff_task.id), principal.user)
if spiff_task.state != TaskState.READY: if spiff_task.state != TaskState.READY:
raise ( raise (

View File

@ -336,24 +336,23 @@ class AuthorizationService:
@staticmethod @staticmethod
def assert_user_can_complete_task( def assert_user_can_complete_task(
process_instance_id: int, process_instance_id: int,
task_bpmn_identifier: str, task_guid: str,
user: UserModel, user: UserModel,
) -> bool: ) -> bool:
human_task = HumanTaskModel.query.filter_by( human_task = HumanTaskModel.query.filter_by(
task_name=task_bpmn_identifier, task_id=task_guid,
process_instance_id=process_instance_id, process_instance_id=process_instance_id,
completed=False, completed=False,
).first() ).first()
if human_task is None: if human_task is None:
raise HumanTaskNotFoundError( raise HumanTaskNotFoundError(
f"Could find an human task with task name '{task_bpmn_identifier}'" f"Could find an human task with task guid '{task_guid}' for process instance '{process_instance_id}'"
f" for process instance '{process_instance_id}'"
) )
if user not in human_task.potential_owners: if user not in human_task.potential_owners:
raise UserDoesNotHaveAccessToTaskError( raise UserDoesNotHaveAccessToTaskError(
f"User {user.username} does not have access to update" f"User {user.username} does not have access to update"
f" task'{task_bpmn_identifier}' for process instance" f" task'{task_guid}' for process instance"
f" '{process_instance_id}'" f" '{process_instance_id}'"
) )
return True return True

View File

@ -1556,7 +1556,16 @@ class ProcessInstanceProcessor:
task_guid=task_model.guid, task_guid=task_model.guid,
user_id=user.id, user_id=user.id,
) )
task_service.process_parents_and_children_and_save_to_database(spiff_task)
# children of a multi-instance task has the attribute "triggered" set to True
# so use that to determine if a spiff_task is apart of a multi-instance task
# and therefore we need to process its parent since the current task will not
# know what is actually going on.
# Basically "triggered" means "this task is not part of the task spec outputs"
spiff_task_to_process = spiff_task
if spiff_task_to_process.triggered is True:
spiff_task_to_process = spiff_task.parent
task_service.process_parents_and_children_and_save_to_database(spiff_task_to_process)
# this is the thing that actually commits the db transaction (on behalf of the other updates above as well) # this is the thing that actually commits the db transaction (on behalf of the other updates above as well)
self.save() self.save()

View File

@ -426,7 +426,7 @@ class ProcessInstanceService:
data: dict[str, Any], data: dict[str, Any],
user: UserModel, user: UserModel,
) -> None: ) -> None:
AuthorizationService.assert_user_can_complete_task(process_instance.id, spiff_task.task_spec.name, user) AuthorizationService.assert_user_can_complete_task(process_instance.id, str(spiff_task.id), user)
cls.save_file_data_and_replace_with_digest_references( cls.save_file_data_and_replace_with_digest_references(
data, data,
process_instance.id, process_instance.id,
@ -521,7 +521,7 @@ class ProcessInstanceService:
can_complete = False can_complete = False
try: try:
AuthorizationService.assert_user_can_complete_task( AuthorizationService.assert_user_can_complete_task(
processor.process_instance_model.id, spiff_task.task_spec.name, g.user processor.process_instance_model.id, str(spiff_task.id), g.user
) )
can_complete = True can_complete = True
except HumanTaskNotFoundError: except HumanTaskNotFoundError: