Adapt logout behaviour in ajax/not ajax modes

This commit is contained in:
Yohan Boniface 2023-07-27 15:02:51 +02:00
parent d56162390d
commit fc37ad7c17
2 changed files with 21 additions and 1 deletions

View file

@ -261,3 +261,21 @@ def test_user_dashboard_display_user_maps(client, map):
assert f"{map.get_absolute_url()}?download" in body assert f"{map.get_absolute_url()}?download" in body
assert "Everyone (public)" in body assert "Everyone (public)" in body
assert "Owner only" in body assert "Owner only" in body
@pytest.mark.django_db
def test_logout_should_return_json_in_ajax(client, user, settings):
client.login(username=user.username, password="123123")
response = client.get(
reverse("logout"), headers={"X_REQUESTED_WITH": "XMLHttpRequest"}
)
data = json.loads(response.content.decode())
assert data["redirect"] == "/"
@pytest.mark.django_db
def test_logout_should_return_redirect(client, user, settings):
client.login(username=user.username, password="123123")
response = client.get(reverse("logout"))
assert response.status_code == 302
assert response["Location"] == "/"

View file

@ -945,7 +945,9 @@ def stats(request):
def logout(request): def logout(request):
do_logout(request) do_logout(request)
return simple_json_response(redirect="/") if is_ajax(request):
return simple_json_response(redirect="/")
return HttpResponseRedirect("/")
class LoginPopupEnd(TemplateView): class LoginPopupEnd(TemplateView):