Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Feb 23, 2024
1 parent ce00d00 commit 8d95377
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
19 changes: 12 additions & 7 deletions src/open_inwoner/accounts/middleware.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging

from django.conf import settings
from django.http import HttpResponseRedirect
from django.urls import NoReverseMatch, reverse

logger = logging.getLogger(__name__)
from furl import furl

logger = logging.getLogger(__name__)


class NecessaryFieldsMiddleware:
"""
Expand Down Expand Up @@ -49,11 +51,14 @@ def __call__(self, request):
)
and request.user.require_necessary_fields()
):
redirect_url = (
furl(reverse("profile:registration_necessary"))
.set({"next": request.path})
.url
)
return HttpResponseRedirect(redirect_url)
redirect = furl(reverse("profile:registration_necessary"))
if request.path != settings.LOGIN_REDIRECT_URL:
redirect.set({"next": request.path})
# redirect_url = (
# furl(reverse("profile:registration_necessary"))
# .set({"next": request.path})
# .url
# )
return HttpResponseRedirect(redirect.url)

return self.get_response(request)
20 changes: 13 additions & 7 deletions src/open_inwoner/accounts/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,11 @@ def test_invite_url_not_in_session_after_successful_login(

# follow redirect flow
res = self.client.get(response["Location"])
res = self.client.get(res["Location"])
res = self.client.get(res["Location"])

self.assertRedirects(
res, f"{reverse('profile:registration_necessary')}?invite={invite.key}"
res,
f"{reverse('profile:registration_necessary')}?invite={invite.key}",
fetch_redirect_response=False,
)
self.assertNotIn("invite_url", self.client.session.keys())

Expand Down Expand Up @@ -708,7 +708,7 @@ def test_redirect_flow_with_no_vestigingsnummer(self, mock_solo, mock_kvk):
response = self.client.post(url, data, user=user, follow=True)
self.assertRedirects(
response,
furl(f"{reverse('profile:registration_necessary')}").set({"next": "/"}),
reverse("profile:registration_necessary"),
)

# check company branch number in session
Expand Down Expand Up @@ -739,6 +739,10 @@ def test_eherkenning_user_is_redirected_to_necessary_registration(
response = self.app.get(reverse("pages-root"), user=user)

# redirect to /kvk/branches/
self.assertRedirects(
response, reverse("kvk:branches"), fetch_redirect_response=False
)

res = self.app.post(response["Location"], {"branch_number": "1234"})

# redirect to /register/necessary/
Expand Down Expand Up @@ -1387,9 +1391,11 @@ def test_any_page_for_digid_user_redirect_to_necessary_fields(self):
with self.subTest(url=url):
response = self.app.get(url, user=user)

self.assertRedirects(
response, reverse("profile:registration_necessary")
)
redirect = furl(reverse("profile:registration_necessary"))
if url != reverse("pages-root"):
redirect.set({"next": url})

self.assertRedirects(response, redirect.url)

def test_submit_without_invite(self):
user = UserFactory(
Expand Down
4 changes: 2 additions & 2 deletions src/open_inwoner/accounts/views/registration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Optional
from typing import Optional
from urllib.parse import unquote

from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.urls import NoReverseMatch, reverse
from django.utils.translation import gettext as _
Expand Down
5 changes: 4 additions & 1 deletion src/open_inwoner/kvk/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from django.conf import settings
from django.http import HttpResponseRedirect
from django.urls import NoReverseMatch, reverse

Expand Down Expand Up @@ -41,7 +42,9 @@ def __call__(self, request):
return self.get_response(request)

# redirect to company branch choice
redirect = furl(reverse("kvk:branches")).set({"next": request.path})
redirect = furl(reverse("kvk:branches"))
if request.path != settings.LOGIN_REDIRECT_URL:
redirect.set({"next": request.path})
redirect.args.update(request.GET)

return HttpResponseRedirect(redirect.url)

0 comments on commit 8d95377

Please sign in to comment.