From 1555b0244a145f19adaa755c32cae2d1a1816f3b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 27 Jun 2019 14:28:19 +0200 Subject: [PATCH 1/2] remove switch_back view (#34308) --- src/authentic2/urls.py | 4 ---- src/authentic2/utils.py | 20 ++------------------ src/authentic2/views.py | 4 ---- 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/authentic2/urls.py b/src/authentic2/urls.py index fecadd2c..7d3df248 100644 --- a/src/authentic2/urls.py +++ b/src/authentic2/urls.py @@ -79,10 +79,6 @@ accounts_urlpatterns = [ views.password_reset, name='password_reset'), - url(r'^switch-back/$', - views.switch_back, - name='a2-switch-back'), - # Legacy, only there to provide old view names to resolver url(r'^password/change/$', views.notimplemented_view, diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py index dd8d7075..761975ec 100644 --- a/src/authentic2/utils.py +++ b/src/authentic2/utils.py @@ -45,6 +45,7 @@ from django.shortcuts import resolve_url from django.template.loader import render_to_string, TemplateDoesNotExist from django.core.mail import send_mail from django.core import signing +from django.core.cache import cache from django.core.urlresolvers import reverse from django.utils.formats import localize from django.contrib import messages @@ -823,6 +824,7 @@ def to_dict_of_set(d): def switch_user(request, new_user): '''Switch to another user and remember currently logged in user in the session. Reserved to superusers.''' + logger = logging.getLogger(__name__) if constants.SWITCH_USER_SESSION_KEY in request.session: messages.error(request, _('Your user is already switched, go to your ' @@ -847,24 +849,6 @@ def switch_user(request, new_user): return continue_to_next_url(request) -def switch_back(request): - '''Switch back to original superuser after a user switch''' - logger = logging.getLogger(__name__) - if constants.SWITCH_USER_SESSION_KEY in request.session: - switched = request.session[constants.SWITCH_USER_SESSION_KEY] - for key in switched: - request.session[key] = switched[key] - del request.session[constants.SWITCH_USER_SESSION_KEY] - del request._cached_user - request.user._wrapped = empty - messages.info(request, _('Successfully switched back to user %s') - % request.user.get_full_name()) - logger.info(u'switched back to user %s', request.user) - else: - messages.warning(request, _('No user to switch back to')) - return continue_to_next_url(request) - - def datetime_to_utc(dt): if timezone.is_naive(dt): dt = timezone.make_aware(dt, timezone.get_current_timezone()) diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 0370d2a6..d9c40e09 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -740,10 +740,6 @@ class PasswordResetConfirmView(cbv.RedirectToNextURLViewMixin, FormView): password_reset_confirm = PasswordResetConfirmView.as_view() -def switch_back(request): - return utils.switch_back(request) - - def valid_token(method): def f(request, *args, **kwargs): try: -- 2.20.1