mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix: only check workflow trigger source if not empty (#5701)
This commit is contained in:
parent
6587470033
commit
4855f4b8b1
@ -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]}",
|
||||
|
@ -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
|
||||
|
@ -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="from@example.com",
|
||||
filter_to="someone@somewhere.com",
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user