Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Add check for changed password

Daniel Quinnf72fa43e8691
diff --git a/src/documents/__init__.py b/src/documents/__init__.py
index e69de29bb..864b5f5fe 100644
--- a/src/documents/__init__.py
+++ b/src/documents/__init__.py
@@ -0,0 +1 @@
+from .checks import changed_password_check
diff --git a/src/documents/checks.py b/src/documents/checks.py
new file mode 100644
index 000000000..b3b8729c4
--- /dev/null
+++ b/src/documents/checks.py
@@ -0,0 +1,26 @@
+from django.core.checks import Warning, register
+
+
+@register()
+def changed_password_check(app_configs, **kwargs):
+
+ from documents.models import Document
+ from paperless.db import GnuPG
+
+ warning = (
+ "At least one document:\n\n {}\n\nin your data store was encrypted "
+ "with a password other than the one currently\nin use. This means "
+ "that this file, and others encrypted with the other\npassword are no "
+ "longer acessible, which is probably not what you want. If\nyou "
+ "intend to change your Paperless password, you must first export all "
+ "of\nthe old documents, start fresh with the new password and then "
+ "re-import them."
+ )
+
+ document = Document.objects.order_by("-pk").filter(
+ storage_type=Document.STORAGE_TYPE_GPG
+ ).first()
+
+ if document and not GnuPG.decrypted(document.source_file):
+ return [Warning(warning.format(document))]
+ return []
diff --git a/src/documents/tests/test_checks.py b/src/documents/tests/test_checks.py
new file mode 100644
index 000000000..da3a4adf0
--- /dev/null
+++ b/src/documents/tests/test_checks.py
@@ -0,0 +1,25 @@
+import unittest
+
+from django.test import TestCase
+
+from ..checks import changed_password_check
+from ..models import Document
+from .factories import DocumentFactory
+
+
+class ChecksTestCase(TestCase):
+
+ def test_changed_password_check_empty_db(self):
+ self.assertEqual(changed_password_check(None), [])
+
+ def test_changed_password_check_no_encryption(self):
+ DocumentFactory.create(storage_type=Document.STORAGE_TYPE_UNENCRYPTED)
+ self.assertEqual(changed_password_check(None), [])
+
+ @unittest.skip("I don't know how to test this")
+ def test_changed_password_check_gpg_encryption_with_good_password(self):
+ pass
+
+ @unittest.skip("I don't know how to test this")
+ def test_changed_password_check_fail(self):
+ pass