]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Enhancement: include DOCUMENT_TYPE to post consume scripts (#9977)
authormatthesrieke <m.rieke@52north.org>
Wed, 28 May 2025 23:32:59 +0000 (01:32 +0200)
committerGitHub <noreply@github.com>
Wed, 28 May 2025 23:32:59 +0000 (23:32 +0000)
* expose DOCUMENT_TYPE to post consume scripts

* Apply suggestions from code review

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
docs/advanced_usage.md
scripts/post-consumption-example.sh
src/documents/consumer.py
src/documents/tests/test_consumer.py

index 87f39795410c99cdad0428a093cd95e22bf6bc4a..aa52d2f5978f78778f76f23e369ff2a6443cafb6 100644 (file)
@@ -179,6 +179,7 @@ variables:
 | ---------------------------- | ---------------------------------------------- |
 | `DOCUMENT_ID`                | Database primary key of the document           |
 | `DOCUMENT_FILE_NAME`         | Formatted filename, not including paths        |
+| `DOCUMENT_TYPE`              | The document type (if any)                     |
 | `DOCUMENT_CREATED`           | Date & time when document created              |
 | `DOCUMENT_MODIFIED`          | Date & time when document was last modified    |
 | `DOCUMENT_ADDED`             | Date & time when document was added            |
index 154f9df71e111a35591e7f795e45d5c9b7570b8e..fbcd0b4cffb2cc7b71ed5a26fb3ea0ddfbac08e2 100755 (executable)
@@ -6,6 +6,7 @@ A document with an id of ${DOCUMENT_ID} was just consumed.  I know the
 following additional information about it:
 
 * Generated File Name: ${DOCUMENT_FILE_NAME}
+* Document type: ${DOCUMENT_TYPE}
 * Archive Path: ${DOCUMENT_ARCHIVE_PATH}
 * Source Path: ${DOCUMENT_SOURCE_PATH}
 * Created: ${DOCUMENT_CREATED}
index c78c21d37ea244f1000c6fc392e70896ca05f87b..7a57d2535f787a3c9995ff515f2de80cae3493ea 100644 (file)
@@ -303,6 +303,7 @@ class ConsumerPlugin(
         script_env = os.environ.copy()
 
         script_env["DOCUMENT_ID"] = str(document.pk)
+        script_env["DOCUMENT_TYPE"] = str(document.document_type)
         script_env["DOCUMENT_CREATED"] = str(document.created)
         script_env["DOCUMENT_MODIFIED"] = str(document.modified)
         script_env["DOCUMENT_ADDED"] = str(document.added)
index 370ff0ef661a9198299e553fcc22905bdcac57ed..3c17ddfaf82fc22a5dd59037e46feb5714a1312a 100644 (file)
@@ -1174,12 +1174,16 @@ class PostConsumeTestCase(DirectoriesMixin, GetConsumerMixin, TestCase):
                 m.assert_called_once()
 
     @mock.patch("documents.consumer.run_subprocess")
-    def test_post_consume_script_with_correspondent(self, m):
+    def test_post_consume_script_with_correspondent_and_type(self, m):
         with tempfile.NamedTemporaryFile() as script:
             with override_settings(POST_CONSUME_SCRIPT=script.name):
                 c = Correspondent.objects.create(name="my_bank")
+                t = DocumentType.objects.create(
+                    name="Test type",
+                )
                 doc = Document.objects.create(
                     title="Test",
+                    document_type=t,
                     mime_type="application/pdf",
                     correspondent=c,
                 )
@@ -1207,6 +1211,7 @@ class PostConsumeTestCase(DirectoriesMixin, GetConsumerMixin, TestCase):
 
                 subset = {
                     "DOCUMENT_ID": str(doc.pk),
+                    "DOCUMENT_TYPE": "Test type",
                     "DOCUMENT_DOWNLOAD_URL": f"/api/documents/{doc.pk}/download/",
                     "DOCUMENT_THUMBNAIL_URL": f"/api/documents/{doc.pk}/thumb/",
                     "DOCUMENT_CORRESPONDENT": "my_bank",