2018-06-17 20:14:46 +01:00
|
|
|
import textwrap
|
|
|
|
|
|
2018-05-27 23:32:18 +01:00
|
|
|
from django.conf import settings
|
2018-05-29 23:59:30 +02:00
|
|
|
from django.core.checks import Error, register
|
2020-12-16 18:40:19 +01:00
|
|
|
from django.core.exceptions import FieldError
|
2018-07-15 13:40:38 +02:00
|
|
|
from django.db.utils import OperationalError, ProgrammingError
|
2018-03-18 15:42:51 +00:00
|
|
|
|
2020-11-12 21:20:12 +01:00
|
|
|
from documents.signals import document_consumer_declaration
|
|
|
|
|
|
2018-03-18 15:42:51 +00:00
|
|
|
|
|
|
|
|
@register()
|
|
|
|
|
def changed_password_check(app_configs, **kwargs):
|
|
|
|
|
|
|
|
|
|
from documents.models import Document
|
|
|
|
|
from paperless.db import GnuPG
|
|
|
|
|
|
2018-05-27 14:28:41 +01:00
|
|
|
try:
|
2018-05-29 23:59:30 +02:00
|
|
|
encrypted_doc = Document.objects.filter(
|
2018-05-27 14:28:41 +01:00
|
|
|
storage_type=Document.STORAGE_TYPE_GPG).first()
|
2020-12-16 18:40:19 +01:00
|
|
|
except (OperationalError, ProgrammingError, FieldError):
|
2018-05-29 23:59:30 +02:00
|
|
|
return [] # No documents table yet
|
|
|
|
|
|
|
|
|
|
if encrypted_doc:
|
2018-06-17 20:14:46 +01:00
|
|
|
|
2018-05-29 23:59:30 +02:00
|
|
|
if not settings.PASSPHRASE:
|
|
|
|
|
return [Error(
|
|
|
|
|
"The database contains encrypted documents but no password "
|
|
|
|
|
"is set."
|
|
|
|
|
)]
|
2018-06-17 20:14:46 +01:00
|
|
|
|
|
|
|
|
if not GnuPG.decrypted(encrypted_doc.source_file):
|
2018-05-29 23:59:30 +02:00
|
|
|
return [Error(textwrap.dedent(
|
|
|
|
|
"""
|
|
|
|
|
The current password doesn't match the password of the
|
|
|
|
|
existing documents.
|
|
|
|
|
|
|
|
|
|
If you intend to change your password, you must first export
|
|
|
|
|
all of the old documents, start fresh with the new password
|
|
|
|
|
and then re-import them."
|
|
|
|
|
"""))]
|
2018-03-18 15:42:51 +00:00
|
|
|
|
|
|
|
|
return []
|
2020-11-12 21:20:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@register()
|
|
|
|
|
def parser_check(app_configs, **kwargs):
|
|
|
|
|
|
|
|
|
|
parsers = []
|
|
|
|
|
for response in document_consumer_declaration.send(None):
|
|
|
|
|
parsers.append(response[1])
|
|
|
|
|
|
|
|
|
|
if len(parsers) == 0:
|
|
|
|
|
return [Error("No parsers found. This is a bug. The consumer won't be "
|
2020-12-22 13:04:08 +01:00
|
|
|
"able to consume any documents without parsers.")]
|
2020-11-12 21:20:12 +01:00
|
|
|
else:
|
|
|
|
|
return []
|