Merge branch 'dev' into dmn-from-spreadsheet-395

This commit is contained in:
mike cullerton 2021-09-09 13:09:35 -04:00
commit cc403f1fac
10 changed files with 682 additions and 317 deletions

View File

@ -1,7 +1,7 @@
language: python
python:
- "3.7"
- "3.8"
services:
- postgresql

17
Pipfile
View File

@ -12,7 +12,7 @@ coverage = "*"
alembic = "*"
coverage = "*"
docxtpl = "*"
flask = "*"
flask = "<2"
flask-admin = "*"
flask-bcrypt = "*"
flask-cors = "*"
@ -43,17 +43,10 @@ xlrd = "*"
xlsxwriter = "*"
pygithub = "*"
apscheduler = "*"
connexion = {extras = [ "swagger-ui",], version = "*"}
sentry-sdk = {extras = [ "flask",], version = "==0.14.4"}
spiffworkflow = {git = "https://github.com/sartography/SpiffWorkflow.git"}
dateparser = "*"
[requires]
python_version = "3.8"
[packages.connexion]
extras = [ "swagger-ui",]
version = "*"
[packages.sentry-sdk]
extras = [ "flask",]
version = "==0.14.4"
[packages.spiffworkflow]
git = "https://github.com/sartography/SpiffWorkflow.git"

773
Pipfile.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -111,7 +111,7 @@ def update_file_data(file_id):
file_model = session.query(FileModel).filter_by(id=file_id).with_for_update().first()
file = connexion.request.files['file']
if file_model is None:
raise ApiError('no_such_file', 'The file id you provided does not exist')
raise ApiError('no_such_file', f'The file id you provided ({file_id}) does not exist')
file_model = FileService.update_file(file_model, file.stream.read(), file.content_type)
return FileSchema().dump(to_file_api(file_model))
@ -122,7 +122,7 @@ def get_file_data_by_hash(md5_hash):
def get_file_data(file_id, version=None):
file_data = FileService.get_file_data(file_id, version)
if file_data is None:
raise ApiError('no_such_file', 'The file id you provided does not exist')
raise ApiError('no_such_file', f'The file id you provided ({file_id}) does not exist')
return send_file(
io.BytesIO(file_data.data),
attachment_filename=file_data.file_model.name,
@ -137,7 +137,7 @@ def get_file_data_link(file_id, auth_token, version=None):
raise ApiError('not_authenticated', 'You need to include an authorization token in the URL with this')
file_data = FileService.get_file_data(file_id, version)
if file_data is None:
raise ApiError('no_such_file', 'The file id you provided does not exist')
raise ApiError('no_such_file', f'The file id you provided ({file_id}) does not exist')
return send_file(
io.BytesIO(file_data.data),
attachment_filename=file_data.file_model.name,
@ -151,7 +151,7 @@ def get_file_data_link(file_id, auth_token, version=None):
def get_file_info(file_id):
file_model = session.query(FileModel).filter_by(id=file_id).with_for_update().first()
if file_model is None:
raise ApiError('no_such_file', 'The file id you provided does not exist', status_code=404)
raise ApiError('no_such_file', f'The file id you provided ({file_id}) does not exist', status_code=404)
return FileSchema().dump(to_file_api(file_model))

View File

@ -5,7 +5,8 @@ from pandas._libs.missing import NA
from crc import session, app
from crc.api.common import ApiError
from crc.models.file import FileModel, FileDataModel
from crc.models.workflow import WorkflowSpecModel, WorkflowSpecCategoryModel
from crc.models.workflow import WorkflowSpecModel, WorkflowSpecCategoryModel, WorkflowSpecCategoryModelSchema, \
WorkflowSpecModelSchema, WorkflowLibraryModel, WorkflowLibraryModelSchema
from crc.services.file_service import FileService
from crc.services.workflow_sync import WorkflowSyncService
from crc.api.workflow import get_workflow_specification
@ -134,40 +135,39 @@ def file_get(workflow_spec_id,filename):
FileModel.name == filename).first()
return currentfile
def create_or_update_local_spec(remote,workflow_spec_id):
specdict = WorkflowSyncService.get_remote_workflow_spec(remote, workflow_spec_id)
# if we are updating from a master spec, then we want to make sure it is the only
# master spec in our local system.
# master spec in our local system, turn all other master_specs off
if specdict['is_master_spec']:
masterspecs = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.is_master_spec == True).all()
for masterspec in masterspecs:
masterspec.is_master_spec = False
session.add(masterspec)
master_specs = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.is_master_spec == True).all()
for master_spec in master_specs:
master_spec.is_master_spec = False
session.add(master_spec)
localspec = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.id == workflow_spec_id).first()
if localspec is None:
localspec = WorkflowSpecModel()
localspec.id = workflow_spec_id
if specdict['category'] == None:
localspec.category = None
else:
localcategory = session.query(WorkflowSpecCategoryModel).filter(WorkflowSpecCategoryModel.name
== specdict['category']['name']).first()
if localcategory == None:
# category doesn't exist - lets make it
localcategory = WorkflowSpecCategoryModel()
localcategory.name = specdict['category']['name']
localcategory.display_name = specdict['category']['display_name']
localcategory.display_order = specdict['category']['display_order']
session.add(localcategory)
localspec.category = localcategory
# Update local_spec, or create a new one if one does not exist.
local_spec = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.id == workflow_spec_id).first()
local_spec = WorkflowSpecModelSchema().load(specdict, session=session, instance=local_spec)
localspec.display_order = specdict['display_order']
localspec.display_name = specdict['display_name']
localspec.name = specdict['name']
localspec.is_master_spec = specdict['is_master_spec']
localspec.description = specdict['description']
session.add(localspec)
# Set the category
if specdict['category'] is not None:
local_category = session.query(WorkflowSpecCategoryModel).\
filter(WorkflowSpecCategoryModel.name == specdict['category']['name']).first()
local_category = WorkflowSpecCategoryModelSchema().load(specdict['category'], session=session,
instance=local_category)
session.add(local_category)
local_spec.category = local_category
# Set the libraries
session.query(WorkflowLibraryModel).filter(WorkflowLibraryModel.workflow_spec_id == local_spec.id).delete()
for library in specdict['libraries']:
# Assure refernced libraries are local, and link them.
create_or_update_local_spec(remote, library['id'])
local_lib = WorkflowLibraryModel(workflow_spec_id=local_spec.id,
library_spec_id=library['id'])
session.add(local_lib)
session.add(local_spec)
def update_or_create_current_file(remote,workflow_spec_id,updatefile):
currentfile = file_get(workflow_spec_id, updatefile['filename'])

