feat: Add option to mask e-mails and phone numbers

This is a prerequisite to do tests on DEv and UAT systems
This commit is contained in:
2025-08-01 20:28:51 +02:00
parent 62491b84c1
commit 39a098af8e
3 changed files with 49 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
from django.core.management import BaseCommand
from fellchensammlung.tools.admin import mask_organization_contact_data
class Command(BaseCommand):
help = 'Mask e-mail addresses and phone numbers of organizations for testing purposes.'
def add_arguments(self, parser):
parser.add_argument("domain", type=str)
def handle(self, *args, **options):
domain = options["domain"]
mask_organization_contact_data(domain)

View File

@@ -1,5 +1,6 @@
import logging
from random import randint
from notfellchen import settings
from django.utils import timezone
from datetime import timedelta
@@ -139,3 +140,18 @@ def send_test_email(email):
to = email
mail.send_mail(subject, plain_message, from_email, [to], html_message=html_message)
def mask_organization_contact_data(catchall_domain="example.org"):
"""
Masks e-mails, so they are all sent to one domain, preferably a catchall domain.
"""
rescue_orgs_with_phone_number = RescueOrganization.objects.filter(phone_number__isnull=False)
for rescue_org_with_phone_number in rescue_orgs_with_phone_number:
rescue_org_with_phone_number.phone_number = randint(100000000000, 1000000000000)
rescue_org_with_phone_number.save()
rescue_orgs_with_email = RescueOrganization.objects.filter(email__isnull=False)
for rescue_org_with_email in rescue_orgs_with_email:
rescue_org_with_email.email = f"{rescue_org_with_email.email.replace('@', '-')}@{catchall_domain}"
rescue_org_with_email.save()