mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Change: enable auditlog by default, fix import / export (#6267)
This commit is contained in:
@@ -9,6 +9,9 @@ from typing import Optional
|
||||
|
||||
import tqdm
|
||||
from django.conf import settings
|
||||
|
||||
if settings.AUDIT_LOG_ENABLED:
|
||||
from auditlog.models import LogEntry
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.auth.models import User
|
||||
@@ -307,6 +310,11 @@ class Command(BaseCommand):
|
||||
serializers.serialize("json", ApplicationConfiguration.objects.all()),
|
||||
)
|
||||
|
||||
if settings.AUDIT_LOG_ENABLED:
|
||||
manifest += json.loads(
|
||||
serializers.serialize("json", LogEntry.objects.all()),
|
||||
)
|
||||
|
||||
# These are treated specially and included in the per-document manifest
|
||||
# if that setting is enabled. Otherwise, they are just exported to the bulk
|
||||
# manifest
|
||||
|
@@ -21,7 +21,13 @@ from django.db.models.signals import post_save
|
||||
from filelock import FileLock
|
||||
|
||||
from documents.file_handling import create_source_path_directory
|
||||
from documents.models import Correspondent
|
||||
from documents.models import CustomField
|
||||
from documents.models import CustomFieldInstance
|
||||
from documents.models import Document
|
||||
from documents.models import DocumentType
|
||||
from documents.models import Note
|
||||
from documents.models import Tag
|
||||
from documents.parsers import run_convert
|
||||
from documents.settings import EXPORTER_ARCHIVE_NAME
|
||||
from documents.settings import EXPORTER_FILE_NAME
|
||||
@@ -30,6 +36,9 @@ from documents.signals.handlers import update_filename_and_move_files
|
||||
from documents.utils import copy_file_with_basic_stats
|
||||
from paperless import version
|
||||
|
||||
if settings.AUDIT_LOG_ENABLED:
|
||||
from auditlog.registry import auditlog
|
||||
|
||||
|
||||
@contextmanager
|
||||
def disable_signal(sig, receiver, sender):
|
||||
@@ -151,6 +160,15 @@ class Command(BaseCommand):
|
||||
receiver=update_filename_and_move_files,
|
||||
sender=Document.tags.through,
|
||||
):
|
||||
if settings.AUDIT_LOG_ENABLED:
|
||||
auditlog.unregister(Document)
|
||||
auditlog.unregister(Correspondent)
|
||||
auditlog.unregister(Tag)
|
||||
auditlog.unregister(DocumentType)
|
||||
auditlog.unregister(Note)
|
||||
auditlog.unregister(CustomField)
|
||||
auditlog.unregister(CustomFieldInstance)
|
||||
|
||||
# Fill up the database with whatever is in the manifest
|
||||
try:
|
||||
with transaction.atomic():
|
||||
|
@@ -780,3 +780,17 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
|
||||
self.assertEqual(ContentType.objects.count(), num_content_type_objects)
|
||||
self.assertEqual(Permission.objects.count(), num_permission_objects + 1)
|
||||
|
||||
def test_exporter_with_auditlog_disabled(self):
|
||||
shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
|
||||
shutil.copytree(
|
||||
os.path.join(os.path.dirname(__file__), "samples", "documents"),
|
||||
os.path.join(self.dirs.media_dir, "documents"),
|
||||
)
|
||||
|
||||
with override_settings(
|
||||
AUDIT_LOG_ENABLED=False,
|
||||
):
|
||||
manifest = self._do_export(use_filename_format=True)
|
||||
for obj in manifest:
|
||||
self.assertNotEqual(obj["model"], "auditlog.logentry")
|
||||
|
Reference in New Issue
Block a user