Merge pull request #1235 from umap-project/logout-redirect

Adapt logout behaviour in ajax/not ajax modes
This commit is contained in:
Yohan Boniface 2023-08-15 07:24:55 +02:00 committed by GitHub
commit f94a513c4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 "Everyone (public)" 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):
do_logout(request)
return simple_json_response(redirect="/")
if is_ajax(request):
return simple_json_response(redirect="/")
return HttpResponseRedirect("/")
class LoginPopupEnd(TemplateView):