Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: only check workflow trigger source if not empty (#5701)

shamoon4855f4b8b17d
diff --git a/src/documents/matching.py b/src/documents/matching.py
index 81154b8f4..6ffa1b3aa 100644
--- a/src/documents/matching.py
+++ b/src/documents/matching.py
@@ -258,7 +258,9 @@ def consumable_document_matches_workflow(
reason = ""
# Document source vs trigger source
- if document.source not in [int(x) for x in list(trigger.sources)]:
+ if len(trigger.sources) > 0 and document.source not in [
+ int(x) for x in list(trigger.sources)
+ ]:
reason = (
f"Document source {document.source.name} not in"
f" {[DocumentSource(int(x)).name for x in trigger.sources]}",
diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py
index 5fa104640..891891846 100644
--- a/src/documents/serialisers.py
+++ b/src/documents/serialisers.py
@@ -1410,9 +1410,6 @@ class WorkflowTriggerSerializer(serializers.ModelSerializer):
]
def validate(self, attrs):
- if ("filter_mailrule") in attrs and attrs["filter_mailrule"] is not None:
- attrs["sources"] = {DocumentSource.MailFetch.value}
-
# Empty strings treated as None to avoid unexpected behavior
if (
"filter_filename" in attrs
diff --git a/src/documents/tests/test_api_workflows.py b/src/documents/tests/test_api_workflows.py
index 21e887c24..0751d0df5 100644
--- a/src/documents/tests/test_api_workflows.py
+++ b/src/documents/tests/test_api_workflows.py
@@ -15,8 +15,6 @@ from documents.models import Workflow
from documents.models import WorkflowAction
from documents.models import WorkflowTrigger
from documents.tests.utils import DirectoriesMixin
-from paperless_mail.models import MailAccount
-from paperless_mail.models import MailRule
class TestApiWorkflows(DirectoriesMixin, APITestCase):
@@ -344,56 +342,6 @@ class TestApiWorkflows(DirectoriesMixin, APITestCase):
self.assertEqual(trigger2.filter_path, "*/test/*")
self.assertIsNone(trigger2.filter_filename)
- def test_api_create_workflow_trigger_with_mailrule(self):
- """
- GIVEN:
- - API request to create a workflow trigger with a mail rule but no MailFetch source
- WHEN:
- - API is called
- THEN:
- - New trigger is created with MailFetch as source
- """
- account1 = MailAccount.objects.create(
- name="Email1",
- username="username1",
- password="password1",
- imap_server="server.example.com",
- imap_port=443,
- imap_security=MailAccount.ImapSecurity.SSL,
- character_set="UTF-8",
- )
- rule1 = MailRule.objects.create(
- name="Rule1",
- account=account1,
- folder="INBOX",
- filter_from="[email protected]",
- filter_to="[email protected]",
- filter_subject="subject",
- filter_body="body",
- filter_attachment_filename_include="file.pdf",
- maximum_age=30,
- action=MailRule.MailAction.MARK_READ,
- assign_title_from=MailRule.TitleSource.FROM_SUBJECT,
- assign_correspondent_from=MailRule.CorrespondentSource.FROM_NOTHING,
- order=0,
- attachment_type=MailRule.AttachmentProcessing.ATTACHMENTS_ONLY,
- )
- response = self.client.post(
- self.ENDPOINT_TRIGGERS,
- json.dumps(
- {
- "type": WorkflowTrigger.WorkflowTriggerType.CONSUMPTION,
- "sources": [DocumentSource.ApiUpload],
- "filter_mailrule": rule1.pk,
- },
- ),
- content_type="application/json",
- )
- self.assertEqual(response.status_code, status.HTTP_201_CREATED)
- self.assertEqual(WorkflowTrigger.objects.count(), 2)
- trigger = WorkflowTrigger.objects.get(id=response.data["id"])
- self.assertEqual(trigger.sources, [int(DocumentSource.MailFetch).__str__()])
-
def test_api_update_workflow_nested_triggers_actions(self):
"""
GIVEN: