From e4af527e462db2a091ffe59a67933b5ca01438b8 Mon Sep 17 00:00:00 2001 From: dzhuang Date: Sun, 16 Jul 2017 16:35:35 +0800 Subject: [PATCH] Added missing request.user = impersonee in ImpersonateMiddleware --- course/auth.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/course/auth.py b/course/auth.py index 104dc052..e944c9ad 100644 --- a/course/auth.py +++ b/course/auth.py @@ -140,10 +140,13 @@ class ImpersonateMiddleware(object): may_impersonate = True else: qset = get_impersonable_user_qset(cast(User, request.user)) - if qset.filter(pk__in=cast(User, impersonee).pk).count(): + if qset.filter(pk=cast(User, impersonee).pk).count(): may_impersonate = True - if not may_impersonate: + if may_impersonate: + request.relate_impersonate_original_user = request.user + request.user = impersonee + else: messages.add_message(request, messages.ERROR, _("Error while impersonating.")) @@ -230,7 +233,7 @@ def impersonate(request): impersonee = form.cleaned_data["user"] if impersonable_user_qset.filter( - pk__in=cast(User, impersonee).pk).count(): + pk=cast(User, impersonee).pk).count(): request.session['impersonate_id'] = impersonee.id request.session['relate_impersonation_header'] = form.cleaned_data[ "add_impersonation_header"] -- GitLab