delete human tasks when process instance is deleted w/ burnettk
This commit is contained in:
parent
1a71a44b5e
commit
626db0d780
|
@ -1,3 +1,5 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
import logging
|
||||
from logging.config import fileConfig
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: b7face8078df
|
||||
Revision ID: 907bcf0c3d75
|
||||
Revises:
|
||||
Create Date: 2022-12-22 21:12:03.739025
|
||||
Create Date: 2022-12-28 13:52:13.030028
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'b7face8078df'
|
||||
revision = '907bcf0c3d75'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
|
@ -60,10 +60,15 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel):
|
|||
process_initiator_id: int = db.Column(ForeignKey(UserModel.id), nullable=False)
|
||||
process_initiator = relationship("UserModel")
|
||||
|
||||
active_human_tasks = relationship(
|
||||
"HumanTaskModel",
|
||||
primaryjoin="and_(HumanTaskModel.process_instance_id==ProcessInstanceModel.id, HumanTaskModel.completed == False)",
|
||||
) # type: ignore
|
||||
|
||||
human_tasks = relationship(
|
||||
"HumanTaskModel",
|
||||
cascade="delete",
|
||||
primaryjoin="and_(HumanTaskModel.process_instance_id==ProcessInstanceModel.id, HumanTaskModel.completed == False)",
|
||||
overlaps="active_human_tasks",
|
||||
) # type: ignore
|
||||
message_instances = relationship("MessageInstanceModel", cascade="delete") # type: ignore
|
||||
message_correlations = relationship("MessageCorrelationModel", cascade="delete") # type: ignore
|
||||
|
|
|
@ -68,7 +68,7 @@ class TestGetLocaltime(BaseTest):
|
|||
processor = ProcessInstanceProcessor(process_instance)
|
||||
|
||||
processor.do_engine_steps(save=True)
|
||||
human_task = process_instance.human_tasks[0]
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
spiff_task = processor.__class__.get_task_by_bpmn_identifier(
|
||||
human_task.task_name, processor.bpmn_process_instance
|
||||
)
|
||||
|
@ -81,7 +81,7 @@ class TestGetLocaltime(BaseTest):
|
|||
human_task,
|
||||
)
|
||||
|
||||
human_task = process_instance.human_tasks[0]
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
spiff_task = processor.__class__.get_task_by_bpmn_identifier(
|
||||
human_task.task_name, processor.bpmn_process_instance
|
||||
)
|
||||
|
|
|
@ -125,7 +125,7 @@ class TestAuthorizationService(BaseTest):
|
|||
)
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
processor.do_engine_steps(save=True)
|
||||
human_task = process_instance.human_tasks[0]
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
spiff_task = processor.__class__.get_task_by_bpmn_identifier(
|
||||
human_task.task_name, processor.bpmn_process_instance
|
||||
)
|
||||
|
@ -133,7 +133,7 @@ class TestAuthorizationService(BaseTest):
|
|||
processor, spiff_task, {}, initiator_user, human_task
|
||||
)
|
||||
|
||||
human_task = process_instance.human_tasks[0]
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
spiff_task = processor.__class__.get_task_by_bpmn_identifier(
|
||||
human_task.task_name, processor.bpmn_process_instance
|
||||
)
|
||||
|
|
|
@ -31,10 +31,14 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
with_db_and_bpmn_file_cleanup: None,
|
||||
) -> None:
|
||||
"""Test_script_engine_takes_data_and_returns_expected_results."""
|
||||
app.config["THREAD_LOCAL_DATA"].process_model_identifier = 'hey'
|
||||
app.config["THREAD_LOCAL_DATA"].process_instance_id = 0
|
||||
script_engine = ProcessInstanceProcessor._script_engine
|
||||
|
||||
result = script_engine._evaluate("a", {"a": 1})
|
||||
assert result == 1
|
||||
app.config["THREAD_LOCAL_DATA"].process_model_identifier = None
|
||||
app.config["THREAD_LOCAL_DATA"].process_instance_id = None
|
||||
|
||||
def test_script_engine_can_use_custom_scripts(
|
||||
self,
|
||||
|
@ -42,12 +46,16 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
with_db_and_bpmn_file_cleanup: None,
|
||||
) -> None:
|
||||
"""Test_script_engine_takes_data_and_returns_expected_results."""
|
||||
app.config["THREAD_LOCAL_DATA"].process_model_identifier = 'hey'
|
||||
app.config["THREAD_LOCAL_DATA"].process_instance_id = 0
|
||||
script_engine = ProcessInstanceProcessor._script_engine
|
||||
result = script_engine._evaluate("fact_service(type='norris')", {})
|
||||
assert (
|
||||
result
|
||||
== "Chuck Norris doesn’t read books. He stares them down until he gets the information he wants."
|
||||
)
|
||||
app.config["THREAD_LOCAL_DATA"].process_model_identifier = None
|
||||
app.config["THREAD_LOCAL_DATA"].process_instance_id = None
|
||||
|
||||
def test_sets_permission_correctly_on_human_task(
|
||||
self,
|
||||
|
@ -80,8 +88,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
processor = ProcessInstanceProcessor(process_instance)
|
||||
processor.do_engine_steps(save=True)
|
||||
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
assert human_task.lane_assignment_id is None
|
||||
assert len(human_task.potential_owners) == 1
|
||||
assert human_task.potential_owners[0] == initiator_user
|
||||
|
@ -97,8 +105,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
processor, spiff_task, {}, initiator_user, human_task
|
||||
)
|
||||
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
assert human_task.lane_assignment_id == finance_group.id
|
||||
assert len(human_task.potential_owners) == 1
|
||||
assert human_task.potential_owners[0] == finance_user
|
||||
|
@ -114,8 +122,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
ProcessInstanceService.complete_form_task(
|
||||
processor, spiff_task, {}, finance_user, human_task
|
||||
)
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
assert human_task.lane_assignment_id is None
|
||||
assert len(human_task.potential_owners) == 1
|
||||
assert human_task.potential_owners[0] == initiator_user
|
||||
|
@ -163,8 +171,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
processor.do_engine_steps(save=True)
|
||||
processor.save()
|
||||
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
assert human_task.lane_assignment_id is None
|
||||
assert len(human_task.potential_owners) == 1
|
||||
assert human_task.potential_owners[0] == initiator_user
|
||||
|
@ -181,8 +189,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
)
|
||||
assert human_task.completed_by_user_id == initiator_user.id
|
||||
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
assert human_task.lane_assignment_id is None
|
||||
assert len(human_task.potential_owners) == 2
|
||||
assert human_task.potential_owners == [finance_user_three, finance_user_four]
|
||||
|
@ -200,8 +208,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
processor, spiff_task, {}, finance_user_three, human_task
|
||||
)
|
||||
assert human_task.completed_by_user_id == finance_user_three.id
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
assert human_task.lane_assignment_id is None
|
||||
assert len(human_task.potential_owners) == 1
|
||||
assert human_task.potential_owners[0] == finance_user_four
|
||||
|
@ -218,8 +226,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
processor, spiff_task, {}, finance_user_four, human_task
|
||||
)
|
||||
assert human_task.completed_by_user_id == finance_user_four.id
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
assert human_task.lane_assignment_id is None
|
||||
assert len(human_task.potential_owners) == 1
|
||||
assert human_task.potential_owners[0] == initiator_user
|
||||
|
@ -231,8 +239,8 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
processor, spiff_task, {}, initiator_user, human_task
|
||||
)
|
||||
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
human_task = process_instance.human_tasks[0]
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
human_task = process_instance.active_human_tasks[0]
|
||||
spiff_task = processor.__class__.get_task_by_bpmn_identifier(
|
||||
human_task.task_name, processor.bpmn_process_instance
|
||||
)
|
||||
|
@ -276,11 +284,11 @@ class TestProcessInstanceProcessor(BaseTest):
|
|||
)
|
||||
processor = ProcessInstanceProcessor(process_instance)
|
||||
processor.do_engine_steps(save=True)
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
initial_human_task_id = process_instance.human_tasks[0].id
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
initial_human_task_id = process_instance.active_human_tasks[0].id
|
||||
|
||||
# save again to ensure we go attempt to process the human tasks again
|
||||
processor.save()
|
||||
|
||||
assert len(process_instance.human_tasks) == 1
|
||||
assert initial_human_task_id == process_instance.human_tasks[0].id
|
||||
assert len(process_instance.active_human_tasks) == 1
|
||||
assert initial_human_task_id == process_instance.active_human_tasks[0].id
|
||||
|
|
Loading…
Reference in New Issue