mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Tweak the import/export system to handle encryption choices better
Now when you export a document, the `storage_type` value is always `unencrypted` (since that's what it is when it's exported anyway), and the flag is set by the importing script instead, based on the existence of a `PAPERLESS_PASSPHRASE` environment variable, indicating that encryption is enabled.
This commit is contained in:
		| @@ -55,7 +55,12 @@ class Command(Renderable, BaseCommand): | ||||
|         documents = Document.objects.all() | ||||
|         document_map = {d.pk: d for d in documents} | ||||
|         manifest = json.loads(serializers.serialize("json", documents)) | ||||
|         for document_dict in manifest: | ||||
|  | ||||
|         for index, document_dict in enumerate(manifest): | ||||
|  | ||||
|             # Force output to unencrypted as that will be the current state. | ||||
|             # The importer will make the decision to encrypt or not. | ||||
|             manifest[index]["fields"]["storage_type"] = Document.STORAGE_TYPE_UNENCRYPTED  # NOQA: E501 | ||||
|  | ||||
|             document = document_map[document_dict["pk"]] | ||||
|  | ||||
|   | ||||
| @@ -94,7 +94,7 @@ class Command(Renderable, BaseCommand): | ||||
|             document_path = os.path.join(self.source, doc_file) | ||||
|             thumbnail_path = os.path.join(self.source, thumb_file) | ||||
|  | ||||
|             if document.storage_type == Document.STORAGE_TYPE_GPG: | ||||
|             if settings.PASSPHRASE: | ||||
|  | ||||
|                 with open(document_path, "rb") as unencrypted: | ||||
|                     with open(document.source_path, "wb") as encrypted: | ||||
| @@ -112,3 +112,15 @@ class Command(Renderable, BaseCommand): | ||||
|  | ||||
|                 shutil.copy(document_path, document.source_path) | ||||
|                 shutil.copy(thumbnail_path, document.thumbnail_path) | ||||
|  | ||||
|         # Reset the storage type to whatever we've used while importing | ||||
|  | ||||
|         storage_type = Document.STORAGE_TYPE_UNENCRYPTED | ||||
|         if settings.PASSPHRASE: | ||||
|             storage_type = Document.STORAGE_TYPE_GPG | ||||
|  | ||||
|         Document.objects.filter( | ||||
|             pk__in=[r["pk"] for r in self.manifest] | ||||
|         ).update( | ||||
|             storage_type=storage_type | ||||
|         ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn