diff --git a/passbook/admin/middleware.py b/passbook/admin/middleware.py new file mode 100644 index 000000000..1c4d1c42a --- /dev/null +++ b/passbook/admin/middleware.py @@ -0,0 +1,25 @@ +"""passbook admin Middleware to impersonate users""" + +from passbook.core.models import User + + +def impersonate(get_response): + """Middleware to impersonate users""" + + def middleware(request): + """Middleware to impersonate users""" + + # User is superuser and has __impersonate ID set + if request.user.is_superuser and "__impersonate" in request.GET: + request.session['impersonate_id'] = request.GET["__impersonate"] + # user wants to stop impersonation + elif "__unimpersonate" in request.GET and 'impersonate_id' in request.session: + del request.session['impersonate_id'] + + # Actually impersonate user + if request.user.is_superuser and 'impersonate_id' in request.session: + request.user = User.objects.get(pk=request.session['impersonate_id']) + + response = get_response(request) + return response + return middleware diff --git a/passbook/admin/settings.py b/passbook/admin/settings.py new file mode 100644 index 000000000..14f5e9421 --- /dev/null +++ b/passbook/admin/settings.py @@ -0,0 +1,5 @@ +"""passbook admin settings""" + +MIDDLEWARE = [ + 'passbook.admin.middleware.impersonate', +] diff --git a/passbook/admin/templates/administration/user/list.html b/passbook/admin/templates/administration/user/list.html index fe641038c..726936b1e 100644 --- a/passbook/admin/templates/administration/user/list.html +++ b/passbook/admin/templates/administration/user/list.html @@ -31,6 +31,8 @@ href="{% url 'passbook_admin:user-delete' pk=user.pk %}?back={{ request.get_full_path }}">{% trans 'Delete' %} {% trans 'Reset Password' %} + {% trans 'Impersonate' %} {% endfor %} diff --git a/passbook/core/templates/base/skeleton.html b/passbook/core/templates/base/skeleton.html index dad228996..dba86a0b8 100644 --- a/passbook/core/templates/base/skeleton.html +++ b/passbook/core/templates/base/skeleton.html @@ -4,40 +4,51 @@ -
- - -