All workflows types override previous

This commit is contained in:
shamoon 2023-12-27 09:06:09 -08:00
parent d127c37977
commit 5b95f0a2c6
5 changed files with 14 additions and 17 deletions

View File

@ -274,10 +274,9 @@ to workflow trigger 'types':
- Updated: fires when a document is updated. Similar to 'added' events, can include filtering by tags, doc type, or - Updated: fires when a document is updated. Similar to 'added' events, can include filtering by tags, doc type, or
correspondent correspondent
In general, workflows are applied sequentially (by sort order) but the behavior of consequtive workflows depends on the type. In general, workflow (and any actions they contain) are applied sequentially by sort order. Subsequent workflow actions will
"Consumption" workflows will never override an assignment from a preceding workflow. "Added" and "Updated" workflow triggers override assignments from a preceeding workflow except for assignments that accept multiple items e.g. tags, custom fields and
will overwrite these values (since these are immediately assigned to the document). Titles are always overwritten by permissions will be merged.
subsequent workflows. Assignments that accept multiple items e.g. tags, custom fields and permissions will be merged.
Workflows allow you to filter by: Workflows allow you to filter by:

View File

@ -603,13 +603,12 @@ class Consumer(LoggingMixin):
return document return document
def get_template_overrides( def get_workflow_overrides(
self, self,
input_doc: ConsumableDocument, input_doc: ConsumableDocument,
) -> DocumentMetadataOverrides: ) -> DocumentMetadataOverrides:
""" """
Match consumption templates to a document based on source and Get overrides from matching workflows
file name filters, path filters or mail rule filter if specified
""" """
overrides = DocumentMetadataOverrides() overrides = DocumentMetadataOverrides()
for workflow in Workflow.objects.filter(enabled=True).order_by("order"): for workflow in Workflow.objects.filter(enabled=True).order_by("order"):

View File

@ -33,21 +33,20 @@ class DocumentMetadataOverrides:
def update(self, other: "DocumentMetadataOverrides") -> "DocumentMetadataOverrides": def update(self, other: "DocumentMetadataOverrides") -> "DocumentMetadataOverrides":
""" """
Merges two DocumentMetadataOverrides objects such that object B's overrides Merges two DocumentMetadataOverrides objects such that object B's overrides
are only applied if the property is empty in object A or merged if multiple are applied to object A or merged if multiple are accepted.
are accepted.
The update is an in-place modification of self The update is an in-place modification of self
""" """
# only if empty # only if empty
if self.title is None: if other.title is not None:
self.title = other.title self.title = other.title
if self.correspondent_id is None: if other.correspondent_id is not None:
self.correspondent_id = other.correspondent_id self.correspondent_id = other.correspondent_id
if self.document_type_id is None: if other.document_type_id is not None:
self.document_type_id = other.document_type_id self.document_type_id = other.document_type_id
if self.storage_path_id is None: if other.storage_path_id is not None:
self.storage_path_id = other.storage_path_id self.storage_path_id = other.storage_path_id
if self.owner_id is None: if other.owner_id is not None:
self.owner_id = other.owner_id self.owner_id = other.owner_id
# merge # merge

View File

@ -158,7 +158,7 @@ def consume_file(
overrides.asn = reader.asn overrides.asn = reader.asn
logger.info(f"Found ASN in barcode: {overrides.asn}") logger.info(f"Found ASN in barcode: {overrides.asn}")
template_overrides = Consumer().get_template_overrides( template_overrides = Consumer().get_workflow_overrides(
input_doc=input_doc, input_doc=input_doc,
) )

View File

@ -244,7 +244,7 @@ class TestWorkflows(DirectoriesMixin, FileSystemAssertsMixin, APITestCase):
WHEN: WHEN:
- File that matches is consumed - File that matches is consumed
THEN: THEN:
- Template overrides are applied with subsequent templates only overwriting empty values - Template overrides are applied with subsequent templates overwriting previous values
or merging if multiple or merging if multiple
""" """
trigger1 = WorkflowTrigger.objects.create( trigger1 = WorkflowTrigger.objects.create(
@ -306,9 +306,9 @@ class TestWorkflows(DirectoriesMixin, FileSystemAssertsMixin, APITestCase):
m.assert_called_once() m.assert_called_once()
_, overrides = m.call_args _, overrides = m.call_args
# template 1 # template 1
self.assertEqual(overrides["override_correspondent_id"], self.c.pk)
self.assertEqual(overrides["override_document_type_id"], self.dt.pk) self.assertEqual(overrides["override_document_type_id"], self.dt.pk)
# template 2 # template 2
self.assertEqual(overrides["override_correspondent_id"], self.c2.pk)
self.assertEqual(overrides["override_storage_path_id"], self.sp.pk) self.assertEqual(overrides["override_storage_path_id"], self.sp.pk)
# template 1 & 2 # template 1 & 2
self.assertEqual( self.assertEqual(