mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Move the encrypt/decrypt decision out of db and into the view
This commit is contained in:
		| @@ -52,12 +52,12 @@ class FetchView(SessionOrBasicAuthMixin, DetailView): | |||||||
|  |  | ||||||
|         if self.kwargs["kind"] == "thumb": |         if self.kwargs["kind"] == "thumb": | ||||||
|             return HttpResponse( |             return HttpResponse( | ||||||
|                 GnuPG.decrypted(self.object.thumbnail_file), |                 self._get_raw_data(self.object.thumbnail_file), | ||||||
|                 content_type=content_types[Document.TYPE_PNG] |                 content_type=content_types[Document.TYPE_PNG] | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|         response = HttpResponse( |         response = HttpResponse( | ||||||
|             GnuPG.decrypted(self.object.source_file), |             self._get_raw_data(self.object.source_file), | ||||||
|             content_type=content_types[self.object.file_type] |             content_type=content_types[self.object.file_type] | ||||||
|         ) |         ) | ||||||
|         response["Content-Disposition"] = 'attachment; filename="{}"'.format( |         response["Content-Disposition"] = 'attachment; filename="{}"'.format( | ||||||
| @@ -65,6 +65,11 @@ class FetchView(SessionOrBasicAuthMixin, DetailView): | |||||||
|  |  | ||||||
|         return response |         return response | ||||||
|  |  | ||||||
|  |     def _get_raw_data(self, file_handle): | ||||||
|  |         if self.object.storage_type == Document.STORAGE_TYPE_UNENCRYPTED: | ||||||
|  |             return file_handle | ||||||
|  |         return GnuPG.decrypted(file_handle) | ||||||
|  |  | ||||||
|  |  | ||||||
| class PushView(SessionOrBasicAuthMixin, FormView): | class PushView(SessionOrBasicAuthMixin, FormView): | ||||||
|     """ |     """ | ||||||
|   | |||||||
| @@ -12,15 +12,11 @@ class GnuPG(object): | |||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def decrypted(cls, file_handle): |     def decrypted(cls, file_handle): | ||||||
|         if(not settings.ENABLE_ENCRYPTION): |  | ||||||
|             return file_handle.read() |  | ||||||
|         return cls.gpg.decrypt_file( |         return cls.gpg.decrypt_file( | ||||||
|             file_handle, passphrase=settings.PASSPHRASE).data |             file_handle, passphrase=settings.PASSPHRASE).data | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def encrypted(cls, file_handle): |     def encrypted(cls, file_handle): | ||||||
|         if(not settings.ENABLE_ENCRYPTION): |  | ||||||
|             return file_handle.read() |  | ||||||
|         return cls.gpg.encrypt_file( |         return cls.gpg.encrypt_file( | ||||||
|             file_handle, |             file_handle, | ||||||
|             recipients=None, |             recipients=None, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn