Ticket #159: ticket-159-circular-logout.patch

File ticket-159-circular-logout.patch, 2.7 KB (added by Ash Christopher, 13 years ago)

New patch for ticket.

  • django/contrib/admin/sites.py

    diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
    old mode 100644
    new mode 100755
    index 83a0869..304df5c
    a b from django.utils.text import capfirst  
    1414from django.utils.translation import ugettext as _
    1515from django.views.decorators.cache import never_cache
    1616from django.conf import settings
     17from django.http import HttpResponseRedirect
     18
    1719
    1820LOGIN_FORM_KEY = 'this_is_the_login_form'
    1921
    class AdminSite(object):  
    188190        """
    189191        def inner(request, *args, **kwargs):
    190192            if not self.has_permission(request):
     193                if request.path.endswith(reverse('admin:logout')):
     194                    return HttpResponseRedirect(reverse('admin:index'))
    191195                return self.login(request)
    192196            return view(request, *args, **kwargs)
    193197        if not cacheable:
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    old mode 100644
    new mode 100755
    index 6037c2b..4ef3e9d
    a b class AdminCustomSaveRelatedTests(TestCase):  
    33513351
    33523352        self.assertEqual('Josh Stone', Parent.objects.latest('id').name)
    33533353        self.assertEqual([u'Catherine Stone', u'Paul Stone'], children_names)
     3354
     3355class AdminViewLogoutTest(TestCase):
     3356    urls = "regressiontests.admin_views.urls"
     3357    fixtures = ['admin-views-users.xml', ]
     3358
     3359    def setUp(self):
     3360        self.client.login(username='super', password='secret')
     3361   
     3362    def tearDown(self):
     3363        self.client.logout()
     3364
     3365    def test_client_logout_url_can_be_used_to_login(self):
     3366        response = self.client.get('/test_admin/admin/logout/')
     3367        self.assertEqual(response.status_code, 200)
     3368        self.assertEqual(response.template_name, 'registration/logged_out.html')
     3369        self.assertEqual(response.request['PATH_INFO'], '/test_admin/admin/logout/')
     3370
     3371        # we are now logged out - issue a GET request to `/test_admin/admin/logout/`
     3372        response = self.client.get('/test_admin/admin/logout/')
     3373        self.assertEqual(response.status_code, 302)  # we should be redirected to the login page.
     3374
     3375        response = self.client.get('/test_admin/admin/logout/', follow=True)  # follow the redirect and test results.
     3376        self.assertEqual(response.status_code, 200)
     3377        self.assertEqual(response.template_name, 'admin/login.html')
     3378        self.assertEqual(response.request['PATH_INFO'], '/test_admin/admin/')
     3379
     3380        self.assertTrue(
     3381            '<input type="hidden" name="next" value="/test_admin/admin/" />' in response.content)
Back to Top