diff --git a/impact/public/tests/tests.py b/impact/public/tests/tests.py index 8396966e4..3067a323b 100644 --- a/impact/public/tests/tests.py +++ b/impact/public/tests/tests.py @@ -28,12 +28,13 @@ def test_page_index_pour_un_visiteur_anonyme(client): assert "" in content -def test_redirection_de_la_page_index_vers_ses_reglementations_si_l_utilisateur_est_connecte( +def test_redirection_de_la_page_index_vers_ses_reglementations_si_l_utilisateur_vient_de_se_connecter_depuis_la_page_d_accueil( client, alice ): client.force_login(alice) - - response = client.get("/", follow=True) + response = client.get( + "/", follow=True, headers={"referer": "http://domain.test/connexion?next=/"} + ) assert response.status_code == 200 assert response.redirect_chain == [ diff --git a/impact/public/views.py b/impact/public/views.py index 2cb8329ec..42d166f38 100644 --- a/impact/public/views.py +++ b/impact/public/views.py @@ -18,7 +18,8 @@ def index(request): - if request.user.is_authenticated: + referer = request.META.get("HTTP_REFERER", "") + if referer.endswith("/connexion?next=/"): return redirect(reverse("reglementations")) return render(request, "public/index.html")