View File

@ -38,6 +38,7 @@ class Task(object):
FIELD_PROP_REPEAT = "repeat"
FIELD_PROP_READ_ONLY = "read_only"
FIELD_PROP_LDAP_LOOKUP = "ldap.lookup"
FIELD_PROP_READ_ONLY_EXPRESSION = "read_only_expression"
FIELD_PROP_HIDE_EXPRESSION = "hide_expression"
FIELD_PROP_REQUIRED_EXPRESSION = "required_expression"
FIELD_PROP_LABEL_EXPRESSION = "label_expression"

View File

@ -220,8 +220,9 @@ class WorkflowService(object):
# A task should only have default_value **or** value expression, not both.
if field.has_property(Task.FIELD_PROP_VALUE_EXPRESSION) and (hasattr(field, 'default_value') and field.default_value):
raise ApiError(code='default value and value_expression',
message='This task has both a default_value and value_expression. Please fix this to only have one or the other.')
raise ApiError.from_task(code='default value and value_expression',
message=f'This task ({task.get_name()}) has both a default_value and value_expression. Please fix this to only have one or the other.',
task=task)
# If we have a default_value or value_expression, try to set the default
if field.has_property(Task.FIELD_PROP_VALUE_EXPRESSION) or (hasattr(field, 'default_value') and field.default_value):
form_data[field.id] = WorkflowService.get_default_value(field, task)

View File

