From 0c85fdada88b1b928520c66aafb7b5f4a840b23d Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Mon, 2 Sep 2019 10:40:10 +0200
Subject: [PATCH] Enable impersonation through django-impersonate. Advances
 #63.

---
 biscuit/core/settings.py | 8 ++++++++
 biscuit/core/urls.py     | 1 +
 pyproject.toml           | 1 +
 3 files changed, 10 insertions(+)

diff --git a/biscuit/core/settings.py b/biscuit/core/settings.py
index db1c1349f..fb4942d20 100644
--- a/biscuit/core/settings.py
+++ b/biscuit/core/settings.py
@@ -51,6 +51,7 @@ INSTALLED_APPS = [
     'settings_context_processor',
     'sass_processor',
     'easyaudit',
+    'impersonate',
     'bootstrap4',
     'fa',
     'django_any_js',
@@ -90,6 +91,7 @@ MIDDLEWARE = [
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'impersonate.middleware.ImpersonateMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'easyaudit.middleware.easyaudit.EasyAuditMiddleware',
@@ -274,4 +276,10 @@ MAINTENANCE_MODE_IGNORE_IP_ADDRESSES = _settings.get(
 MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = 'ipware.ip.get_ip'
 MAINTENANCE_MODE_IGNORE_SUPERUSER = True
 
+IMPERSONATE = {
+    'USE_HTTP_REFERER': True,
+    'REQUIRE_SUPERUSER': True,
+    'ALLOW_SUPERUSER': True
+}
+
 _settings.populate_obj(sys.modules[__name__])
diff --git a/biscuit/core/urls.py b/biscuit/core/urls.py
index 4e7d3ac62..2ccb4f749 100644
--- a/biscuit/core/urls.py
+++ b/biscuit/core/urls.py
@@ -27,6 +27,7 @@ urlpatterns = [
     path('', views.index, name='index'),
     path('maintenance-mode/', include('maintenance_mode.urls')),
     path('contact/', include('contact_form.urls')),
+    path('impersonate/', include('impersonate.urls')),
     path('__i18n__/', include('django.conf.urls.i18n'))
 ]
 
diff --git a/pyproject.toml b/pyproject.toml
index 768f1ac01..cba2ad8b7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -43,6 +43,7 @@ django-ipware = "^2.1"
 easy-thumbnails = "^2.6"
 django-image-cropping = "^1.2"
 django-contact-form = "^1.7"
+django-impersonate = "^1.4"
 
 [tool.poetry.extras]
 ldap = ["django-auth-ldap"]
-- 
GitLab