Skip to content

Commit c4bf508

Browse files
Do not redirect user to the logout page when logging in. Fixes ietf-tools#3478. Commit ready for merge.
- Legacy-Id: 19876
1 parent eeb461f commit c4bf508

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

ietf/doc/templatetags/ietf_filters.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,23 @@ def expires_soon(x,request):
394394
def startswith(x, y):
395395
return str(x).startswith(y)
396396

397+
398+
@register.filter(name='removesuffix', is_safe=False)
399+
def removesuffix(value, suffix):
400+
"""Remove an exact-match suffix
401+
402+
The is_safe flag is False because indiscriminate use of this could result in non-safe output.
403+
See https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/#filters-and-auto-escaping
404+
which describes the possibility that removing characters from an escaped string may introduce
405+
HTML-unsafe output.
406+
"""
407+
base = str(value)
408+
if base.endswith(suffix):
409+
return base[:-len(suffix)]
410+
else:
411+
return base
412+
413+
397414
@register.filter
398415
def has_role(user, role_names):
399416
from ietf.ietfauth.utils import has_role

ietf/ietfauth/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def test_login_and_logout(self):
9595
# try logging out
9696
r = self.client.get(urlreverse('django.contrib.auth.views.logout'))
9797
self.assertEqual(r.status_code, 200)
98+
self.assertNotContains(r, "accounts/logout")
9899

99100
r = self.client.get(urlreverse(ietf.ietfauth.views.profile))
100101
self.assertEqual(r.status_code, 302)

ietf/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
</ul>
7373
{% if not user.is_authenticated %}
7474
<p class="navbar-text"></p>
75-
<a class="btn {% if server_mode and server_mode == "production" %}btn-warning{% else %}btn-default{% endif %} btn-sm navbar-btn" rel="nofollow" href="/accounts/login/?next={{request.get_full_path|urlencode}}">Sign in</a>
75+
<a class="btn {% if server_mode and server_mode == "production" %}btn-warning{% else %}btn-default{% endif %} btn-sm navbar-btn" rel="nofollow" href="/accounts/login/?next={{request.get_full_path|removesuffix:"accounts/logout/"|urlencode}}">Sign in</a>
7676
{% endif %}
7777

7878
<form class="navbar-form navbar-right hidden-xs" action="/doc/search/">

0 commit comments

Comments
 (0)