Skip to content

Commit d0288f4

Browse files
committed
Rename safe_next_url -> extract_next_path_from_params
Avoid using the word safe as it implies some level of escaping / safety that this function doesn't provide.
1 parent 74bcc56 commit d0288f4

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

manage_breast_screening/auth/demo_views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
from django.shortcuts import get_object_or_404, redirect, render
77
from django.urls import reverse
88

9-
from manage_breast_screening.core.utils.urls import safe_next_url
9+
from manage_breast_screening.core.utils.urls import extract_next_path_from_params
1010

1111
from .models import PERSONAS
1212

1313

1414
@login_not_required
1515
def persona_login(request):
1616
users = _get_users(request.user)
17-
next_url = safe_next_url(request)
17+
next_path = extract_next_path_from_params(request)
1818

1919
if request.method == "POST":
2020
user = get_object_or_404(users, nhs_uid=request.POST["username"])
2121
login(request, user, backend="django.contrib.auth.backends.ModelBackend")
2222

2323
redirect_url = reverse("clinics:select_provider")
24-
if next_url:
25-
redirect_url = f"{redirect_url}?{urlencode({'next': next_url})}"
24+
if next_path:
25+
redirect_url = f"{redirect_url}?{urlencode({'next': next_path})}"
2626

2727
return redirect(redirect_url)
2828
else:
@@ -33,7 +33,7 @@ def persona_login(request):
3333
"users": users,
3434
"page_title": "Personas",
3535
"current_user": request.user,
36-
"next": next_url,
36+
"next": next_path,
3737
},
3838
)
3939

manage_breast_screening/clinics/views.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.views.decorators.http import require_http_methods
44

55
from ..core.decorators import current_provider_exempt
6-
from ..core.utils.urls import safe_next_url
6+
from ..core.utils.urls import extract_next_path_from_params
77
from ..participants.models import Appointment, AppointmentStatus
88
from .models import Clinic, Provider
99
from .presenters import AppointmentListPresenter, ClinicPresenter, ClinicsPresenter
@@ -58,21 +58,21 @@ def check_in(_request, pk, appointment_pk):
5858
@current_provider_exempt
5959
@login_required
6060
def select_provider(request):
61-
next_url = safe_next_url(request)
61+
next_path = extract_next_path_from_params(request)
6262
user_providers = Provider.objects.filter(assignments__user=request.user)
6363

6464
if len(user_providers) == 1:
6565
request.session["current_provider"] = str(user_providers.first().pk)
66-
if next_url:
67-
return redirect(next_url)
66+
if next_path:
67+
return redirect(next_path)
6868
return redirect("clinics:index")
6969

7070
if request.method == "POST":
7171
provider_id = request.POST.get("provider")
7272
if provider_id and user_providers.filter(pk=provider_id).exists():
7373
request.session["current_provider"] = provider_id
74-
if next_url:
75-
return redirect(next_url)
74+
if next_path:
75+
return redirect(next_path)
7676
return redirect("clinics:index")
7777

7878
return render(
@@ -81,6 +81,6 @@ def select_provider(request):
8181
context={
8282
"providers": user_providers,
8383
"page_title": "Select Provider",
84-
"next": next_url,
84+
"next": next_path,
8585
},
8686
)

manage_breast_screening/core/utils/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def safe_next_url(request):
1+
def extract_next_path_from_params(request):
22
"""Extract and validate a 'next' URL from request GET or POST parameters.
33
44
Only returns the URL if it's a safe relative URL (starts with '/').

0 commit comments

Comments
 (0)