@ -0,0 +1,84 @@
<?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_0kwhkcg" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0">
<bpmn:process id="Process_09qy7hp" name="Test Default Value and Value Expression" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_0efs0fk</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_0efs0fk" sourceRef="StartEvent_1" targetRef="Task_0zremzf" />
<bpmn:userTask id="Task_0zremzf" name="Set Value Expression" camunda:formKey="valueExpression">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="value_expression_expression" label="Expression Value" type="string">
<camunda:validation>
<camunda:constraint name="required" config="True" />
</camunda:validation>
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_0efs0fk</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0wor210</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="SequenceFlow_0wor210" sourceRef="Task_0zremzf" targetRef="Task_GetName" />
<bpmn:userTask id="Task_GetName" name="Get Name" camunda:formKey="getName">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="name" label="Name" type="string" defaultValue="World">
<camunda:properties>
<camunda:property id="value_expression" value="value_expression_expression" />
</camunda:properties>
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_0wor210</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1fu62xl</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="SequenceFlow_1fu62xl" sourceRef="Task_GetName" targetRef="Task_1ncwuip" />
<bpmn:manualTask id="Task_1ncwuip" name="Say Hello">
<bpmn:documentation># Hello
Hello {{ name }}
</bpmn:documentation>
<bpmn:incoming>SequenceFlow_1fu62xl</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_15apauw</bpmn:outgoing>
</bpmn:manualTask>
<bpmn:endEvent id="EndEvent_1n2m3qs">
<bpmn:incoming>SequenceFlow_15apauw</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_15apauw" sourceRef="Task_1ncwuip" targetRef="EndEvent_1n2m3qs" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_09qy7hp">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0efs0fk_di" bpmnElement="SequenceFlow_0efs0fk">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_0mopxz9_di" bpmnElement="Task_0zremzf">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0wor210_di" bpmnElement="SequenceFlow_0wor210">
<di:waypoint x="370" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_14t3km3_di" bpmnElement="Task_GetName">
<dc:Bounds x="430" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1fu62xl_di" bpmnElement="SequenceFlow_1fu62xl">
<di:waypoint x="530" y="117" />
<di:waypoint x="590" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="ManualTask_0b4upj5_di" bpmnElement="Task_1ncwuip">
<dc:Bounds x="590" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_1n2m3qs_di" bpmnElement="EndEvent_1n2m3qs">
<dc:Bounds x="752" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_15apauw_di" bpmnElement="SequenceFlow_15apauw">
<di:waypoint x="690" y="117" />
<di:waypoint x="752" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -1,4 +1,6 @@
from unittest import mock
from unittest.mock import patch
from tests.base_test import BaseTest
from crc import db
@ -11,6 +13,7 @@ from crc.api.workflow_sync import get_all_spec_state, \
from crc.models.workflow import WorkflowSpecModel
from datetime import datetime
from crc.services.file_service import FileService
from crc.services.workflow_sync import WorkflowSyncService
def get_random_fact_pos(othersys):
"""
@ -141,6 +144,7 @@ class TestWorkflowSync(BaseTest):
self.assertEqual(remote_workflow['display_name'],'Random Fact')
remote_workflow['description'] = 'This Workflow came from Remote'
remote_workflow['display_name'] = 'Remote Workflow'
remote_workflow['library'] = True
workflow_mock.return_value = remote_workflow
# change the remote file date and hash
othersys = get_workflow_spec_files('random_fact')
@ -160,7 +164,45 @@ class TestWorkflowSync(BaseTest):
self.assertEqual('21bb6f9e-0af7-0ab2-0fc7-ec0f94787e58' in md5sums, True)
new_local_workflow = get_workflow_specification('random_fact')
self.assertEqual(new_local_workflow['display_name'],'Remote Workflow')
self.assertTrue(new_local_workflow['library'])
@patch('crc.services.workflow_sync.WorkflowSyncService.get_remote_file_by_hash')
@patch('crc.services.workflow_sync.WorkflowSyncService.get_remote_workflow_spec_files')
def test_workflow_sync_with_libraries(self, get_remote_workflow_spec_files_mock, get_remote_file_by_hash_mock):
self.load_example_data()
# make a remote workflow that is slightly different from local, and add a library to it.
remote_workflow = get_workflow_specification('random_fact')
remote_library = self.load_test_spec('two_forms')
remote_workflow['description'] = 'This Workflow came from Remote'
remote_workflow['libraries'] = [{'id': remote_library.id, 'name': 'two_forms', 'display_name': "Two Forms"}]
random_workflow_remote_files = get_workflow_spec_files('random_fact')
rf2pos = get_random_fact_2_pos(random_workflow_remote_files)
random_workflow_remote_files[rf2pos]['date_created'] = str(datetime.utcnow())
random_workflow_remote_files[rf2pos]['md5_hash'] = '12345'
get_remote_workflow_spec_files_mock.return_value = random_workflow_remote_files
get_remote_file_by_hash_mock.return_value = self.workflow_sync_response('random_fact2.bpmn')
# more mock stuff, but we need to return different things depending on what is asked, so we use the side
# effect pattern rather than setting a single return_value through a patch.
def mock_workflow_spec(*args):
if args[1] == 'random_fact':
return remote_workflow
else:
return get_workflow_specification(args[1])
with mock.patch.object(WorkflowSyncService, 'get_remote_workflow_spec', side_effect=mock_workflow_spec):
response = sync_changed_files('localhost:0000','random_fact') # endpoint not used due to mock
self.assertIsNotNone(response)
self.assertEqual(len(response),1)
self.assertEqual(response[0], 'random_fact2.bpmn')
files = FileService.get_spec_data_files('random_fact')
md5sums = [str(f.md5_hash) for f in files]
self.assertEqual('21bb6f9e-0af7-0ab2-0fc7-ec0f94787e58' in md5sums, True)
new_local_workflow = get_workflow_specification('random_fact')
self.assertEqual(new_local_workflow['display_name'],'Random Fact')
self.assertEqual(1, len(new_local_workflow['libraries']))
@patch('crc.services.workflow_sync.WorkflowSyncService.get_remote_file_by_hash')

View File

@ -33,3 +33,12 @@ class TestValueExpression(BaseTest):
self.assertEqual('black', second_task.data['value_expression_value'])
self.assertIn('color', second_task.data)
self.assertEqual('black', second_task.data['color']['value'])
def test_validate_task_with_both_default_and_expression(self):
# This actually fails validation.
# We are testing the error message is correct.
self.load_example_data()
spec_model = self.load_test_spec('default_value_expression')
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers())
self.assertEqual('default value and value_expression', rv.json[0]['code'])
self.assertIn('Task_GetName', rv.json[0]['message'])