From 63874cf9820ee82050d3d11ba12212c197821fcd Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sat, 27 Jan 2024 18:06:05 +0100 Subject: add impersonation --- accounts/urls.py | 1 + accounts/views.py | 5 +++++ manager/settings.py | 8 +++++++- manager/urls.py | 1 + requirements.txt | 1 + templates/registration/base_client.html | 4 +++- version.txt | 2 +- 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/accounts/urls.py b/accounts/urls.py index 57a649d..76a54e6 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -14,4 +14,5 @@ urlpatterns = [ path('oauth_disconnect/', views.oauth_disconnect, name='oauth_disconnect'), path('auth_connect/', views.auth_connect, name='auth_connect'), path('user_switcher/', views.user_switcher, name='user_switcher'), + path('logout/', views.logout_view, name='logout'), ] diff --git a/accounts/views.py b/accounts/views.py index f04f495..9ecb15f 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -789,3 +789,8 @@ def edit(request, code): def terms(request): context = {} return render(request, 'accounts/terms.html', context) + + +def logout_view(request): + logout(request) + return HttpResponseRedirect('/') \ No newline at end of file diff --git a/manager/settings.py b/manager/settings.py index c2ffdf6..e145e45 100644 --- a/manager/settings.py +++ b/manager/settings.py @@ -66,6 +66,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'impersonate', ] MIDDLEWARE = [ @@ -76,6 +77,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'impersonate.middleware.ImpersonateMiddleware', ] AUTHLIB_OAUTH_CLIENTS = { @@ -174,4 +176,8 @@ STATICFILES_DIRS = [ LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = '/' -FQD_BASE_URL = 'http://127.0.0.1:8000' \ No newline at end of file +FQD_BASE_URL = 'http://127.0.0.1:8000' + +# Impersonate settings +REQUIRE_SUPERUSER = True +ALLOW_SUPERUSER = False \ No newline at end of file diff --git a/manager/urls.py b/manager/urls.py index f3b8008..beaefbe 100644 --- a/manager/urls.py +++ b/manager/urls.py @@ -23,6 +23,7 @@ urlpatterns = [ path('accounts/', include('accounts.urls')), path('accounts/', include('django.contrib.auth.urls')), path('admin/', admin.site.urls), + path('impersonate/', include('impersonate.urls')), ] if settings.DEBUG: diff --git a/requirements.txt b/requirements.txt index 62c7159..05c1064 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ pdf2image django-debug-toolbar requests authlib +django-impersonate diff --git a/templates/registration/base_client.html b/templates/registration/base_client.html index 357197a..2518988 100644 --- a/templates/registration/base_client.html +++ b/templates/registration/base_client.html @@ -134,7 +134,7 @@
  • listLista documenti
  • {% endif %} -
  • exit_to_appLogout
  • +
  • exit_to_appLogout