Merge pull request #197 from sartography/token_reset_message

Token reset message
This commit is contained in:
Dan Funk 2020-11-18 18:17:59 -05:00 committed by GitHub
commit f98d919bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 187 additions and 27 deletions

View File

@ -39,7 +39,7 @@ requests = "*"
sentry-sdk = {extras = ["flask"],version = "==0.14.4"}
sphinx = "*"
swagger-ui-bundle = "*"
spiffworkflow = {git = "https://github.com/sartography/SpiffWorkflow.git",ref = "master"}
spiffworkflow = {git = "https://github.com/sartography/SpiffWorkflow.git",ref = "cancel-event"}
webtest = "*"
werkzeug = "*"
xlrd = "*"

52
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "621d57ec513f24c665dd34e08ae5a19fc27784e87c55bb4d2a91a1d48a473081"
"sha256": "263e8627b483ddc81a2016eb4da3e6738140b449c9c4be13a7a62a9191f171cd"
},
"pipfile-spec": 6,
"requires": {
@ -47,10 +47,10 @@
},
"babel": {
"hashes": [
"sha256:1aac2ae2d0d8ea368fa90906567f5c08463d98ade155c0c4bfedd6a0f7160e38",
"sha256:d670ea0b10f8b723672d3a6abeb87b565b244da220d76b4dba1b66269ec152d4"
"sha256:9d35c22fcc79893c3ecc85ac4a56cde1ecf3f19c540bba0922308a6c06ca6fa5",
"sha256:da031ab54472314f210b0adcff1588ee5d1d1d0ba4dbd07b94dba82bde791e05"
],
"version": "==2.8.0"
"version": "==2.9.0"
},
"bcrypt": {
"hashes": [
@ -80,10 +80,10 @@
},
"certifi": {
"hashes": [
"sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3",
"sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41"
"sha256:1f422849db327d534e3d0c5f02a263458c3955ec0aae4ff09b95f195c59f4edd",
"sha256:f05def092c44fbf25834a51509ef6e631dc19765ab8a57b4e7ab85531f0a9cf4"
],
"version": "==2020.6.20"
"version": "==2020.11.8"
},
"cffi": {
"hashes": [
@ -221,11 +221,11 @@
},
"docxtpl": {
"hashes": [
"sha256:5c98ea92ce31bcf24357a03d193d5096f16b9618d2d6b9b3f8fff01a4081eaf0",
"sha256:b5f1823de88b1762cfb1fa86fed6e088ab87aa22f7c157b23b2d1bffb38272f9"
"sha256:aa12f454f798daa43b52c41f1c90f890f0405b128f1dadd5aeee501d7e347855",
"sha256:dd2fc41f682c0d8f9e8479af167b3b8e781cc0a7b343af37a9a5aaff6dd035d7"
],
"index": "pypi",
"version": "==0.11.1"
"version": "==0.11.2"
},
"et-xmlfile": {
"hashes": [
@ -471,11 +471,11 @@
},
"marshmallow": {
"hashes": [
"sha256:4bc31ab18133083b12893c61f2fc38b93c390d3fd6ae2ac61980b7dc936a1afa",
"sha256:97ad6acaf727be986330969cff16040fce051510759ca709de9cd48093c55d04"
"sha256:73facc37462dfc0b27f571bdaffbef7709e19f7a616beb3802ea425b07843f4e",
"sha256:e26763201474b588d144dae9a32bdd945cd26a06c943bc746a6882e850475378"
],
"index": "pypi",
"version": "==3.9.0"
"version": "==3.9.1"
},
"marshmallow-enum": {
"hashes": [
@ -487,11 +487,11 @@
},
"marshmallow-sqlalchemy": {
"hashes": [
"sha256:098d4486374d0c63b4a947269c36d8850eedf35c59f172c5a1da28c070af64f4",
"sha256:cf0c7fead0b30ad66892a0cefcb39151591842ab16ca48ffa5bd816719b2491e"
"sha256:93f47b880ac7070f7b34c8ac0a71eeec3f8582a22e5c0330c1c436e3f5f99a37",
"sha256:d051cf013c075c43e1ee5c4b01f8fab6dd6b140dab6825be45875f674a0d289c"
],
"index": "pypi",
"version": "==0.24.0"
"version": "==0.24.1"
},
"numpy": {
"hashes": [
@ -746,11 +746,11 @@
},
"requests": {
"hashes": [
"sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b",
"sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"
"sha256:7f1a0b932f4a60a1a65caa4263921bb7d9ee911957e0ae4a23a6dd08185ad5f8",
"sha256:e786fa28d8c9154e6a4de5d46a1d921b8749f8b74e28bde23768e5e16eece998"
],
"index": "pypi",
"version": "==2.24.0"
"version": "==2.25.0"
},
"sentry-sdk": {
"extras": [
@ -787,11 +787,11 @@
},
"sphinx": {
"hashes": [
"sha256:1c21e7c5481a31b531e6cbf59c3292852ccde175b504b00ce2ff0b8f4adc3649",
"sha256:3abdb2c57a65afaaa4f8573cbabd5465078eb6fd282c1e4f87f006875a7ec0c7"
"sha256:1e8d592225447104d1172be415bc2972bd1357e3e12fdc76edf2261105db4300",
"sha256:d4e59ad4ea55efbb3c05cde3bfc83bfc14f0c95aa95c3d75346fcce186a47960"
],
"index": "pypi",
"version": "==3.3.0"
"version": "==3.3.1"
},
"sphinxcontrib-applehelp": {
"hashes": [
@ -837,7 +837,7 @@
},
"spiffworkflow": {
"git": "https://github.com/sartography/SpiffWorkflow.git",
"ref": "a1d5c2feedc2a9490110d5a182ee260c76ed6e66"
"ref": "54c75ba9503a3e4bded34da7ed2d87b2a6b3e6cb"
},
"sqlalchemy": {
"hashes": [
@ -892,10 +892,10 @@
},
"urllib3": {
"hashes": [
"sha256:8d7eaa5a82a1cac232164990f04874c594c9453ec55eef02eab885aa02fc17a2",
"sha256:f5321fbe4bf3fefa0efd0bfe7fb14e90909eb62a48ccda331726b4319897dd5e"
"sha256:19188f96923873c92ccb987120ec4acaa12f0461fa9ce5d3d0772bc965a39e08",
"sha256:d8ff90d979214d7b4f8ce956e80f4028fc6860e4431f731ea4a8c08f23f99473"
],
"version": "==1.25.11"
"version": "==1.26.2"
},
"waitress": {
"hashes": [

View File

@ -147,6 +147,9 @@ def set_current_task(workflow_id, task_id):
raise ApiError("invalid_state", "You may not move the token to a task who's state is not "
"currently set to COMPLETE or READY.")
# If we have an interrupt task, run it.
processor.bpmn_workflow.cancel_notify()
# Only reset the token if the task doesn't already have it.
if spiff_task.state == spiff_task.COMPLETED:
spiff_task.reset_token(reset_data=True) # Don't try to copy the existing data back into this task.

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0a9entn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.7.3">
<bpmn:process id="Process_1dagb7t" name="TestMessage" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Start">
<bpmn:outgoing>Flow_0xym55y</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_16q1uec" name="TestMessageFlow" sourceRef="Event_TokenReset" targetRef="Activity_TestMessage" />
<bpmn:scriptTask id="Activity_TestMessage" name="Test Message" camunda:resultVariable="test_message">
<bpmn:incoming>Flow_16q1uec</bpmn:incoming>
<bpmn:script>update_study("title:'New Title'")
print('New Title')</bpmn:script>
</bpmn:scriptTask>
<bpmn:userTask id="Activity_GetData" name="GetData" camunda:formKey="FirstTaskForm">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="formdata" label="Gimme some data" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1rvh899</bpmn:incoming>
<bpmn:outgoing>Flow_1n1fs6z</bpmn:outgoing>
</bpmn:userTask>
<bpmn:scriptTask id="Activity_PrintData" name="PrintData">
<bpmn:incoming>Flow_07i0gvv</bpmn:incoming>
<bpmn:outgoing>Flow_1c2tudh</bpmn:outgoing>
<bpmn:script>[print(formdata) for _ in range(how_many)]
printdata = formdata</bpmn:script>
</bpmn:scriptTask>
<bpmn:endEvent id="Event_1b8jy9y" name="EndEvent">
<bpmn:incoming>Flow_1c2tudh</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1c2tudh" sourceRef="Activity_PrintData" targetRef="Event_1b8jy9y" />
<bpmn:sequenceFlow id="Flow_0xym55y" sourceRef="StartEvent_1" targetRef="Activity_Hello" />
<bpmn:sequenceFlow id="Flow_1rvh899" sourceRef="Activity_Hello" targetRef="Activity_GetData" />
<bpmn:scriptTask id="Activity_Hello" name="Hello">
<bpmn:incoming>Flow_0xym55y</bpmn:incoming>
<bpmn:outgoing>Flow_1rvh899</bpmn:outgoing>
<bpmn:script>print('Hello'); printdata=''; test_message=''</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1n1fs6z" sourceRef="Activity_GetData" targetRef="Activity_HowMany" />
<bpmn:userTask id="Activity_HowMany" name="HowMany" camunda:formKey="HowMany">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="how_many" label="How many?" type="long" defaultValue="1" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1n1fs6z</bpmn:incoming>
<bpmn:outgoing>Flow_07i0gvv</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="Flow_07i0gvv" sourceRef="Activity_HowMany" targetRef="Activity_PrintData" />
<bpmn:boundaryEvent id="Event_TokenReset" name="TokenReset" attachedToRef="Activity_HowMany">
<bpmn:outgoing>Flow_16q1uec</bpmn:outgoing>
<bpmn:cancelEventDefinition id="CancelEventDefinition_1d5hszc" />
</bpmn:boundaryEvent>
</bpmn:process>
<bpmn:message id="Message_0iyvlbz" name="token_reset" />
<bpmn:message id="Message_1ow6ruy" name="Message_00ldv4i" />
<bpmn:signal id="Signal_1fbgshz" name="token_reset" />
<bpmn:message id="Message_1czi5ye" name="token_reset" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1dagb7t">
<bpmndi:BPMNEdge id="Flow_07i0gvv_di" bpmnElement="Flow_07i0gvv">
<di:waypoint x="650" y="117" />
<di:waypoint x="720" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1n1fs6z_di" bpmnElement="Flow_1n1fs6z">
<di:waypoint x="490" y="117" />
<di:waypoint x="550" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1rvh899_di" bpmnElement="Flow_1rvh899">
<di:waypoint x="330" y="117" />
<di:waypoint x="390" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0xym55y_di" bpmnElement="Flow_0xym55y">
<di:waypoint x="188" y="117" />
<di:waypoint x="230" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1c2tudh_di" bpmnElement="Flow_1c2tudh">
<di:waypoint x="820" y="117" />
<di:waypoint x="862" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_16q1uec_di" bpmnElement="Flow_16q1uec">
<di:waypoint x="600" y="175" />
<di:waypoint x="600" y="269" />
<bpmndi:BPMNLabel>
<dc:Bounds x="605" y="222" width="89" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="152" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="158" y="142" width="24" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0bieozg_di" bpmnElement="Activity_TestMessage">
<dc:Bounds x="550" y="269" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_04w71at_di" bpmnElement="Activity_GetData">
<dc:Bounds x="390" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1xlnpzi_di" bpmnElement="Activity_PrintData">
<dc:Bounds x="720" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1b8jy9y_di" bpmnElement="Event_1b8jy9y">
<dc:Bounds x="862" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="857" y="142" width="48" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1jj0s1n_di" bpmnElement="Activity_Hello">
<dc:Bounds x="230" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0hkt70o_di" bpmnElement="Activity_HowMany">
<dc:Bounds x="550" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1yxxtrb_di" bpmnElement="Event_TokenReset">
<dc:Bounds x="582" y="139" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="610" y="173" width="59" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,34 @@
from tests.base_test import BaseTest
from crc.models.study import StudyModel
from crc import db
class TestMessageEvent(BaseTest):
def test_message_event(self):
workflow = self.create_workflow('message_event')
study_id = workflow.study_id
# Start the workflow.
first_task = self.get_workflow_api(workflow).next_task
self.assertEqual('Activity_GetData', first_task.name)
workflow = self.get_workflow_api(workflow)
self.complete_form(workflow, first_task, {'formdata': 'asdf'})
workflow = self.get_workflow_api(workflow)
self.assertEqual('Activity_HowMany', workflow.next_task.name)
# reset the workflow
# this ultimately calls crc.api.workflow.set_current_task
self.app.put('/v1.0/workflow/%i/task/%s/set_token' % (
workflow.id,
first_task.id),
headers=self.logged_in_headers(),
content_type="application/json")
# set_current_task should call the interupt (signal) task
# which should run the script in our task
#
# test to see if our changes made it to the DB
study_result = db.session.query(StudyModel).filter(StudyModel.id == study_id).first()
self.assertEqual('New Title', study_result.title)