Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige l'impossibilité de se connecter après un ban temporaire #6635

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions zds/member/tests/views/tests_login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime, timedelta

from django.conf import settings
from django.urls import reverse
from django.test import TestCase
Expand Down Expand Up @@ -170,6 +172,29 @@ def test_banned_user(self):
)
self.assertContains(result, escape(LoginForm.error_messages["banned"]))

def test_previously_temp_banned_user(self):
"""
Nominal case: correct username, activated user, correct password, previously temp banned user.
Expected: successful login, redirect to homepage.
"""

# Equivalent to a previously temporary banned user
self.profile.can_read = False
self.profile.end_ban_read = datetime.now() - timedelta(days=30)
self.profile.save()

result = self.client.post(
self.login_url,
{
"username": self.correct_username,
"password": self.correct_password,
},
follow=True,
)

self.assertRedirects(result, reverse("homepage"))
self.assertTrue(self.client.session.get_expire_at_browser_close())

def test_redirection_good_target(self):
"""Nominal case: redirection to an existing page with the parameter 'next'."""
result = self.client.post(
Expand Down
2 changes: 1 addition & 1 deletion zds/middlewares/setlastvisitmiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ def process_response(self, request, response):
profile.last_visit = datetime.datetime.now()
profile.last_ip_address = get_client_ip(request)
profile.save()
if not profile.can_read:
if not profile.is_banned():
logout(request)
return response