jgillula / paperless-ngx-postprocessor

A powerful and customizable postprocessing script for paperless-ngx
GNU Affero General Public License v3.0
96 stars 10 forks source link

User permissions (API token) #24

Open TristanPct opened 2 months ago

TristanPct commented 2 months ago

Hello and thank you for this tool!

What permissions are required for the user associated with the API key?

I tried with a new user giving him all documents | permissions but I have this error:

[2024-09-08 14:15:03,777] [INFO] [paperless.consumer] /usr/src/paperless-ngx-postprocessor/post_consume_script.sh exited 0
[2024-09-08 14:15:03,778] [INFO] [paperless.consumer] /usr/src/paperless-ngx-postprocessor/post_consume_script.sh stderr:
[2024-09-08 14:15:03,778] [WARNING] [paperless.consumer] [2024-09-08 14:15:02,979] [DEBUG] [paperlessngx_postprocessor] Running /usr/src/paperless-ngx-postprocessor/paperlessngx_postprocessor.py with config {'auth_token': '<redacted>', 'dry_run': False, 'skip_validation': False, 'backup': None, 'postprocessing_tag': None, 'invalid_tag': None, 'verbose': 'DEBUG', 'rulesets_dir': '/usr/src/paperless-ngx-postprocessor/rulesets.d', 'paperless_api_url': 'http://localhost:8000/api', 'paperless_src_dir': '/usr/src/paperless/src', 'mode': 'process', 'filename': None} and {'document_id': '174', 'correspondent': None, 'document_type': None, 'tag': None, 'storage_path': None, 'created_year': None, 'created_month': None, 'created_day': None, 'created_range': None, 'added_month': None, 'added_day': None, 'added_range': None, 'asn': None, 'title': None, 'all': False}
[2024-09-08 14:15:03,778] [WARNING] [paperless.consumer] [2024-09-08 14:15:02,982] [DEBUG] [postprocessor] Loaded 2 rules
[2024-09-08 14:15:03,779] [WARNING] [paperless.consumer] [2024-09-08 14:15:03,350] [INFO] [paperlessngx_postprocessor] Processing 1 documents.
[2024-09-08 14:15:03,779] [WARNING] [paperless.consumer] Traceback (most recent call last):
[2024-09-08 14:15:03,779] [WARNING] [paperless.consumer]   File "/usr/src/paperless-ngx-postprocessor/paperlessngx_postprocessor.py", line 128, in <module>
[2024-09-08 14:15:03,779] [WARNING] [paperless.consumer]     backup_documents = postprocessor.postprocess(documents)
[2024-09-08 14:15:03,780] [WARNING] [paperless.consumer]                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-09-08 14:15:03,780] [WARNING] [paperless.consumer]   File "/usr/src/paperless-ngx-postprocessor/paperlessngx_postprocessor/postprocessor.py", line 283, in postprocess
[2024-09-08 14:15:03,780] [WARNING] [paperless.consumer]     metadata_in_filename_format = self._api.get_metadata_in_filename_format(document)
[2024-09-08 14:15:03,780] [WARNING] [paperless.consumer]                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-09-08 14:15:03,780] [WARNING] [paperless.consumer]   File "/usr/src/paperless-ngx-postprocessor/paperlessngx_postprocessor/paperless_api.py", line 171, in get_metadata_in_filename_format
[2024-09-08 14:15:03,781] [WARNING] [paperless.consumer]     new_metadata["tag_list"] = [self.get_tag_by_id(tag)["name"] for tag in metadata["tags"]]
[2024-09-08 14:15:03,781] [WARNING] [paperless.consumer]                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-09-08 14:15:03,781] [WARNING] [paperless.consumer]   File "/usr/src/paperless-ngx-postprocessor/paperlessngx_postprocessor/paperless_api.py", line 171, in <listcomp>
[2024-09-08 14:15:03,781] [WARNING] [paperless.consumer]     new_metadata["tag_list"] = [self.get_tag_by_id(tag)["name"] for tag in metadata["tags"]]
[2024-09-08 14:15:03,782] [WARNING] [paperless.consumer]                                 ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
[2024-09-08 14:15:03,782] [WARNING] [paperless.consumer] KeyError: 'name'

If I attach my API key to my admin user, everything works fine.

jgillula commented 2 months ago

I've only ever tried with an admin user, myself. Given the description of the Global Permissions I would imagine you would also have to add the View permission for Correspondent, DocumentType, StoragePath, and Tag.

Let me know if that works or not. Once we narrow down the list I can add it to the documentation.