diff --git a/src/paperless/auto_auth.py b/src/paperless/auto_auth.py new file mode 100644 index 000000000..27d9158c1 --- /dev/null +++ b/src/paperless/auto_auth.py @@ -0,0 +1,16 @@ +from django.contrib.auth.models import User + +class User: + is_superuser = True + is_active = True + is_staff = True + id = 1 + +def return_true(*args, **kwargs): + return True +User.has_module_perms = return_true +User.has_perm = return_true + +class Middleware(object): + def process_request(self, request): + request.user = User() diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 6d750c9b0..a28424e81 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -77,14 +77,21 @@ INSTALLED_APPS = [ if os.getenv("PAPERLESS_INSTALLED_APPS"): INSTALLED_APPS += os.getenv("PAPERLESS_INSTALLED_APPS").split(",") + +AUTH_CLASSES = [\ + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware'] + +if bool(os.getenv("PAPERLESS_DISABLE_AUTH","true").lower() in ("yes", "y", "1", "t", "true")): + AUTH_CLASSES = ['auto_auth.Middleware'] + MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware']\ + + AUTH_CLASSES + \ + ['django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]