diff --git a/tuning/management/__init__.py b/tuning/management/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tuning/management/commands/__init__.py b/tuning/management/commands/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tuning/management/commands/anonymize_users.py b/tuning/management/commands/anonymize_users.py new file mode 100644 index 0000000000000000000000000000000000000000..ae1fa3300a8d32be31b35572db84bf25929c9c40 --- /dev/null +++ b/tuning/management/commands/anonymize_users.py @@ -0,0 +1,29 @@ +from django.conf import settings +from django.contrib.auth import get_user_model +from django.core.management.base import BaseCommand, CommandError +from faker import Faker + + +class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument("-f", action="store_true") + + def handle(self, *args, **options): + if settings.MAJAK_ENV != "dev": + raise CommandError("Possible to run only in dev environment.") + + if not options["f"]: + self.stdout.write("Use param -f to actually anonymize users.") + return + + fake = Faker() + User = get_user_model() + + for u in User.objects.all(): + old = f"{u} | {u.email}" + u.first_name = fake.first_name() + u.last_name = fake.last_name() + u.email = fake.email() + u.save() + new = f"{u} | {u.email}" + self.stdout.write(f"{old} -> {new}")