-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enregistrer le dernier evenement connu pour une adresse mail (#894
) ## Description 🎸 Creer ou mettre à jour `EmailLastSeen` lors des évènements suivants : * navigation d'un utilisateur authentifié : dans un `middleware` dedié * creation d'un `Post`/`Topic` : dans la méthode `save` du modèle `Post` * click sur une notification email : dans le middleware `NotificationMiddleware` de suivi des urls dans les mails de notification ## Type de changement 🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une fonctionnalité). 🚧 technique ### Points d'attention 🦺 Les mises à jour de `Post` ne déclenche plus de mise à jour de `EmailLastSeen` pour éviter la détérioration de données en cas de `save` massif sur des instances existantes du modèle `Post` 🦺 Creation d'un `DSP`, d'un `UpVote` ou d'un `Event`, les vues sont en `LoginRequiredOnly`. L'enregistrement du passage de l'utilisateur est donc déjà enregistré par `MarkAsSeenLoggedUserMiddleware` 🦺 prérequis #891 et #892
- Loading branch information
1 parent
fb886e1
commit 9aa316c
Showing
13 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
|
||
from django.utils.deprecation import MiddlewareMixin | ||
|
||
from lacommunaute.users.enums import EmailLastSeenKind | ||
from lacommunaute.users.models import EmailLastSeen | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MarkAsSeenLoggedUserMiddleware(MiddlewareMixin): | ||
def process_request(self, request): | ||
if request.user.is_authenticated: | ||
EmailLastSeen.objects.seen(email=request.user.email, kind=EmailLastSeenKind.LOGGED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
|
||
from lacommunaute.users.enums import EmailLastSeenKind | ||
from lacommunaute.users.factories import UserFactory | ||
from lacommunaute.users.models import EmailLastSeen | ||
|
||
|
||
@pytest.mark.parametrize("logged", [True, False]) | ||
def test_mark_as_seen_logged_user_middleware(client, db, logged): | ||
if logged: | ||
user = UserFactory() | ||
client.force_login(user) | ||
|
||
response = client.get("/") | ||
assert response.status_code == 200 | ||
|
||
if logged: | ||
email_last_seen = EmailLastSeen.objects.get() | ||
assert email_last_seen.email == user.email | ||
assert email_last_seen.last_seen_kind == EmailLastSeenKind.LOGGED | ||
else: | ||
assert not EmailLastSeen.objects.exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters