From 5662035efdb788c0511c68433463a879b9822da4 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Tue, 23 Aug 2016 15:54:09 +0100 Subject: [PATCH 01/10] Fixed an ugly bug that broke all deletions --- src/documents/signals/handlers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index 666bcbeb3..a4096154b 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -5,7 +5,7 @@ from subprocess import Popen from django.conf import settings -from ..models import Correspondent, Tag +from ..models import Correspondent, Document, Tag def logger(message, group): @@ -85,6 +85,10 @@ def run_post_consume_script(sender, document, **kwargs): def cleanup_document_deletion(sender, instance, using, **kwargs): + + if not isinstance(instance, Document): + return + for f in (instance.source_path, instance.thumbnail_path): try: os.unlink(f) From 7b8914132d563a1cccc767a8ab0997cb40390463 Mon Sep 17 00:00:00 2001 From: Jeff Bogatay Date: Tue, 23 Aug 2016 12:18:28 -0400 Subject: [PATCH 02/10] Make database location variable --- src/paperless/settings.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index c80434bc7..1e946d0b0 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -31,6 +31,11 @@ LOGIN_URL = '/admin/login' ALLOWED_HOSTS = [] +# Tap paperless.conf if it's available +if os.path.exists("/etc/paperless.conf"): + load_dotenv("/etc/paperless.conf") + + # Application definition @@ -90,9 +95,10 @@ WSGI_APPLICATION = 'paperless.wsgi.application' DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "..", "data", "db.sqlite3"), + "NAME": os.path.join(os.getenv("PAPERLESS_DBLOCATION",os.path.join(BASE_DIR, "..", "data")), "db.sqlite3") } } +print(DATABASES) if os.getenv("PAPERLESS_DBUSER") and os.getenv("PAPERLESS_DBPASS"): DATABASES["default"] = { "ENGINE": "django.db.backends.postgresql_psycopg2", @@ -150,11 +156,6 @@ MEDIA_URL = "/media/" # values in /etc/paperless.conf instead. # ---------------------------------------------------------------------------- -# Tap paperless.conf if it's available -if os.path.exists("/etc/paperless.conf"): - load_dotenv("/etc/paperless.conf") - - # Logging LOGGING = { From 5e6e1ce9598c48bda242e9fb86cede09a9396389 Mon Sep 17 00:00:00 2001 From: Jeff Bogatay Date: Tue, 23 Aug 2016 12:22:36 -0400 Subject: [PATCH 03/10] Remove debug stuff --- src/paperless/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 1e946d0b0..dcb87a248 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -98,7 +98,7 @@ DATABASES = { "NAME": os.path.join(os.getenv("PAPERLESS_DBLOCATION",os.path.join(BASE_DIR, "..", "data")), "db.sqlite3") } } -print(DATABASES) + if os.getenv("PAPERLESS_DBUSER") and os.getenv("PAPERLESS_DBPASS"): DATABASES["default"] = { "ENGINE": "django.db.backends.postgresql_psycopg2", From 05f3cad271b4cb329bd2924df5cd078f297da349 Mon Sep 17 00:00:00 2001 From: Jeff Bogatay Date: Tue, 23 Aug 2016 11:31:54 -0400 Subject: [PATCH 04/10] Secure document fetching --- src/documents/views.py | 2 +- src/paperless/settings.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/documents/views.py b/src/documents/views.py index 71d350e02..d47ab8654 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -31,7 +31,7 @@ class IndexView(TemplateView): return TemplateView.get_context_data(self, **kwargs) -class FetchView(DetailView): +class FetchView(LoginRequiredMixin, DetailView): model = Document diff --git a/src/paperless/settings.py b/src/paperless/settings.py index faf532d52..c80434bc7 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -27,6 +27,8 @@ SECRET_KEY = 'e11fl1oa-*ytql8p)(06fbj4ukrlo+n7k&q5+$1md7i+mge=ee' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +LOGIN_URL = '/admin/login' + ALLOWED_HOSTS = [] From 74c553797919bc869bfa3e03d62f63859e2f945d Mon Sep 17 00:00:00 2001 From: Jeff Bogatay Date: Tue, 23 Aug 2016 12:24:51 -0400 Subject: [PATCH 05/10] Document new ENV variable --- paperless.conf.example | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/paperless.conf.example b/paperless.conf.example index 85709698f..3ba8c6693 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -80,3 +80,8 @@ PAPERLESS_SHARED_SECRET="" # For more information on how to use this value, you should probably search # the web for "MAGICK_TMPDIR". #PAPERLESS_CONVERT_TMPDIR=/var/tmp/paperless + +# You can specify where you want the SQLite database to be stored instead of +# the default location +#PAPERLESS_DBLOCATION=/path/to/database/file + From 69466e712bd5dc75f56020577e694d75d4a4537f Mon Sep 17 00:00:00 2001 From: Jeff Bogatay Date: Tue, 23 Aug 2016 13:28:08 -0400 Subject: [PATCH 06/10] Prettify code, change ENV variable name --- paperless.conf.example | 2 +- src/paperless/settings.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/paperless.conf.example b/paperless.conf.example index 3ba8c6693..6b2a102ab 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -83,5 +83,5 @@ PAPERLESS_SHARED_SECRET="" # You can specify where you want the SQLite database to be stored instead of # the default location -#PAPERLESS_DBLOCATION=/path/to/database/file +#PAPERLESS_DBDIR=/path/to/database/file diff --git a/src/paperless/settings.py b/src/paperless/settings.py index dcb87a248..de25313c6 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -95,7 +95,13 @@ WSGI_APPLICATION = 'paperless.wsgi.application' DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(os.getenv("PAPERLESS_DBLOCATION",os.path.join(BASE_DIR, "..", "data")), "db.sqlite3") + "NAME": os.path.join( + os.getenv( + "PAPERLESS_DBDIR", + os.path.join(BASE_DIR, "..", "data") + ), + "db.sqlite3" + ) } } From 509f7d908e73a7441f37b749988aae20066357b2 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Wed, 24 Aug 2016 12:27:21 +0100 Subject: [PATCH 07/10] Updated changelog. I really should tag soon --- docs/changelog.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 65f6759e9..4c24e80a0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,9 @@ Changelog * 0.2.0 + * `#148`_: The database location (sqlite) is now a variable you can set in + ``paperless.conf``. + * `#146`_: Fixed a bug that allowed unauthorised access to the `/fetch` URL. * `#131`_: Document files are now automatically removed from disk when they're deleted in Paperless. * `#121`_: Fixed a bug where Paperless wasn't setting document creation time @@ -130,3 +133,5 @@ Changelog .. _#98: https://github.com/danielquinn/paperless/issues/98 .. _#121: https://github.com/danielquinn/paperless/issues/121 .. _#131: https://github.com/danielquinn/paperless/issues/131 +.. _#146: https://github.com/danielquinn/paperless/issues/146 +.. _#148: https://github.com/danielquinn/paperless/pull/148 From a85096775e14548d5e5c63a25729e4495a0e9896 Mon Sep 17 00:00:00 2001 From: Jeff Bogatay Date: Tue, 23 Aug 2016 14:48:13 -0400 Subject: [PATCH 08/10] Allow overriding default media directory --- paperless.conf.example | 2 ++ src/paperless/settings.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/paperless.conf.example b/paperless.conf.example index 6b2a102ab..abb93eefe 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -85,3 +85,5 @@ PAPERLESS_SHARED_SECRET="" # the default location #PAPERLESS_DBDIR=/path/to/database/file +# Override the default MEDIA_ROOT here. This is where all files are stored. +#PAPERLESS_MEDIADIR=/path/to/media diff --git a/src/paperless/settings.py b/src/paperless/settings.py index de25313c6..b343b3a17 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -151,7 +151,10 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.9/howto/static-files/ STATIC_ROOT = os.path.join(BASE_DIR, "..", "static") -MEDIA_ROOT = os.path.join(BASE_DIR, "..", "media") +MEDIA_ROOT = os.getenv( + "PAPERLESS_MEDIADIR", + os.path.join(BASE_DIR, "..", "media") + ) STATIC_URL = '/static/' MEDIA_URL = "/media/" From 4708f63138049476308506ac8a56f5aec85554af Mon Sep 17 00:00:00 2001 From: Ruben Waterman Date: Sat, 27 Aug 2016 00:56:14 +0200 Subject: [PATCH 09/10] Update setup.rst Added a line on how to use the ubuntu upstart example in Vagrant. It took me hours to figure out why it wouldn't start on boot but would when you would type "start paperless-server" manually. The start on vagrant-mounted solved the problem, so I thought it would be good to share this with the paperless community. --- docs/setup.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/setup.rst b/docs/setup.rst index 2361357fb..c2db11095 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -550,8 +550,7 @@ your gunicorn instance. This should do the trick: Vagrant ....... -You're currently on your own, but the Ubuntu explanation above may be enough. - +You may use the Ubuntu explanation above. Replace ``(local-filesystems and net-device-up IFACE=eth0)`` with ``vagrant-mounted``. .. _setup-permanent-docker: From 38b63fbe7737454f0211144e068a319b68834de2 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Wed, 24 Aug 2016 16:39:36 +0100 Subject: [PATCH 10/10] Updated changelog to include #150 --- docs/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4c24e80a0..25683aeaf 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,8 @@ Changelog * 0.2.0 + * `#150`_: The media root is now a variable you can set in + ``paperless.conf``. * `#148`_: The database location (sqlite) is now a variable you can set in ``paperless.conf``. * `#146`_: Fixed a bug that allowed unauthorised access to the `/fetch` URL. @@ -135,3 +137,4 @@ Changelog .. _#131: https://github.com/danielquinn/paperless/issues/131 .. _#146: https://github.com/danielquinn/paperless/issues/146 .. _#148: https://github.com/danielquinn/paperless/pull/148 +.. _#150: https://github.com/danielquinn/paperless/pull/150