-
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(notification): enregistrer les retours sur les notifs mails (#891)
## Description 🎸 Ajouter l'uuid de la `notification` dans l'url du message de notif. 🎸 Intercepter ce paramètre dans les requêtes entrantes pour mettre à jour la `notification` ## Type de changement 🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une fonctionnalité). 🚧 technique
- Loading branch information
1 parent
4ae46d0
commit ec67205
Showing
11 changed files
with
261 additions
and
238 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import uuid | ||
|
||
from django.utils import timezone | ||
from django.utils.deprecation import MiddlewareMixin | ||
|
||
from lacommunaute.notification.models import Notification | ||
|
||
|
||
class NotificationMiddleware(MiddlewareMixin): | ||
def process_request(self, request): | ||
if "notif" not in request.GET: | ||
return | ||
|
||
notif_uuid = request.GET.get("notif", "") | ||
|
||
try: | ||
uuid.UUID(notif_uuid, version=4) | ||
except ValueError: | ||
pass | ||
else: | ||
Notification.objects.filter(uuid=notif_uuid).update(visited_at=timezone.now()) |
35 changes: 35 additions & 0 deletions
35
lacommunaute/notification/migrations/0012_notification_uuid_notification_visited_at.py
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,35 @@ | ||
# Generated by Django 5.1.5 on 2025-01-23 13:56 | ||
|
||
import uuid | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("notification", "0011_alter_emailsenttrack_kind_alter_notification_kind"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="notification", | ||
name="uuid", | ||
field=models.UUIDField(blank=True, null=True, unique=True, verbose_name="uuid"), | ||
), | ||
migrations.AlterField( | ||
model_name="notification", | ||
name="uuid", | ||
field=models.UUIDField( | ||
blank=True, | ||
default=uuid.uuid4, | ||
null=True, | ||
unique=True, | ||
verbose_name="uuid", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="notification", | ||
name="visited_at", | ||
field=models.DateTimeField(blank=True, null=True, verbose_name="clicked at"), | ||
), | ||
] |
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,29 @@ | ||
import pytest | ||
|
||
from lacommunaute.notification.factories import NotificationFactory | ||
from lacommunaute.notification.models import Notification | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"notif_param, expected_visited_at", | ||
[ | ||
("", None), | ||
("malformed", None), | ||
("74eb2ba8-04bf-489f-8c1d-fd1b34b0f3e9", None), | ||
(lambda: str(NotificationFactory().uuid), True), | ||
], | ||
) | ||
def test_notif_param(client, db, notif_param, expected_visited_at): | ||
misc_notification = NotificationFactory() | ||
if callable(notif_param): | ||
notif_param = notif_param() | ||
|
||
client.get(f"/?notif={notif_param}") | ||
|
||
if expected_visited_at: | ||
notification = Notification.objects.get(uuid=notif_param) | ||
notification.refresh_from_db() | ||
assert notification.visited_at is not None | ||
|
||
misc_notification.refresh_from_db() | ||
assert misc_notification.visited_at is None |
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
Oops, something went wrong.