From 3aafabba26b4b4e5361648da13b48376ffde1f35 Mon Sep 17 00:00:00 2001 From: CkuT Date: Fri, 30 Mar 2018 08:33:08 +0200 Subject: [PATCH] Fix LogEntry user when PAPERLESS_DISABLE_LOGIN is set to true --- .../migrations/0019_add_consumer_user.py | 25 +++++++++++++++++++ src/documents/signals/handlers.py | 2 +- src/documents/tests/test_matchables.py | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/documents/migrations/0019_add_consumer_user.py diff --git a/src/documents/migrations/0019_add_consumer_user.py b/src/documents/migrations/0019_add_consumer_user.py new file mode 100644 index 000000000..a3d7d787e --- /dev/null +++ b/src/documents/migrations/0019_add_consumer_user.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-07-15 17:12 +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from django.db import migrations + + +def forwards_func(apps, schema_editor): + User.objects.create(username="consumer") + + +def reverse_func(apps, schema_editor): + User.objects.get(username="consumer").delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('documents', '0018_auto_20170715_1712'), + ] + + operations = [ + migrations.RunPython(forwards_func, reverse_func), + ] diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index adc20ce6d..cdeaaba40 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -102,7 +102,7 @@ def cleanup_document_deletion(sender, instance, using, **kwargs): def set_log_entry(sender, document=None, logging_group=None, **kwargs): ct = ContentType.objects.get(model="document") - user = User.objects.first() + user = User.objects.get(username="consumer") LogEntry.objects.create( action_flag=ADDITION, diff --git a/src/documents/tests/test_matchables.py b/src/documents/tests/test_matchables.py index 94d6ee97a..55d25598a 100644 --- a/src/documents/tests/test_matchables.py +++ b/src/documents/tests/test_matchables.py @@ -210,7 +210,7 @@ class TestDocumentConsumptionFinishedSignal(TestCase): def setUp(self): TestCase.setUp(self) - User.objects.create_user(username='testuser', password='12345') + User.objects.create_user(username='test_consumer', password='12345') self.doc_contains = Document.objects.create( content="I contain the keyword.", file_type="pdf")