-
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: supprimer les traces d'envoi d'emails de plus de 90 jours (#902)
## Description 🎸 L'application trace dans `EmailSentTrack` les appels à `brevo` et le code retour de leur API. Ces objets contiennent des données visées par le champ de la RGPD. Leur seul objectif est de pouvoir identifier l'apparition d'un problème lors de l'appel à l'API. Elles ne sont pas utilisées par ailleurs. Supprimons les au bout de 90 jours. ## Type de changement 🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une fonctionnalité). 🚧 technique ### Points d'attention 🦺 creation d'un nouveau logger. sera revu avec la mise en place de datadog (yc un json formatter) 🦺 ajout d'un filtre dans l'admin sur le `status_code` de l'api `brevo`
- Loading branch information
1 parent
dfc378a
commit 8abf9ef
Showing
9 changed files
with
78 additions
and
5 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
16 changes: 16 additions & 0 deletions
16
lacommunaute/notification/management/commands/delete_old_email_sent_tracks.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,16 @@ | ||
from logging import getLogger | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from lacommunaute.notification.models import EmailSentTrack | ||
|
||
|
||
logger = getLogger("commands") | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Supprimer les anciens enregistrements EmailSentTrack" | ||
|
||
def handle(self, *args, **options): | ||
nb_deleted = EmailSentTrack.objects.delete_old_records() | ||
logger.info("%s enregistrements EmailSentTrack supprimés", nb_deleted) |
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
12 changes: 12 additions & 0 deletions
12
lacommunaute/notification/tests/tests_management_commands.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,12 @@ | ||
from dateutil.relativedelta import relativedelta | ||
from django.core.management import call_command | ||
from django.utils import timezone | ||
|
||
from lacommunaute.notification.factories import EmailSentTrackFactory | ||
from lacommunaute.notification.models import EmailSentTrack | ||
|
||
|
||
def test_delete_old_email_sent_tracks(db): | ||
EmailSentTrackFactory(created=timezone.now() - relativedelta(days=90)) | ||
call_command("delete_old_email_sent_tracks") | ||
assert EmailSentTrack.objects.count() == 0 |
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 @@ | ||
class AutoNowAddOverrideMixin: | ||
"""This mixin allows you to override fields with `auto_now=True`""" | ||
|
||
@classmethod | ||
def _create(cls, model_class, *args, **kwargs): | ||
auto_now_add_desactivated = [] | ||
for field in model_class._meta.get_fields(): | ||
if getattr(field, "auto_now_add", False) and kwargs.get(field.name): | ||
field.auto_now_add = False | ||
auto_now_add_desactivated.append(field) | ||
try: | ||
return super()._create(model_class, *args, **kwargs) | ||
finally: | ||
for field in auto_now_add_desactivated: | ||
field.auto_now_add = True |